Changeset - 3b5a563ef64b
[Not reviewed]
0 2 0
Brett Smith - 7 years ago 2017-05-17 16:56:19
brettcsmith@brettcsmith.org
historical: Write results to cache when appropriate.
2 files changed with 5 insertions and 0 deletions:
0 comments (0 inline, 0 general)
oxrlib/commands/historical.py
Show inline comments
...
 
@@ -9,12 +9,14 @@ def format_rate_pair(rate, from_curr, to_curr):
 
    yield format_one_rate(rate, 1, to_curr, from_curr)
 

	
 
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),
 
                  sep='\n', file=stdout)
 
    elif config.args.amount is None:
 
        print(*format_rate_pair(rate, config.args.from_currency, config.args.to_currency),
tests/test_historical.py
Show inline comments
...
 
@@ -16,12 +16,15 @@ class FakeResponder:
 
    def _respond(self, *args, **kwargs):
 
        return open(self.response_path)
 

	
 
    def __getattr__(self, name):
 
        return self._respond
 

	
 
    def should_cache(self):
 
        return False
 

	
 

	
 
class FakeConfig:
 
    def __init__(self, responder, argvars=None):
 
        self.responder = responder
 
        self.args = argparse.Namespace()
 
        if argvars is not None:
0 comments (0 inline, 0 general)