-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
252486c
commit c9ddc2e
Showing
2 changed files
with
92 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,68 @@ | ||
from io import BytesIO | ||
import json | ||
import pytest | ||
import yaml | ||
|
||
from dcpy.test.conftest import RECIPES_BUCKET | ||
from dcpy.models.lifecycle.ingest import Template | ||
from dcpy.lifecycle.ingest import configure, transform | ||
from dcpy.utils import s3 | ||
from dcpy.connectors.edm import recipes | ||
from dcpy.lifecycle.ingest import configure, transform, validate | ||
|
||
from .shared import ( | ||
TEST_DATASET, | ||
TEST_OUTPUT, | ||
BASIC_CONFIG, | ||
BASIC_LIBRARY_CONFIG, | ||
) | ||
|
||
|
||
@pytest.mark.parametrize("dataset", [t.name for t in configure.TEMPLATE_DIR.glob("*")]) | ||
def test_validate_all_datasets(dataset): | ||
def test_validate_all_templates(dataset): | ||
with open(configure.TEMPLATE_DIR / dataset, "r") as f: | ||
s = yaml.safe_load(f) | ||
template = Template(**s) | ||
transform.validate_processing_steps( | ||
template.id, template.ingestion.processing_steps | ||
) | ||
|
||
|
||
class TestValidateAgainstExistingVersions: | ||
def test_new(self, create_buckets): | ||
assert ( | ||
validate.validate_against_existing_versions(TEST_DATASET, TEST_OUTPUT) | ||
== validate.ArchiveAction.push | ||
) | ||
|
||
def test_existing_library(self, create_buckets): | ||
ds = BASIC_LIBRARY_CONFIG.sparse_dataset | ||
config_str = json.dumps(BASIC_LIBRARY_CONFIG.model_dump(mode="json")) | ||
s3.upload_file_obj( | ||
BytesIO(config_str.encode()), | ||
RECIPES_BUCKET, | ||
f"{recipes.s3_folder_path(ds)}/config.json", | ||
BASIC_LIBRARY_CONFIG.dataset.acl, | ||
) | ||
assert recipes.exists(ds) | ||
assert ( | ||
validate.validate_against_existing_versions(ds, TEST_OUTPUT) | ||
== validate.ArchiveAction.do_nothing | ||
) | ||
|
||
def test_existing(self, create_buckets): | ||
ds = BASIC_CONFIG.dataset | ||
recipes.archive_dataset(BASIC_CONFIG, TEST_OUTPUT) | ||
assert recipes.exists(ds) | ||
assert ( | ||
validate.validate_against_existing_versions(ds, TEST_OUTPUT) | ||
== validate.ArchiveAction.update_freshness | ||
) | ||
|
||
def test_existing_data_diffs(self, create_buckets): | ||
ds = BASIC_CONFIG.dataset | ||
recipes.archive_dataset(BASIC_CONFIG, TEST_OUTPUT) | ||
assert recipes.exists(ds) | ||
with pytest.raises(FileExistsError): | ||
validate.validate_against_existing_versions( | ||
ds, TEST_OUTPUT.parent / "test.parquet" | ||
) |