Skip to content

Commit

Permalink
Sync PublicKey class with API spec (#3152)
Browse files Browse the repository at this point in the history
Adds the following attributes:
- created_at
- id
- title
- url
  • Loading branch information
EnricoMi authored Jan 9, 2025
1 parent 519b61b commit 26c284b
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 0 deletions.
32 changes: 32 additions & 0 deletions github/PublicKey.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,12 +74,26 @@ class PublicKey(CompletableGithubObject):
"""

def _initAttributes(self) -> None:
self._created_at: Attribute[str] = NotSet
self._id: Attribute[int] = NotSet
self._key: Attribute[str] = NotSet
self._key_id: Attribute[str | int] = NotSet
self._title: Attribute[str] = NotSet
self._url: Attribute[str] = NotSet

def __repr__(self) -> str:
return self.get__repr__({"key_id": self._key_id.value, "key": self._key.value})

@property
def created_at(self) -> str:
self._completeIfNotSet(self._created_at)
return self._created_at.value

@property
def id(self) -> int:
self._completeIfNotSet(self._id)
return self._id.value

@property
def key(self) -> str:
self._completeIfNotSet(self._key)
Expand All @@ -90,14 +104,32 @@ def key_id(self) -> str | int:
self._completeIfNotSet(self._key_id)
return self._key_id.value

@property
def title(self) -> str:
self._completeIfNotSet(self._title)
return self._title.value

@property
def url(self) -> str:
self._completeIfNotSet(self._url)
return self._url.value

def encrypt(self, unencrypted_value: str) -> str:
return encrypt(self._key.value, unencrypted_value)

def _useAttributes(self, attributes: dict[str, Any]) -> None:
if "created_at" in attributes: # pragma no branch
self._created_at = self._makeStringAttribute(attributes["created_at"])
if "id" in attributes: # pragma no branch
self._id = self._makeIntAttribute(attributes["id"])
if "key" in attributes: # pragma no branch
self._key = self._makeStringAttribute(attributes["key"])
if "key_id" in attributes: # pragma no branch
if isinstance(attributes["key_id"], str):
self._key_id = self._makeStringAttribute(attributes["key_id"])
else:
self._key_id = self._makeIntAttribute(attributes["key_id"])
if "title" in attributes: # pragma no branch
self._title = self._makeStringAttribute(attributes["title"])
if "url" in attributes: # pragma no branch
self._url = self._makeStringAttribute(attributes["url"])
6 changes: 6 additions & 0 deletions tests/PublicKey.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,18 +35,24 @@
# #
################################################################################

from __future__ import annotations

from . import Framework


class PublicKey(Framework.TestCase):
def testAttributes(self):
self.public_key = self.g.get_user().get_repo("PyGithub").get_public_key()
self.assertIsNone(self.public_key.created_at)
self.assertIsNone(self.public_key.id)
self.assertEqual(self.public_key.key, "u5e1Z25+z8pmgVVt5Pd8k0z/sKpVL1MXYtRAecE4vm8=")
self.assertEqual(self.public_key.key_id, "568250167242549743")
self.assertEqual(
repr(self.public_key),
'PublicKey(key_id="568250167242549743", key="u5e1Z25+z8pmgVVt5Pd8k0z/sKpVL1MXYtRAecE4vm8=")',
)
self.assertIsNone(self.public_key.title)
self.assertIsNone(self.public_key.url)

def testAttributes_with_int_key_id(self):
self.public_key = self.g.get_user().get_repo("PyGithub").get_public_key()
Expand Down

0 comments on commit 26c284b

Please sign in to comment.