1
+ import copy
1
2
import os
2
3
3
4
import json
@@ -26,6 +27,33 @@ def registry_content(request):
26
27
return content
27
28
28
29
30
+ @pytest .fixture
31
+ def registry_content_with_services (registry_content ):
32
+ any_svc_key = list (registry_content )[0 ]
33
+ registry_content ["test" ] = copy .deepcopy (registry_content [any_svc_key ])
34
+ registry_content ["test" ]["services" ] = [
35
+ {
36
+ "name" : "test-service" ,
37
+ "keywords" : ["other" ],
38
+ "description" : "test service" ,
39
+ "version" : "1.2.3" ,
40
+ "links" : [
41
+ {
42
+ "rel" : "service" ,
43
+ "href" : "https://example.com/test" ,
44
+ "type" : "application/json"
45
+ },
46
+ {
47
+ "rel" : "service-doc" ,
48
+ "href" : "https://readthedocs.com/example" ,
49
+ "type" : "text/html"
50
+ }
51
+ ]
52
+ }
53
+ ]
54
+ return registry_content
55
+
56
+
29
57
@pytest .fixture
30
58
def schema_content (request ):
31
59
"""Return the content contained in node_registry.schema.json"""
@@ -38,3 +66,43 @@ def schema_content(request):
38
66
39
67
def test_valid_registry (registry_content , schema_content ):
40
68
jsonschema .validate (registry_content , schema_content )
69
+
70
+
71
+ def test_services_good_version (registry_content_with_services , schema_content ):
72
+ jsonschema .validate (registry_content_with_services , schema_content )
73
+
74
+
75
+ def test_services_bad_version (registry_content_with_services , schema_content ):
76
+ registry_content_with_services ["test" ]["services" ][0 ]["version" ] = "bad_version"
77
+ with pytest .raises (jsonschema .exceptions .ValidationError ) as exc :
78
+ jsonschema .validate (registry_content_with_services , schema_content )
79
+ assert "bad_version" in exc .value .message
80
+ assert list (exc .value .path ) == ["test" , "services" , 0 , "version" ]
81
+ assert list (exc .value .schema_path )[- 6 :] == ["properties" , "services" , "items" , "properties" , "version" , "pattern" ]
82
+
83
+
84
+ def test_services_bad_links (registry_content_with_services , schema_content ):
85
+ registry_content_with_services ["test" ]["services" ][0 ].pop ("links" )
86
+ with pytest .raises (jsonschema .exceptions .ValidationError ) as exc :
87
+ jsonschema .validate (registry_content_with_services , schema_content )
88
+ assert exc .value .message == "'links' is a required property"
89
+ assert list (exc .value .path ) == ["test" , "services" , 0 ]
90
+ assert list (exc .value .schema_path )[- 4 :] == ["properties" , "services" , "items" , "required" ]
91
+
92
+
93
+ @pytest .mark .parametrize (
94
+ ["required_link_rel" , "expected_link_pos" ],
95
+ [
96
+ ("service" , 0 ),
97
+ ("service-doc" , 1 ),
98
+ ]
99
+ )
100
+ def test_services_missing_link (registry_content_with_services , schema_content , required_link_rel , expected_link_pos ):
101
+ links = registry_content_with_services ["test" ]["services" ][0 ]["links" ]
102
+ links = [link for link in links if link ["rel" ] != required_link_rel ]
103
+ registry_content_with_services ["test" ]["services" ][0 ]["links" ] = links
104
+ with pytest .raises (jsonschema .exceptions .ValidationError ) as exc :
105
+ jsonschema .validate (registry_content_with_services , schema_content )
106
+ assert "does not contain" in exc .value .message
107
+ assert list (exc .value .path ) == ["test" , "services" , 0 , "links" ]
108
+ assert list (exc .value .schema_path )[- 4 :] == ["links" , "allOf" , expected_link_pos , "contains" ]
0 commit comments