def test_resource_schema_objects_w_cache(self, rmock, mocker): cache_mock_set = mocker.patch.object(cache, 'set') mocker.patch.object(cache, 'get', return_value='dummy_from_cache') # fill cache rmock.get('https://example.com/schemas', json={ "schemas": [{ "name": "etalab/schema-irve", "title": "Schéma IRVE", "versions": [{ "version_name": "1.0.0" }, { "version_name": "1.0.1" }, { "version_name": "1.0.2" }] }] }) ResourceSchema.objects() assert cache_mock_set.called rmock.get('https://example.com/schemas', status_code=500) assert 'dummy_from_cache' == ResourceSchema.objects() assert rmock.call_count == 2
def test_resource_schema_objects(self, app, rmock): rmock.get('https://example.com/schemas', json={ "schemas": [{ "name": "etalab/schema-irve", "title": "Schéma IRVE", "versions": [{ "version_name": "1.0.0" }, { "version_name": "1.0.1" }, { "version_name": "1.0.2" }] }] }) assert ResourceSchema.objects() == [{ "id": "etalab/schema-irve", "label": "Schéma IRVE", "versions": ["1.0.0", "1.0.1", "1.0.2"] }]
def test_resource_schema_objects_no_catalog_url(self): assert ResourceSchema.objects() == []
def test_resource_schema_objects_timeout_no_cache(self, client, rmock): rmock.get('https://example.com/schemas', exc=requests.exceptions.ConnectTimeout) with pytest.raises(SchemasCacheUnavailableException): ResourceSchema.objects()
def test_resource_schema_objects_404_endpoint(self): with pytest.raises(SchemasCatalogNotFoundException): ResourceSchema.objects()
def test_resource_schema_objects(self, app, rmock): rmock.get('https://example.com/schemas', json={ 'schemas': [{"name": "etalab/schema-irve", "title": "Schéma IRVE"}] }) assert ResourceSchema.objects() == [{"id": "etalab/schema-irve", "label": "Schéma IRVE"}]