def test_get_s3_json_content(): """ Just test an S3 bucket and key that doesn't exist """ ctx = Context() ctx['utils'] = utils = MockUtils() ctx['clock'] = Clock() cache = JSONCache(ctx) jdata = cache.get_s3_json_content("taar_not_my_bucket", "this/is/not/a/valid/path") assert jdata == EXPECTED_S3_JSON assert utils._get_count == 1 for i in range(10): cache.get_s3_json_content("taar_not_my_bucket", "this/is/not/a/valid/path") assert utils._get_count == 1
def test_expiry(): """ Just test a URL that we know will fail """ class MockClock: def __init__(self): self._now = 100 def time(self): return self._now ctx = Context() utils = MockUtils() ctx['utils'] = utils ctx['clock'] = MockClock() cache = JSONCache(ctx) cache._ttl = 0 # Set TTL to nothing cache.refresh_expiry() jdata = cache.fetch_json( "http://127.0.0.1:9001/some-nonexistant-url-foo.json") assert jdata == EXPECTED_JSON jdata = cache.get_s3_json_content("taar_not_my_bucket", "this/is/not/a/valid/path") assert jdata == EXPECTED_S3_JSON assert utils._get_count == 1 assert utils._fetch_count == 1 for i in range(10): cache.fetch_json("http://127.0.0.1:9001/some-nonexistant-url-foo.json") cache.get_s3_json_content("taar_not_my_bucket", "this/is/not/a/valid/path") # Cache expires each time assert utils._get_count == 11 assert utils._fetch_count == 11