def test_config_with_api_key(self, config_with_api_key): with patch.object(requests, "get", wraps=requests.get) as wrapped_get: resolver = Resolver.parse(config_with_api_key) resolver.lookup_schema( "iglu:com.snowplowanalytics.self-desc/schema/jsonschema/1-0-0") wrapped_get.assert_called_with( "http://iglucentral.com/schemas/com.snowplowanalytics.self-desc/schema/jsonschema/1-0-0", headers={"apiKey": "fake-key"}, timeout=3, )
def test_resolve_cache_invalidated_per_cacheTtl(self, config_with_cacheTtl): resolver = Resolver.parse(config_with_cacheTtl) assert len(resolver.cache) == 0 schema = resolver.lookup_schema( "iglu:com.snowplowanalytics.iglu/resolver-config/jsonschema/1-0-0") assert len(resolver.cache) == 1 time.sleep(resolver.cacheTtl) schema = resolver.lookup_schema( "iglu:com.snowplowanalytics.iglu/resolver-config/jsonschema/1-0-0") assert len(resolver.cache) == 1 assert schema["self"]["version"] == "1-0-0"
def test_stores_schemas_in_cache(self, json_config): ref_config = RegistryRefConfig("Test registry ref", 5, []) registry = HttpRegistryRef(ref_config, "http://iglucentral.com") resolver = Resolver([registry]) key1 = SchemaKey( "com.snowplowanalytics.snowplow.enrichments", "api_request_enrichment_config", "jsonschema", SchemaVer(1, 0, 0), ) key2 = SchemaKey( "com.snowplowanalytics.snowplow", "duplicate", "jsonschema", SchemaVer(1, 0, 0), ) key3 = SchemaKey( "com.snowplowanalytics.iglu", "resolver-config", "jsonschema", SchemaVer(1, 0, 0), ) key4 = SchemaKey( "com.snowplowanalytics.iglu", "resolver-config", "jsonschema", SchemaVer(1, 0, 0), ) resolver.lookup_schema(key1) resolver.lookup_schema(key2) resolver.lookup_schema(key2) resolver.lookup_schema(key3) resolver.lookup_schema(key4) assert len(resolver.cache) == 3
def resolver(): ref_config = RegistryRefConfig("Test registry ref", 5, []) registry = HttpRegistryRef(ref_config, "http://iglucentral.com") return Resolver([registry])
def test_invalid_config_throws_error(self, invalid_config): with pytest.raises(IgluError): Resolver.parse(invalid_config)
def test_config_with_null_cacheTtl(self, config_with_null_cacheTtl): resolver = Resolver.parse(config_with_null_cacheTtl) assert len(resolver.registries) == 2 assert resolver.cacheTtl is None assert resolver.registries[1].config.name == "Iglu Central"
def test_standard_configuration(self, json_config): resolver = Resolver.parse(json_config) assert len(resolver.registries) == 3 assert resolver.cacheTtl is None assert resolver.registries[1].config.name == "Iglu Central" assert resolver.registries[2].config.name == "Iglu Local"