rtutil: Add RT.unparse() classmethod.

This commit is contained in:
Brett Smith 2020-06-12 15:54:38 -04:00
parent cd578289c4
commit 4ca188611f
2 changed files with 17 additions and 0 deletions

View file

@ -427,6 +427,14 @@ class RT:
)) for post in txn.postings],
)
@classmethod
def unparse(cls, ticket_id: RTId, attachment_id: Optional[RTId]=None) -> str:
"""Return a metadata link string for the given ticket+attachment id"""
if attachment_id is None:
return f'rt:{ticket_id}'
else:
return f'rt:{ticket_id}/{attachment_id}'
def url(self, ticket_id: RTId, attachment_id: Optional[RTId]=None) -> Optional[str]:
if attachment_id is None:
return self.ticket_url(ticket_id)

View file

@ -188,6 +188,15 @@ def test_exists_caches(new_client):
def test_parse(rt, link, expected):
assert rt.parse(link) == expected
@pytest.mark.parametrize('ticket_id,attachment_id,expected', [
('12', None, 'rt:12'),
(34, None, 'rt:34'),
('56', '78', 'rt:56/78'),
(90, 880, 'rt:90/880'),
])
def test_unparse(rt, ticket_id, attachment_id, expected):
assert rt.unparse(ticket_id, attachment_id) == expected
def test_uncommon_server_url_parsing():
url = 'https://example.org/REST/1.0/'
client = testutil.RTClient(url + 'REST/1.0/')