@@ -81,55 +81,58 @@ def test_rt_ticket_bad_field(ticket_query, field_name):
ticket_query(const_operands(field_name, 'rt-id'))
@pytest.mark.parametrize('meta_name', ['foo', 'bar'])
def test_rt_ticket_bad_metadata(ticket_query, meta_name):
with pytest.raises(ValueError):
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)}),
('cf.{payment-to}', 'statement', {'Hon. Mx. 1'}),
])
def test_rt_ticket_from_txn(ticket_query, field_name, meta_name, expected):
func = ticket_query(const_operands(field_name, meta_name))
txn = testutil.Transaction(**{meta_name: 'rt:1'}, postings=[
('Assets:Cash', 80),
context = RowContext(txn, txn.postings[0])
assert func(context) == expected
('id', 'rt-id', {2}),
('Requestors', 'invoice', {'mx2@example.org', 'requestor2@example.org'}),
('Due', 'tax-reporting', {datetime.datetime(2017, 1, 14, 12, 2, 0, tzinfo=UTC)}),
('CF_payment-to', 'statement', {'Hon. Mx. 2'}),
def test_rt_ticket_from_post(ticket_query, field_name, meta_name, expected):
('Assets:Cash', 110, {meta_name: 'rt:2/8'}),
@pytest.mark.parametrize('field_name,meta_name,expected,on_txn', [
('id', 'approval', {1, 2}, True),
('Queue', 'check', {'general'}, False),
('Requestors', 'invoice', {
'mx1@example.org',
'mx2@example.org',
'requestor2@example.org',
}, False),
('cf_payment-to', 'statement', {'Hon. Mx. 1', 'Hon. Mx. 2'}, True),
def test_rt_ticket_multi_results(ticket_query, field_name, meta_name, expected, on_txn):
txn = testutil.Transaction(**{'rt-id': 'rt:1'}, postings=[
('Assets:Cash', 110, {'rt-id': 'rt:2'}),
post = txn.postings[0]
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)