Exemple #1
0
def test_postgresql_storage_comment_support(postgresql_url):

    # Write
    source = Resource(path="data/table.csv")
    source.infer()
    source.schema.get_field("id").description = "integer field"
    source.schema.get_field("name").description = "string field"
    source.to_sql(url=postgresql_url, force=True)

    # Read
    target = Resource.from_sql(url=postgresql_url, name="table")
    assert target.schema == {
        "fields": [
            {
                "name": "id",
                "type": "integer",
                "description": "integer field"
            },
            {
                "name": "name",
                "type": "string",
                "description": "string field"
            },
        ]
    }
    assert target.read_rows() == [
        {
            "id": 1,
            "name": "english"
        },
        {
            "id": 2,
            "name": "中国人"
        },
    ]
Exemple #2
0
def test_sql_storage_resource_url_argument(sqlite_url):
    source = Resource(path="data/table.csv")
    source.to_sql(url=sqlite_url)
    target = Resource.from_sql(name="table", url=sqlite_url)
    assert target.schema == {
        "fields": [
            {
                "name": "id",
                "type": "integer"
            },
            {
                "name": "name",
                "type": "string"
            },
        ]
    }
    assert target.read_rows() == [
        {
            "id": 1,
            "name": "english"
        },
        {
            "id": 2,
            "name": "中国人"
        },
    ]
Exemple #3
0
def test_storage_write_resource_existent_error(database_url):
    engine = sa.create_engine(database_url)
    resource = Resource(path="data/table.csv")
    storage = resource.to_sql(engine=engine)
    with pytest.raises(exceptions.FrictionlessException) as excinfo:
        storage.write_resource(resource)
    error = excinfo.value.error
    assert error.code == "storage-error"
    assert error.note.count("already exists")
    # Cleanup storage
    storage.delete_package(list(storage))