18
18
# HELPERS
19
19
def _download_url (url : str , file : Path ):
20
20
# Download the file from `url` and save it locally under `file_name`:
21
- with urllib .request .urlopen (url ) as response , file .open ('wb' ) as out_file :
21
+ with urllib .request .urlopen (url ) as response , file .open ("wb" ) as out_file :
22
22
shutil .copyfileobj (response , out_file )
23
23
assert file .exists ()
24
24
@@ -36,6 +36,20 @@ def _convert_to_simcore_labels(image_labels: Dict) -> Dict:
36
36
assert len (io_simcore_labels ) > 0
37
37
return io_simcore_labels
38
38
39
+
40
+ def _is_url (value : str ) -> bool :
41
+ """Check if the value is a URL."""
42
+ return isinstance (value , str ) and (
43
+ value .startswith ("http://" ) or value .startswith ("https://" )
44
+ )
45
+
46
+
47
+ def _fetch_url_content (url : str ) -> str :
48
+ """Fetch content from a URL."""
49
+ with urllib .request .urlopen (url ) as response :
50
+ return response .read ().decode ("utf-8" ).strip ()
51
+
52
+
39
53
# FIXTURES
40
54
@pytest .fixture
41
55
def osparc_service_labels_jsonschema (tmp_path ) -> Dict :
@@ -47,34 +61,43 @@ def osparc_service_labels_jsonschema(tmp_path) -> Dict:
47
61
return json_schema
48
62
49
63
50
- @pytest .fixture (scope = ' session' )
64
+ @pytest .fixture (scope = " session" )
51
65
def metadata_labels (metadata_file : Path ) -> Dict :
52
66
with metadata_file .open () as fp :
53
67
metadata = yaml .safe_load (fp )
54
68
return metadata
55
69
70
+
56
71
# TESTS
57
72
58
73
59
- def test_docker_io_simcore_labels_against_files (docker_image : docker .models .images .Image , metadata_labels : Dict ):
74
+ def test_docker_io_simcore_labels_against_files (
75
+ docker_image : docker .models .images .Image , metadata_labels : Dict
76
+ ):
60
77
image_labels = docker_image .labels
61
78
io_simcore_labels = _convert_to_simcore_labels (image_labels )
62
79
# check files are identical
63
80
for key , value in io_simcore_labels .items ():
64
81
assert key in metadata_labels
65
- assert value == metadata_labels [key ]
82
+ if key == "description" :
83
+ assert _is_url (metadata_labels [key ])
84
+ assert value == _fetch_url_content (metadata_labels [key ])
85
+ else :
86
+ assert value == metadata_labels [key ]
66
87
67
88
68
- def test_validate_docker_io_simcore_labels (docker_image : docker .models .images .Image , osparc_service_labels_jsonschema : Dict ):
89
+ def test_validate_docker_io_simcore_labels (
90
+ docker_image : docker .models .images .Image , osparc_service_labels_jsonschema : Dict
91
+ ):
69
92
image_labels = docker_image .labels
70
93
# get io labels
71
94
io_simcore_labels = _convert_to_simcore_labels (image_labels )
72
95
# validate schema
73
96
try :
74
- jsonschema .validate (io_simcore_labels ,
75
- osparc_service_labels_jsonschema )
97
+ jsonschema .validate (io_simcore_labels , osparc_service_labels_jsonschema )
76
98
except jsonschema .SchemaError :
77
- pytest .fail ("Schema {} contains errors" .format (
78
- osparc_service_labels_jsonschema ))
99
+ pytest .fail (
100
+ "Schema {} contains errors" .format (osparc_service_labels_jsonschema )
101
+ )
79
102
except jsonschema .ValidationError :
80
103
pytest .fail ("Failed to validate docker image io labels against schema" )
0 commit comments