Changeset - 4ca188611fcb
[Not reviewed]
0 2 0
Brett Smith - 4 years ago 2020-06-12 19:54:38
brettcsmith@brettcsmith.org
rtutil: Add RT.unparse() classmethod.
2 files changed with 17 insertions and 0 deletions:
0 comments (0 inline, 0 general)
conservancy_beancount/rtutil.py
Show inline comments
...
 
@@ -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)
tests/test_rtutil.py
Show inline comments
...
 
@@ -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/')
0 comments (0 inline, 0 general)