From 1124842ea7e0e68842129d32f7af5ff19e590d8b Mon Sep 17 00:00:00 2001 From: Brett Smith Date: Thu, 11 Jun 2020 16:29:18 -0400 Subject: [PATCH] accrual: Actually use RT caching as intended. Basically none of the reports were reading or writing the RT link cache because they didn't instantiate an rtutil.RT properly to do that. --- conservancy_beancount/reports/accrual.py | 27 ++++++++++++------------ setup.py | 2 +- tests/test_reports_accrual.py | 7 +++--- 3 files changed, 18 insertions(+), 18 deletions(-) diff --git a/conservancy_beancount/reports/accrual.py b/conservancy_beancount/reports/accrual.py index b00ee28..30e0fb5 100644 --- a/conservancy_beancount/reports/accrual.py +++ b/conservancy_beancount/reports/accrual.py @@ -293,13 +293,12 @@ class AgingODS(core.BaseODS[AccrualPostings, Optional[data.Account]]): COL_COUNT = len(COLUMNS) def __init__(self, - rt_client: rt.Rt, + rt_wrapper: rtutil.RT, date: datetime.date, logger: logging.Logger, ) -> None: super().__init__() - self.rt_client = rt_client - self.rt_wrapper = rtutil.RT(self.rt_client) + self.rt_wrapper = rt_wrapper self.date = date self.logger = logger @@ -445,7 +444,7 @@ class AgingODS(core.BaseODS[AccrualPostings, Optional[data.Account]]): class AgingReport(BaseReport): def __init__(self, - rt_client: rt.Rt, + rt_wrapper: rtutil.RT, out_file: BinaryIO, date: Optional[datetime.date]=None, ) -> None: @@ -453,7 +452,7 @@ class AgingReport(BaseReport): date = datetime.date.today() self.out_bin = out_file self.logger = logger.getChild(type(self).__name__) - self.ods = AgingODS(rt_client, date, self.logger) + self.ods = AgingODS(rt_wrapper, date, self.logger) def run(self, groups: PostGroups) -> None: rows: List[AccrualPostings] = [] @@ -501,10 +500,10 @@ class BalanceReport(BaseReport): class OutgoingReport(BaseReport): - def __init__(self, rt_client: rt.Rt, out_file: TextIO) -> None: + def __init__(self, rt_wrapper: rtutil.RT, out_file: TextIO) -> None: super().__init__(out_file) - self.rt_client = rt_client - self.rt_wrapper = rtutil.RT(rt_client) + self.rt_wrapper = rt_wrapper + self.rt_client = rt_wrapper.rt def _primary_rt_id(self, posts: AccrualPostings) -> rtutil.TicketAttachmentIds: rt_id = posts.rt_id @@ -721,8 +720,8 @@ def main(arglist: Optional[Sequence[str]]=None, report: Optional[BaseReport] = None output_path: Optional[Path] = None if args.report_type is ReportType.AGING: - rt_client = config.rt_client() - if rt_client is None: + rt_wrapper = config.rt_wrapper() + if rt_wrapper is None: logger.error("unable to generate aging report: RT client is required") else: now = datetime.datetime.now() @@ -730,14 +729,14 @@ def main(arglist: Optional[Sequence[str]]=None, args.output_file = Path(now.strftime('AgingReport_%Y-%m-%d_%H:%M.ods')) logger.info("Writing report to %s", args.output_file) out_bin = cliutil.bytes_output(args.output_file, stdout) - report = AgingReport(rt_client, out_bin) + report = AgingReport(rt_wrapper, out_bin) elif args.report_type is ReportType.OUTGOING: - rt_client = config.rt_client() - if rt_client is None: + rt_wrapper = config.rt_wrapper() + if rt_wrapper is None: logger.error("unable to generate outgoing report: RT client is required") else: out_file = cliutil.text_output(args.output_file, stdout) - report = OutgoingReport(rt_client, out_file) + report = OutgoingReport(rt_wrapper, out_file) else: out_file = cliutil.text_output(args.output_file, stdout) report = BalanceReport(out_file) diff --git a/setup.py b/setup.py index a7c1cf5..7b0f642 100755 --- a/setup.py +++ b/setup.py @@ -5,7 +5,7 @@ from setuptools import setup setup( name='conservancy_beancount', description="Plugin, library, and reports for reading Conservancy's books", - version='1.1.9', + version='1.1.10', author='Software Freedom Conservancy', author_email='info@sfconservancy.org', license='GNU AGPLv3+', diff --git a/tests/test_reports_accrual.py b/tests/test_reports_accrual.py index 6b7ab91..676d2ae 100644 --- a/tests/test_reports_accrual.py +++ b/tests/test_reports_accrual.py @@ -425,10 +425,11 @@ def check_output(output, expect_patterns): def run_outgoing(rt_id, postings, rt_client=None): if rt_client is None: rt_client = RTClient() + rt_wrapper = rtutil.RT(rt_client) if not isinstance(postings, core.RelatedPostings): postings = accruals_by_meta(postings, rt_id, 'rt-id', wrap_type=accrual.AccrualPostings) output = io.StringIO() - report = accrual.OutgoingReport(rt_client, output) + report = accrual.OutgoingReport(rt_wrapper, output) report.run({rt_id: postings}) return output @@ -525,8 +526,8 @@ def run_aging_report(postings, today=None): for key, group in related.make_consistent() } output = io.BytesIO() - rt_client = RTClient() - report = accrual.AgingReport(rt_client, output, today) + rt_wrapper = rtutil.RT(RTClient()) + report = accrual.AgingReport(rt_wrapper, output, today) report.run(groups) return output