1818# HELPERS
1919def _download_url (url : str , file : Path ):
2020 # 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 :
2222 shutil .copyfileobj (response , out_file )
2323 assert file .exists ()
2424
@@ -36,6 +36,20 @@ def _convert_to_simcore_labels(image_labels: Dict) -> Dict:
3636 assert len (io_simcore_labels ) > 0
3737 return io_simcore_labels
3838
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+
3953# FIXTURES
4054@pytest .fixture
4155def osparc_service_labels_jsonschema (tmp_path ) -> Dict :
@@ -47,34 +61,43 @@ def osparc_service_labels_jsonschema(tmp_path) -> Dict:
4761 return json_schema
4862
4963
50- @pytest .fixture (scope = ' session' )
64+ @pytest .fixture (scope = " session" )
5165def metadata_labels (metadata_file : Path ) -> Dict :
5266 with metadata_file .open () as fp :
5367 metadata = yaml .safe_load (fp )
5468 return metadata
5569
70+
5671# TESTS
5772
5873
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+ ):
6077 image_labels = docker_image .labels
6178 io_simcore_labels = _convert_to_simcore_labels (image_labels )
6279 # check files are identical
6380 for key , value in io_simcore_labels .items ():
6481 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 ]
6687
6788
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+ ):
6992 image_labels = docker_image .labels
7093 # get io labels
7194 io_simcore_labels = _convert_to_simcore_labels (image_labels )
7295 # validate schema
7396 try :
74- jsonschema .validate (io_simcore_labels ,
75- osparc_service_labels_jsonschema )
97+ jsonschema .validate (io_simcore_labels , osparc_service_labels_jsonschema )
7698 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+ )
79102 except jsonschema .ValidationError :
80103 pytest .fail ("Failed to validate docker image io labels against schema" )
0 commit comments