Changeset - 46ac91e86e90
[Not reviewed]
0 1 0
Brett Smith - 4 years ago 2020-04-28 21:20:59
brettcsmith@brettcsmith.org
test_rtutil: Simplify setup.
1 file changed with 1 insertions and 2 deletions:
0 comments (0 inline, 0 general)
tests/test_rtutil.py
Show inline comments
...
 
@@ -188,55 +188,54 @@ def test_no_shared_cache(new_client):
 

	
 
def test_read_only_cache(new_client, tmp_path):
 
    db_path = tmp_path / 'test.db'
 
    ticket_id, _, expected = EXPECTED_URLS[0]
 
    expected = DEFAULT_RT_URL + expected
 
    with new_cache(db_path) as cache1:
 
        rt1 = rtutil.RT(new_client, cache1)
 
        assert rt1.url(ticket_id) == expected
 
    new_client.TICKET_DATA.clear()
 
    db_path.chmod(0o400)
 
    with new_cache(db_path) as cache2:
 
        rt2 = rtutil.RT(new_client, cache2)
 
        assert rt2.url(ticket_id) == expected
 
        assert rt2.url(ticket_id + 1) is None
 

	
 
def test_results_not_found_only_in_transient_cache(new_client):
 
    with new_cache() as cache:
 
        rt1 = rtutil.RT(new_client, cache)
 
        rt2 = rtutil.RT(new_client, cache)
 
        assert not rt1.exists(9)
 
        new_client.TICKET_DATA['9'] = [('99', '(Unnamed)', 'text/plain', '0b')]
 
        assert not rt1.exists(9)
 
        assert rt2.exists(9)
 

	
 
def test_txn_with_urls(new_client):
 
def test_txn_with_urls(rt):
 
    txn_meta = {
 
        'rt-id': 'rt:1',
 
        'contract': 'RepoLink.pdf',
 
        'statement': 'doc1.txt rt:1/4 doc2.txt',
 
    }
 
    txn = testutil.Transaction(**txn_meta, postings=[
 
        ('Income:Donations', -10, {'receipt': 'rt:2/13 donation.txt'}),
 
        ('Assets:Cash', 10, {'receipt': 'cash.png rt:2/14'}),
 
    ])
 
    rt = rtutil.RT(new_client)
 
    actual = rt.txn_with_urls(txn)
 
    def check(source, key, ticket_id, attachment_id=None):
 
        url_path = EXPECTED_URLS_MAP[(ticket_id, attachment_id)]
 
        assert f'<{DEFAULT_RT_URL}{url_path}>' in source.meta[key]
 
    expected_keys = set(txn_meta)
 
    expected_keys.update(['filename', 'lineno'])
 
    assert set(actual.meta) == expected_keys
 
    check(actual, 'rt-id', 1)
 
    assert actual.meta['contract'] == txn_meta['contract']
 
    assert actual.meta['statement'].startswith('doc1.txt ')
 
    check(actual, 'statement', 1, 4)
 
    check(actual.postings[0], 'receipt', 2, 13)
 
    assert actual.postings[0].meta['receipt'].endswith(' donation.txt')
 
    check(actual.postings[1], 'receipt', 2, 14)
 
    assert actual.postings[1].meta['receipt'].startswith('cash.png ')
 
    # Check the original transaction is unchanged
 
    for key, expected in txn_meta.items():
 
        assert txn.meta[key] == expected
 
    assert txn.postings[0].meta['receipt'] == 'rt:2/13 donation.txt'
 
    assert txn.postings[1].meta['receipt'] == 'cash.png rt:2/14'
0 comments (0 inline, 0 general)