Ejemplo n.º 1
0
def test_invalid_json_schema():
    conf = BQTestKitConfig({DEFAULT_LOCATION: "EU"})
    project = Project("test_project", bq_client=None, bqtk_config=conf)
    ds = Dataset("dataset_foo",
                 project=project,
                 bq_client=None,
                 bqtk_config=conf)
    table = Table("table_bar",
                  from_dataset=ds,
                  bq_client=None,
                  bqtk_config=conf)
    with pytest.raises(JSONDecodeError):
        table.with_schema(from_="this is not a json")
Ejemplo n.º 2
0
def test_invalid_change_schema():
    conf = BQTestKitConfig({DEFAULT_LOCATION: "EU"})
    project = Project("test_project", bq_client=None, bqtk_config=conf)
    ds = Dataset("dataset_foo",
                 project=project,
                 bq_client=None,
                 bqtk_config=conf)
    table = Table("table_bar",
                  from_dataset=ds,
                  bq_client=None,
                  bqtk_config=conf)
    with pytest.raises(InvalidInstanceException):
        table.with_schema(from_=[1, 2, 3])
    with pytest.raises(InvalidInstanceException):
        table.with_schema(from_=1)
Ejemplo n.º 3
0
def test_change_schema():
    conf = BQTestKitConfig({DEFAULT_LOCATION: "EU"})
    project = Project("test_project", bq_client=None, bqtk_config=conf)
    ds = Dataset("dataset_foo",
                 project=project,
                 bq_client=None,
                 bqtk_config=conf)
    table = Table("table_bar",
                  from_dataset=ds,
                  bq_client=None,
                  bqtk_config=conf)
    table = table.with_schema(from_="""
        [
            {
                "description": "field 1",
                "mode": "REQUIRED",
                "name": "f1",
                "type": "STRING"
            }
        ]""")
    assert table.schema == [
        SchemaField("f1",
                    field_type="STRING",
                    mode="REQUIRED",
                    description="field 1")
    ]