Mark signing identities as such in Identity.__repr__

This commit is contained in:
Gergely Polonkai 2022-05-06 09:30:11 +02:00
parent d602d9c3ba
commit 547c6b5205
No known key found for this signature in database
GPG Key ID: 2D2885533B869ED4
2 changed files with 15 additions and 1 deletions

View File

@ -56,6 +56,9 @@ class Identity:
return f'@{self.name}.{base32_bytes_to_string(self.verify_key.to_bytes())}' return f'@{self.name}.{base32_bytes_to_string(self.verify_key.to_bytes())}'
def __repr__(self) -> str: def __repr__(self) -> str:
if self.sign_key:
return f'<Identity (signer) {self}>'
return f'<Identity {self}>' return f'<Identity {self}>'
def __eq__(self, other: object) -> bool: def __eq__(self, other: object) -> bool:

View File

@ -67,7 +67,18 @@ def test_str(identity: Identity) -> None:
@pytest.mark.id_key_seed(TEST_SEED) @pytest.mark.id_key_seed(TEST_SEED)
@pytest.mark.id_name('test') @pytest.mark.id_name('test')
def test_repr(identity: Identity) -> None: def test_repr(identity: Identity) -> None:
"""Test if the __str__ method returns the author address""" """Test if the __repr__ method returns the author address"""
assert (
repr(identity)
== '<Identity (signer) @test.bcz76z52y5dlpohtkmpuj3jsdcvfmebzpcgfmtmhu4u7hlexzreya>'
)
def test_repr_nosign() -> None:
"""Test the __repr__ method marks the identity as a signer in the output"""
identity = Identity.from_address('@test.bcz76z52y5dlpohtkmpuj3jsdcvfmebzpcgfmtmhu4u7hlexzreya')
assert ( assert (
repr(identity) == '<Identity @test.bcz76z52y5dlpohtkmpuj3jsdcvfmebzpcgfmtmhu4u7hlexzreya>' repr(identity) == '<Identity @test.bcz76z52y5dlpohtkmpuj3jsdcvfmebzpcgfmtmhu4u7hlexzreya>'