Esempio n. 1
0
def test_global_dict():
    pfl = PackageFileLoader("tests/ut/bq_test_kit/bq_dsl/resources/dummy_query.sql")
    conf = BQTestKitConfig({DEFAULT_LOCATION: "EU"})
    bq_tpl = BQQueryTemplate(from_=pfl, bqtk_config=conf, bq_client=None, interpolators=[DummyInterpolator()])
    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_with_alias = Table("table_bar", from_dataset=ds, bq_client=None, bqtk_config=conf).with_alias("table_foobar")
    bq_tpl = bq_tpl.with_global_dict({"test_project": "unknown"})
    assert bq_tpl.global_dict == {"test_project": "unknown"}
    bq_tpl = bq_tpl.update_global_dict([table, ds, project, table_with_alias])
    assert bq_tpl.global_dict == {
                                    "test_project": project.fqdn(),
                                    "dataset_foo": ds.fqdn(),
                                    "dataset_foo_table_bar": table.fqdn(),
                                    "table_foobar": table_with_alias.fqdn()
                                 }
    bq_tpl = bq_tpl.update_global_dict({"dataset_foo_table_bar": "my_override",
                                        "new_complex_key": {"new_key": "new_value"}})
    assert bq_tpl.global_dict == {
                                    "test_project": project.fqdn(),
                                    "dataset_foo": ds.fqdn(),
                                    "dataset_foo_table_bar": "my_override",
                                    "table_foobar": table_with_alias.fqdn(),
                                    "new_complex_key": {"new_key": "new_value"}
                                 }
def test_change_isolate():
    conf = BQTestKitConfig({
        DEFAULT_LOCATION: "EU"
    }).with_test_context("context")
    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.isolate()
    assert table.isolate_func(table) == f"{table.name}_context"
    assert table.fqdn() == (f"{table.dataset.project.name}."
                            f"{table.dataset.name}."
                            f"{table.name}_context")