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
...
 
@@ -424,11 +424,19 @@ class RT:
 
            meta=self._meta_with_urls(txn.meta, rt_fmt, nonrt_fmt, missing_fmt),
 
            postings=[post._replace(meta=self._meta_with_urls(
 
                post.meta, rt_fmt, nonrt_fmt, missing_fmt,
 
            )) 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)
 
        else:
 
            return self.attachment_url(ticket_id, attachment_id)
tests/test_rtutil.py
Show inline comments
...
 
@@ -185,12 +185,21 @@ def test_exists_caches(new_client):
 
    ('rt://example.org/1', None),
 
    ('https://example.org/rt/Ticket/Display.html?id=123', None),
 
])
 
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/')
 
    rt = rtutil.RT(client)
 
    assert rt.url(1).startswith(url)
 

	
0 comments (0 inline, 0 general)