Changeset - 39a9d0d67ea5
[Not reviewed]
0 3 0
Brett Smith - 3 years ago 2021-03-12 22:16:46
brettcsmith@brettcsmith.org
query: rt_ticket() supports looking up custom fields.
3 files changed with 16 insertions and 1 deletions:
0 comments (0 inline, 0 general)
conservancy_beancount/reports/query.py
Show inline comments
...
 
@@ -55,2 +55,3 @@ import logging
 
import os
 
import re
 
import sqlite3
...
 
@@ -256,2 +257,6 @@ class RTTicket(bc_query_compile.EvalFunction):
 
    __intypes__ = [str, str, int]
 
    _CF_REGEXPS = [
 
        re.compile(r'^CF_([-\w]+)$', re.IGNORECASE),
 
        re.compile(r'^CF\.\{([-\w]+)\}$', re.IGNORECASE),
 
    ]
 
    FIELDS = {key: RTField(key, None) for key in [
...
 
@@ -322,2 +327,9 @@ class RTTicket(bc_query_compile.EvalFunction):
 
        except KeyError:
 
            for regexp in self._CF_REGEXPS:
 
                match = regexp.fullmatch(key)
 
                if match is not None:
 
                    cfield = RTField(f'CF.{{{match.group(1)}}}', None)
 
                    self.FIELDS[cfield.key] = cfield
 
                    self.FIELDS[key] = cfield
 
                    return cfield
 
            raise ValueError(f"unknown RT ticket field {key!r}") from None
setup.py
Show inline comments
...
 
@@ -7,3 +7,3 @@ setup(
 
    description="Plugin, library, and reports for reading Conservancy's books",
 
    version='1.19.2',
 
    version='1.19.3',
 
    author='Software Freedom Conservancy',
tests/test_reports_query.py
Show inline comments
...
 
@@ -92,2 +92,3 @@ def test_rt_ticket_bad_metadata(ticket_query, meta_name):
 
    ('Due', 'tax-reporting', {datetime.datetime(2017, 1, 14, 12, 1, 0, tzinfo=UTC)}),
 
    ('cf.{payment-to}', 'statement', {'Hon. Mx. 1'}),
 
])
...
 
@@ -106,2 +107,3 @@ def test_rt_ticket_from_txn(ticket_query, field_name, meta_name, expected):
 
    ('Due', 'tax-reporting', {datetime.datetime(2017, 1, 14, 12, 2, 0, tzinfo=UTC)}),
 
    ('CF_payment-to', 'statement', {'Hon. Mx. 2'}),
 
])
...
 
@@ -123,2 +125,3 @@ def test_rt_ticket_from_post(ticket_query, field_name, meta_name, expected):
 
    }, False),
 
    ('cf_payment-to', 'statement', {'Hon. Mx. 1', 'Hon. Mx. 2'}, True),
 
])
0 comments (0 inline, 0 general)