def test_descriptor_dereference_pointer(): descriptor = { 'name': 'name', 'data': 'data', 'schema': '#/schemas/main', 'schemas': { 'main': { 'fields': [{ 'name': 'name' }] } }, } resource = Resource(descriptor) assert resource.descriptor == expand({ 'name': 'name', 'data': 'data', 'schema': { 'fields': [{ 'name': 'name' }] }, 'schemas': { 'main': { 'fields': [{ 'name': 'name' }] } }, })
def test_descriptor_retrieve_dict(): descriptor = { 'name': 'name', 'data': 'data', } actual = Resource(descriptor).descriptor expect = expand(descriptor) assert actual == expect
def test_descriptor_dereference(): descriptor = 'data/resource_with_dereferencing.json' resource = Resource(descriptor) assert resource.descriptor == expand({ 'name': 'name', 'data': 'data', 'schema': {'fields': [{'name': 'name'}]}, 'dialect': {'delimiter': ','}, 'dialects': {'main': {'delimiter': ','}}, })
def test_descriptor_retrieve_url(patch_get): descriptor = 'http://example.com/descriptor.json' descriptor_contents = { 'name': 'name', 'data': 'data', } # Mocks patch_get(descriptor, body=json.dumps(descriptor_contents)) # Tests actual = Resource(descriptor).descriptor expect = expand(descriptor_contents) assert actual == expect
def test_descriptor_dereference_local(): descriptor = { 'name': 'name', 'data': 'data', 'schema': 'table_schema.json', } resource = Resource(descriptor, base_path='data') assert resource.descriptor == expand({ 'name': 'name', 'data': 'data', 'schema': {'fields': [{'name': 'name'}]}, })
def test_descriptor_dereference_pointer(): descriptor = { 'name': 'name', 'data': 'data', 'schema': '#/schemas/main', 'schemas': {'main': {'fields': [{'name': 'name'}]}}, } resource = Resource(descriptor) assert resource.descriptor == expand({ 'name': 'name', 'data': 'data', 'schema': {'fields': [{'name': 'name'}]}, 'schemas': {'main': {'fields': [{'name': 'name'}]}}, })
def test_descriptor_dereference_remote(patch_get): descriptor = { 'name': 'name', 'data': 'data', 'schema': 'http://example.com/schema', } # Mocks patch_get('http://example.com/schema', body='{"fields": [{"name": "name"}]}') # Tests resource = Resource(descriptor) assert resource.descriptor == expand({ 'name': 'name', 'data': 'data', 'schema': {'fields': [{'name': 'name'}]}, })
def test_descriptor_retrieve_path(): descriptor = 'data/data-resource.json' actual = Resource(descriptor).descriptor expect = expand(json.load(io.open(descriptor, encoding='utf-8'))) assert actual == expect