mirror of
https://github.com/openSUSE/osc.git
synced 2024-11-09 22:36:14 +01:00
Make most of the fields in KeyinfoPubkey and KeyinfoSslcert models optional
The presence of the fields seems to be random and the only truly required field is the actual public key/cert. Other fields are only for the information.
This commit is contained in:
parent
4d1651d038
commit
52f076636d
@ -4,27 +4,27 @@ from ..util.models import * # pylint: disable=wildcard-import,unused-wildcard-i
|
||||
class KeyinfoPubkey(XmlModel):
|
||||
XML_TAG = "pubkey"
|
||||
|
||||
keyid: str = Field(
|
||||
keyid: Optional[str] = Field(
|
||||
xml_attribute=True,
|
||||
)
|
||||
|
||||
userid: str = Field(
|
||||
userid: Optional[str] = Field(
|
||||
xml_attribute=True,
|
||||
)
|
||||
|
||||
algo: str = Field(
|
||||
algo: Optional[str] = Field(
|
||||
xml_attribute=True,
|
||||
)
|
||||
|
||||
keysize: str = Field(
|
||||
keysize: Optional[str] = Field(
|
||||
xml_attribute=True,
|
||||
)
|
||||
|
||||
expires: int = Field(
|
||||
expires: Optional[int] = Field(
|
||||
xml_attribute=True,
|
||||
)
|
||||
|
||||
fingerprint: str = Field(
|
||||
fingerprint: Optional[str] = Field(
|
||||
xml_attribute=True,
|
||||
)
|
||||
|
||||
@ -34,6 +34,10 @@ class KeyinfoPubkey(XmlModel):
|
||||
|
||||
def get_expires_str(self) -> str:
|
||||
import datetime
|
||||
|
||||
if self.expires is None:
|
||||
return ""
|
||||
|
||||
return datetime.datetime.fromtimestamp(self.expires).strftime("%Y-%m-%d %H:%M:%S")
|
||||
|
||||
def to_human_readable_string(self) -> str:
|
||||
|
@ -8,7 +8,7 @@ class KeyinfoSslcert(XmlModel):
|
||||
xml_attribute=True,
|
||||
)
|
||||
|
||||
serial: str = Field(
|
||||
serial: Optional[str] = Field(
|
||||
xml_attribute=True,
|
||||
)
|
||||
|
||||
@ -16,23 +16,23 @@ class KeyinfoSslcert(XmlModel):
|
||||
xml_attribute=True,
|
||||
)
|
||||
|
||||
subject: str = Field(
|
||||
subject: Optional[str] = Field(
|
||||
xml_attribute=True,
|
||||
)
|
||||
|
||||
algo: str = Field(
|
||||
algo: Optional[str] = Field(
|
||||
xml_attribute=True,
|
||||
)
|
||||
|
||||
keysize: str = Field(
|
||||
keysize: Optional[str] = Field(
|
||||
xml_attribute=True,
|
||||
)
|
||||
|
||||
begins: int = Field(
|
||||
begins: Optional[int] = Field(
|
||||
xml_attribute=True,
|
||||
)
|
||||
|
||||
expires: int = Field(
|
||||
expires: Optional[int] = Field(
|
||||
xml_attribute=True,
|
||||
)
|
||||
|
||||
@ -46,10 +46,18 @@ class KeyinfoSslcert(XmlModel):
|
||||
|
||||
def get_begins_str(self) -> str:
|
||||
import datetime
|
||||
|
||||
if self.begins is None:
|
||||
return ""
|
||||
|
||||
return datetime.datetime.fromtimestamp(self.begins).strftime("%Y-%m-%d %H:%M:%S")
|
||||
|
||||
def get_expires_str(self) -> str:
|
||||
import datetime
|
||||
|
||||
if self.expires is None:
|
||||
return ""
|
||||
|
||||
return datetime.datetime.fromtimestamp(self.expires).strftime("%Y-%m-%d %H:%M:%S")
|
||||
|
||||
def to_human_readable_string(self) -> str:
|
||||
|
43
tests/test_keyinfo.py
Normal file
43
tests/test_keyinfo.py
Normal file
@ -0,0 +1,43 @@
|
||||
import unittest
|
||||
|
||||
from osc import obs_api
|
||||
|
||||
|
||||
class TestKeyinfo(unittest.TestCase):
|
||||
def test_empty_pubkey(self):
|
||||
ki = obs_api.Keyinfo()
|
||||
ki.pubkey_list = [{"value": "<pubkey>"}]
|
||||
|
||||
expected = """
|
||||
Type : GPG public key
|
||||
User ID :
|
||||
Algorithm :
|
||||
Key size :
|
||||
Expires :
|
||||
Fingerprint :
|
||||
<pubkey>""".strip()
|
||||
actual = ki.pubkey_list[0].to_human_readable_string()
|
||||
self.assertEqual(expected, actual)
|
||||
|
||||
def test_empty_sslcert(self):
|
||||
ki = obs_api.Keyinfo()
|
||||
ki.sslcert_list = [{"value": "<pubkey>"}]
|
||||
|
||||
expected = """
|
||||
Type : SSL certificate
|
||||
Subject :
|
||||
Key ID :
|
||||
Serial :
|
||||
Issuer :
|
||||
Algorithm :
|
||||
Key size :
|
||||
Begins :
|
||||
Expires :
|
||||
Fingerprint :
|
||||
<pubkey>""".strip()
|
||||
actual = ki.sslcert_list[0].to_human_readable_string()
|
||||
self.assertEqual(expected, actual)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
Loading…
Reference in New Issue
Block a user