Beispiel #1
0
def test_should_cleanup(resource_name, separator, expected, monkeypatch):
    fake_datetime = FakeDateTime(datetime.datetime(2021, 6, 21, 3, 32, 0))
    monkeypatch.setattr(datetime, "datetime", fake_datetime)

    prefixer = test_utils.prefixer.Prefixer("test",
                                            "utils",
                                            separator=separator)
    assert prefixer.should_cleanup(resource_name) == expected
Beispiel #2
0
def pytest_sessionfinish(session):
    dataset_id = config.db.dialect.dataset_id
    _pytest_sessionfinish(session)
    with contextlib.closing(google.cloud.bigquery.Client()) as client:
        client.delete_dataset(dataset_id,
                              delete_contents=True,
                              not_found_ok=True)
        for dataset in client.list_datasets():
            if prefixer.should_cleanup(dataset.dataset_id):
                client.delete_dataset(dataset,
                                      delete_contents=True,
                                      not_found_ok=True)
Beispiel #3
0
def cleanup_datasets(bq_client: bigquery.Client):
    for dataset in bq_client.list_datasets():
        if prefixer.should_cleanup(dataset.dataset_id):
            bq_client.delete_dataset(dataset,
                                     delete_contents=True,
                                     not_found_ok=True)