From 3b5a563ef64b9d325717359e7b9c468cb8d1177f Mon Sep 17 00:00:00 2001 From: Brett Smith Date: Wed, 17 May 2017 12:56:19 -0400 Subject: [PATCH] historical: Write results to cache when appropriate. --- oxrlib/commands/historical.py | 2 ++ tests/test_historical.py | 3 +++ 2 files changed, 5 insertions(+) diff --git a/oxrlib/commands/historical.py b/oxrlib/commands/historical.py index c7d7f70..075fa83 100644 --- a/oxrlib/commands/historical.py +++ b/oxrlib/commands/historical.py @@ -12,6 +12,8 @@ def run(config, stdout, stderr): loaders = config.get_loaders() with loaders.historical(config.args.date, config.args.base) as rate_json: rate = oxrrate.Rate.from_json_file(rate_json) + if loaders.should_cache(): + config.cache.save_rate(rate) if not config.args.from_currency: for from_curr in sorted(rate.rates): print(*format_rate_pair(rate, from_curr, config.args.to_currency), diff --git a/tests/test_historical.py b/tests/test_historical.py index cacac1c..f8dfcfc 100644 --- a/tests/test_historical.py +++ b/tests/test_historical.py @@ -19,6 +19,9 @@ class FakeResponder: def __getattr__(self, name): return self._respond + def should_cache(self): + return False + class FakeConfig: def __init__(self, responder, argvars=None):