Changeset - e8e713721628
[Not reviewed]
0 2 0
Brett Smith - 4 years ago 2020-03-25 14:18:09
brettcsmith@brettcsmith.org
rtutil: Fix parsing server URLs that include /REST/.
2 files changed with 7 insertions and 1 deletions:
0 comments (0 inline, 0 general)
conservancy_beancount/rtutil.py
Show inline comments
...
 
@@ -41,25 +41,25 @@ class RT:
 
    * Cache results, to reduce network requests
 
    """
 

	
 
    PARSE_REGEXPS = [
 
        re.compile(r'^rt:([0-9]+)(?:/([0-9]+))?/?$'),
 
        re.compile(r'^rt://ticket/([0-9]+)(?:/attachments?/([0-9]+))?/?$'),
 
    ]
 

	
 
    def __init__(self, rt_client: rt.Rt) -> None:
 
        self.rt = rt_client
 
        urlparts = urlparse.urlparse(rt_client.url)
 
        try:
 
            index = urlparts.path.index('/REST/')
 
            index = urlparts.path.rindex('/REST/')
 
        except ValueError:
 
            base_path = urlparts.path.rstrip('/') + '/'
 
        else:
 
            base_path = urlparts.path[:index + 1]
 
        self.url_base = urlparts._replace(path=base_path)
 

	
 
    def _extend_url(self,
 
                    path_tail: str,
 
                    fragment: Optional[str]=None,
 
                    **query: str,
 
    ) -> str:
 
        if fragment is None:
tests/test_rtutil.py
Show inline comments
...
 
@@ -112,12 +112,18 @@ def test_exists_caches(new_client):
 
    ('rt://ticket/1234/attachment/5678', ('1234', '5678')),
 
    ('rt://ticket/1234/attachment/5678/', ('1234', '5678')),
 
    ('rt:', None),
 
    ('rt://', None),
 
    ('rt:example.org', None),
 
    ('rt:example.org/1', None),
 
    ('rt://example.org', None),
 
    ('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
 

	
 
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)