-
Notifications
You must be signed in to change notification settings - Fork 16
Expand file tree
/
Copy pathtest_deploy.py
More file actions
161 lines (132 loc) · 5.53 KB
/
test_deploy.py
File metadata and controls
161 lines (132 loc) · 5.53 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
"""Client tests"""
from collections import OrderedDict
import pytest
from databusclient.api.deploy import (
create_dataset,
create_distribution,
get_file_info,
_get_content_variants,
BadArgumentException,
)
from databusclient.cli import parse_distribution_str
EXAMPLE_URL = "https://raw.githubusercontent.com/dbpedia/databus/608482875276ef5df00f2360a2f81005e62b58bd/server/app/api/swagger.yml"
def test_parse_distribution_str():
"""Test the new pipe-separated distribution string parser"""
# Test with multiple content variants
result = parse_distribution_str("http://example.com/data|lang=en|type=full|sorted=true|.ttl|.gz")
assert result["url"] == "http://example.com/data"
assert result["variants"] == {"lang": "en", "type": "full", "sorted": "true"}
assert result["formatExtension"] == "ttl"
assert result["compression"] == "gz"
# Test with single content variant
result = parse_distribution_str("http://mysite.com/data.json|lang=fr|.json")
assert result["url"] == "http://mysite.com/data.json"
assert result["variants"] == {"lang": "fr"}
assert result["formatExtension"] == "json"
assert result["compression"] is None
# Test URL only
result = parse_distribution_str("http://example.com/file.csv")
assert result["url"] == "http://example.com/file.csv"
assert result["variants"] == {}
assert result["formatExtension"] is None
assert result["compression"] is None
# Test with compression only (no format extension)
result = parse_distribution_str("http://example.com/data|.gz")
assert result["url"] == "http://example.com/data"
assert result["compression"] == "gz"
def test_get_content_variants():
# With content variants
cvs = _get_content_variants(
"https://example.com/file.ttl|lang=en_type=parsed|ttl|none|sha256hash|12345"
)
assert cvs == {
"lang": "en",
"type": "parsed",
}
# Without content variants
cvs = _get_content_variants(
"https://example.com/file.ttl||ttl|none|sha256hash|12345"
)
assert cvs == {}
csv = _get_content_variants("https://example.com/file.ttl")
assert csv == {}
# Wrong format
with pytest.raises(BadArgumentException):
_ = _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()
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
# test by leaving out an argument each
artifact_name = "databusclient-pytest"
uri = "https://raw.githubusercontent.com/dbpedia/databus/master/server/app/api/swagger.yml"
parameters = list(metadata_args_with_filler.keys())
for i in range(0, len(metadata_args_with_filler.keys())):
if i == 1:
continue
dst_string = f"{uri}"
for j in range(0, len(metadata_args_with_filler.keys())):
if j == i:
replacement = metadata_args_with_filler[parameters[j]]
if replacement is None:
pass
else:
dst_string += f"|{replacement}"
else:
dst_string += f"|{parameters[j]}"
print(f"{dst_string=}")
(
name,
cvs,
formatExtension,
compression,
sha256sum,
content_length,
) = get_file_info(artifact_name, dst_string)
created_dst_str = create_distribution(
uri, cvs, formatExtension, compression, (sha256sum, content_length)
)
assert dst_string == created_dst_str
@pytest.mark.skip(reason="temporarily disabled since code needs fixing")
def test_empty_cvs():
dst = [create_distribution(url=EXAMPLE_URL, cvs={})]
dataset = create_dataset(
version_id="https://dev.databus.dbpedia.org/user/group/artifact/1970.01.01/",
title="Test Title",
abstract="Test abstract blabla",
description="Test description blabla",
license_url="https://license.url/test/",
distributions=dst,
)
correct_dataset = {
"@context": "https://downloads.dbpedia.org/databus/context.jsonld",
"@graph": [
{
"@type": "Dataset",
"@id": "https://dev.databus.dbpedia.org/user/group/artifact/1970.01.01#Dataset",
"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",
}
],
}
],
}
assert dataset == correct_dataset