Beispiel #1
0
def test_publish_update_locally_is_true(pytest_dataset: Metadata):
    date_before = pytest_dataset.local_metadata.get('metadata_modified')

    # update local metadata
    new_metadata = pytest_dataset.local_metadata.copy()

    # generate random strings with 3 characters
    random_string = "".join(
        random.choice(string.ascii_uppercase) for _ in range(3))

    # update metadata tags with random_string
    new_metadata["tags"] = [random_string]
    ryaml.dump(new_metadata, open(new_metadata.filepath, "w",
                                  encoding="utf-8"))

    # publish changes
    pytest_dataset.publish(update_locally=True)

    # get new tags from local metadata
    new_tags = pytest_dataset.local_metadata.get('tags')

    # get new `metadata_modified` value from local config file
    date_after = pytest_dataset.local_metadata.get('metadata_modified')

    assert new_tags == [random_string], "Tags were not updated locally"
    assert date_after > date_before, "Date after should be greater than date before"
Beispiel #2
0
def test_publish_is_not_successful(
    invalid_dataset_metadata: Metadata,
    invalid_table_metadata: Metadata,
):
    with pytest.raises(AssertionError, match="Could not publish"):
        invalid_dataset_metadata.publish()

    with pytest.raises(BaseDosDadosException, match="Could not publish"):
        invalid_table_metadata.publish()
Beispiel #3
0
def test_publish_all_is_true(
    pytest_dataset: Metadata,
    pytest_table: Metadata,
):
    res = pytest_table.publish(all=True)
    assert isinstance(res, dict)
    assert res != {}
    assert pytest_dataset.exists_in_ckan()
Beispiel #4
0
def test_publish_if_exists_pass(valid_metadata_dataset: Metadata):
    assert isinstance(valid_metadata_dataset.publish(if_exists="pass"), dict)
    assert valid_metadata_dataset.publish(if_exists="pass") == {}
Beispiel #5
0
def test_publish_if_exists_replace(valid_metadata_dataset: Metadata):
    res = valid_metadata_dataset.publish(if_exists="replace")
    assert isinstance(res, dict)
    assert res != {}
Beispiel #6
0
def test_publish_if_exists_raise(valid_metadata_dataset: Metadata):
    with pytest.raises(BaseDosDadosException, match="already exists in CKAN"):
        valid_metadata_dataset.publish(if_exists="raise")
Beispiel #7
0
def test_publish_is_successful(
    valid_metadata_dataset: Metadata,
    valid_metadata_table: Metadata,
):
    assert isinstance(valid_metadata_dataset.publish(), dict)
    assert isinstance(valid_metadata_table.publish(), dict)