Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sync PublicKey class with API spec #3152

Merged
merged 3 commits into from
Jan 9, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading