Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
68 changes: 40 additions & 28 deletions tests/test_deploy.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,56 +39,63 @@ def test_get_content_variants():
_ = _get_content_variants("https://example.com/file.ttl|invalidformat")


@pytest.mark.skip(reason="temporarily disabled since code needs fixing")
def test_distribution_cases():
metadata_args_with_filler = OrderedDict()
EXAMPLE_SHA256 = "088e6161bf8b4861bdd4e9f517be4441b35a15346cb9d2d3c6d2e3d6cd412030"
EXAMPLE_SIZE = 59986


def test_distribution_cases(monkeypatch):
monkeypatch.setattr(
"databusclient.api.deploy._load_file_stats",
lambda _url: (EXAMPLE_SHA256, EXAMPLE_SIZE),
)

metadata_args_with_filler = OrderedDict()
metadata_args_with_filler["type=config_source=databus"] = ""
metadata_args_with_filler["yml"] = None
metadata_args_with_filler["none"] = None
metadata_args_with_filler[
"79582a2a7712c0ce78a74bb55b253dc2064931364cf9c17c827370edf9b7e4f1:56737"
] = None
metadata_args_with_filler[f"{EXAMPLE_SHA256}:{EXAMPLE_SIZE}"] = None

# test by leaving out an argument each
artifact_name = "databusclient-pytest"
uri = "https://raw.githubusercontent.com/dbpedia/databus/master/server/app/api/swagger.yml"
uri = EXAMPLE_URL
parameters = list(metadata_args_with_filler.keys())
full_dst_string = f"{uri}|{'|'.join(parameters)}"

for i in range(0, len(metadata_args_with_filler.keys())):
for i in range(len(parameters)):
if i == 1:
continue

dst_string = f"{uri}"
for j in range(0, len(metadata_args_with_filler.keys())):
for j in range(len(parameters)):
if j == i:
replacement = metadata_args_with_filler[parameters[j]]
if replacement is None:
pass
else:
if replacement is not None:
dst_string += f"|{replacement}"
else:
dst_string += f"|{parameters[j]}"

print(f"{dst_string=}")
(
name,
cvs,
formatExtension,
format_extension,
compression,
sha256sum,
content_length,
) = get_file_info(artifact_name, dst_string)
) = get_file_info(dst_string)

created_dst_str = create_distribution(
uri, cvs, formatExtension, compression, (sha256sum, content_length)
uri, cvs, format_extension, compression, (sha256sum, content_length)
)

assert dst_string == created_dst_str
# Omitting compression (i == 2) or stats (i == 3) resolves to defaults
expected_dst_str = dst_string if i == 0 else full_dst_string
assert created_dst_str == expected_dst_str


@pytest.mark.skip(reason="temporarily disabled since code needs fixing")
def test_empty_cvs():
def test_empty_cvs(monkeypatch):
monkeypatch.setattr(
"databusclient.api.deploy._load_file_stats",
lambda _url: (EXAMPLE_SHA256, EXAMPLE_SIZE),
)

dst = [create_distribution(url=EXAMPLE_URL, cvs={})]

dataset = create_dataset(
Expand All @@ -104,26 +111,31 @@ def test_empty_cvs():
"@context": "https://downloads.dbpedia.org/databus/context.jsonld",
"@graph": [
{
"@type": "Dataset",
"@id": "https://dev.databus.dbpedia.org/user/group/artifact/1970.01.01#Dataset",
"@id": "https://dev.databus.dbpedia.org/user/group/artifact",
"@type": "Artifact",
"title": "Test Title",
"abstract": "Test abstract blabla",
"description": "Test description blabla",
},
{
"@type": ["Version", "Dataset"],
"@id": "https://dev.databus.dbpedia.org/user/group/artifact/1970.01.01",
"hasVersion": "1970.01.01",
"title": "Test Title",
"abstract": "Test abstract blabla",
"description": "Test description blabla",
"license": "https://license.url/test/",
"distribution": [
{
"@id": "https://dev.databus.dbpedia.org/user/group/artifact/1970.01.01#artifact.yml",
"@type": "Part",
"file": "https://dev.databus.dbpedia.org/user/group/artifact/1970.01.01/artifact.yml",
"formatExtension": "yml",
"compression": "none",
"downloadURL": EXAMPLE_URL,
"byteSize": 59986,
"sha256sum": "088e6161bf8b4861bdd4e9f517be4441b35a15346cb9d2d3c6d2e3d6cd412030",
"byteSize": EXAMPLE_SIZE,
"sha256sum": EXAMPLE_SHA256,
}
],
}
},
],
}

Expand Down
Loading