Changeset - 9e33b2795ca5
[Not reviewed]
0 2 0
Brett Smith - 3 years ago 2021-03-10 15:37:21
brettcsmith@brettcsmith.org
config: Add RTCredentials.idstr() method.

Want to reuse this code for a query-report cache key.
2 files changed with 25 insertions and 5 deletions:
0 comments (0 inline, 0 general)
conservancy_beancount/config.py
Show inline comments
...
 
@@ -67,2 +67,14 @@ class RTCredentials(NamedTuple):
 

	
 
    def idstr(self) -> str:
 
        """Return a string unique to these credentials
 

	
 
        This returns a string that incorporates the server URL and user.
 
        The string will be unique across different credentials.
 
        It's suitable for use as a cache key or filename.
 
        """
 
        return '{}@{}'.format(
 
            self.user or '',
 
            urlparse.quote(self.server or '', ''),
 
        )
 

	
 

	
...
 
@@ -211,7 +223,3 @@ class Config:
 
        else:
 
            cache_name = '{}@{}.sqlite3'.format(
 
                credentials.user,
 
                urlparse.quote(str(credentials.server), ''),
 
            )
 
            cache_path = cache_dir_path / cache_name
 
            cache_path = cache_dir_path / f'{credentials.idstr()}.sqlite3'
 
            try:
tests/test_config.py
Show inline comments
...
 
@@ -9,2 +9,3 @@ import contextlib
 
import decimal
 
import itertools
 
import operator
...
 
@@ -142,2 +143,13 @@ def test_rt_credentials_from_all_sources_mixed(tmp_path):
 

	
 
def test_rt_credentials_idstr():
 
    actual = {
 
        config_mod.RTCredentials(server, user).idstr()
 
        for server, user in itertools.product(
 
                [None, 'https://example.org/rt'],
 
                [None, 'example'],
 
        )}
 
    assert len(actual) == 4
 
    for idstr in actual:
 
        assert '/' not in idstr
 

	
 
def check_rt_client_url(credentials, client):
0 comments (0 inline, 0 general)