File diff 25321a81b0f1 → ef03893bfed3
tests/test_reports_query.py
Show inline comments
...
 
@@ -86,10 +86,10 @@ def test_rt_ticket_bad_metadata(ticket_query, meta_name):
 
        ticket_query(const_operands('id', meta_name))
 

	
 
@pytest.mark.parametrize('field_name,meta_name,expected', [
 
    ('id', 'rt-id', 1),
 
    ('Queue', 'approval', 'general'),
 
    ('Requestors', 'invoice', ['mx1@example.org', 'requestor2@example.org']),
 
    ('Due', 'tax-reporting', datetime.datetime(2017, 1, 14, 12, 1, 0, tzinfo=UTC)),
 
    ('id', 'rt-id', {1}),
 
    ('Queue', 'approval', {'general'}),
 
    ('Requestors', 'invoice', {'mx1@example.org', 'requestor2@example.org'}),
 
    ('Due', 'tax-reporting', {datetime.datetime(2017, 1, 14, 12, 1, 0, tzinfo=UTC)}),
 
])
 
def test_rt_ticket_from_txn(ticket_query, field_name, meta_name, expected):
 
    func = ticket_query(const_operands(field_name, meta_name))
...
 
@@ -97,15 +97,13 @@ def test_rt_ticket_from_txn(ticket_query, field_name, meta_name, expected):
 
        ('Assets:Cash', 80),
 
    ])
 
    context = RowContext(txn, txn.postings[0])
 
    if not isinstance(expected, list):
 
        expected = [expected]
 
    assert func(context) == expected
 

	
 
@pytest.mark.parametrize('field_name,meta_name,expected', [
 
    ('id', 'rt-id', 2),
 
    ('Queue', 'approval', 'general'),
 
    ('Requestors', 'invoice', ['mx2@example.org', 'requestor2@example.org']),
 
    ('Due', 'tax-reporting', datetime.datetime(2017, 1, 14, 12, 2, 0, tzinfo=UTC)),
 
    ('id', 'rt-id', {2}),
 
    ('Queue', 'approval', {'general'}),
 
    ('Requestors', 'invoice', {'mx2@example.org', 'requestor2@example.org'}),
 
    ('Due', 'tax-reporting', {datetime.datetime(2017, 1, 14, 12, 2, 0, tzinfo=UTC)}),
 
])
 
def test_rt_ticket_from_post(ticket_query, field_name, meta_name, expected):
 
    func = ticket_query(const_operands(field_name, meta_name))
...
 
@@ -113,19 +111,16 @@ def test_rt_ticket_from_post(ticket_query, field_name, meta_name, expected):
 
        ('Assets:Cash', 110, {meta_name: 'rt:2/8'}),
 
    ])
 
    context = RowContext(txn, txn.postings[0])
 
    if not isinstance(expected, list):
 
        expected = [expected]
 
    assert func(context) == expected
 

	
 
@pytest.mark.parametrize('field_name,meta_name,expected,on_txn', [
 
    ('id', 'approval', [1, 2], True),
 
    ('Queue', 'check', ['general', 'general'], False),
 
    ('Requestors', 'invoice', [
 
    ('id', 'approval', {1, 2}, True),
 
    ('Queue', 'check', {'general'}, False),
 
    ('Requestors', 'invoice', {
 
        'mx1@example.org',
 
        'mx2@example.org',
 
        'requestor2@example.org',
 
        'requestor2@example.org',
 
    ], False),
 
    }, False),
 
])
 
def test_rt_ticket_multi_results(ticket_query, field_name, meta_name, expected, on_txn):
 
    func = ticket_query(const_operands(field_name, meta_name))
...
 
@@ -136,7 +131,7 @@ def test_rt_ticket_multi_results(ticket_query, field_name, meta_name, expected,
 
    meta = txn.meta if on_txn else post.meta
 
    meta[meta_name] = 'rt:1/2 Docs/12.pdf rt:2/8'
 
    context = RowContext(txn, post)
 
    assert sorted(func(context)) == expected
 
    assert func(context) == expected
 

	
 
@pytest.mark.parametrize('meta_value,on_txn', testutil.combine_values(
 
    ['', 'Docs/34.pdf', 'Docs/100.pdf Docs/120.pdf'],
...
 
@@ -151,7 +146,7 @@ def test_rt_ticket_no_results(ticket_query, meta_value, on_txn):
 
    meta = txn.meta if on_txn else post.meta
 
    meta['check'] = meta_value
 
    context = RowContext(txn, post)
 
    assert func(context) == []
 
    assert func(context) == set()
 

	
 
def test_rt_ticket_caches_tickets():
 
    rt_client = testutil.RTClient()
...
 
@@ -162,9 +157,9 @@ def test_rt_ticket_caches_tickets():
 
        ('Assets:Cash', 160, {'rt-id': 'rt:3'}),
 
    ])
 
    context = RowContext(txn, txn.postings[0])
 
    assert func(context) == [3]
 
    assert func(context) == {3}
 
    del rt_client.TICKET_DATA['3']
 
    assert func(context) == [3]
 
    assert func(context) == {3}
 

	
 
def test_rt_ticket_caches_tickets_not_found():
 
    rt_client = testutil.RTClient()
...
 
@@ -176,9 +171,9 @@ def test_rt_ticket_caches_tickets_not_found():
 
        ('Assets:Cash', 160, {'rt-id': 'rt:3'}),
 
    ])
 
    context = RowContext(txn, txn.postings[0])
 
    assert func(context) == []
 
    assert func(context) == set()
 
    rt_client.TICKET_DATA['3'] = rt3
 
    assert func(context) == []
 
    assert func(context) == set()
 

	
 
def test_books_loader_empty():
 
    result = qmod.BooksLoader(None)()