Esempio n. 1
0
def test_save_data_to_json():
    resource = Resource({'data': [['id'], [1], [2], [3]]})
    resource.save('tmp/data.json')
    with open('tmp/data.json', 'r') as test_file:
        assert json.loads(test_file.read()) == {
            'data': [['id'], [1], [2], [3]],
            'profile': 'data-resource'
        }
Esempio n. 2
0
def test_save_data_to_json_base_path():
    resource = Resource({'data': [['id'], [1], [2], [3]]}, base_path='tmp')
    resource.save('data.json', to_base_path=True)
    with open('tmp/data.json', 'r') as test_file:
        assert json.loads(test_file.read()) == {
            'data': [['id'], [1], [2], [3]],
            'profile': 'data-resource'
        }
Esempio n. 3
0
def test_save_data_to_storage():
    SCHEMA = {
        'fields': [{'format': 'default', 'name': 'id', 'type': 'integer'}],
        'missingValues': ['']
    }
    storage = Mock(spec=Storage)
    resource = Resource({'data': [['id'], [1], [2], [3]]})
    resource.save('data', storage=storage)
    storage.create.assert_called_with('data', SCHEMA, force=True)
    storage.write.assert_called_with('data', ANY)
Esempio n. 4
0
def test_save_data_to_storage():
    SCHEMA = {
        'fields': [{
            'format': 'default',
            'name': 'id',
            'type': 'integer'
        }],
        'missingValues': ['']
    }
    storage = Mock(spec=Storage)
    resource = Resource({'data': [['id'], [1], [2], [3]]})
    resource.save('data', storage=storage)
    storage.create.assert_called_with('data', SCHEMA, force=True)
    storage.write.assert_called_with('data', ANY)