-
Notifications
You must be signed in to change notification settings - Fork 612
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix schema, make it stricter, add tests (#705)
* Fix schema, make it stricter, add tests * format
- Loading branch information
Showing
3 changed files
with
173 additions
and
54 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -82,6 +82,87 @@ def test_parse_and_check_format(self): | |
class TestValidateSchema(unittest.TestCase): | ||
"""A test suite for the validate_schema function of RwsCheck""" | ||
|
||
def test_valid_associated(self): | ||
json_dict = { | ||
"sets": [ | ||
{ | ||
"contact": "[email protected]", | ||
"primary": "https://primary.com", | ||
"associatedSites": ["https://associated1.com"], | ||
"rationaleBySite": { | ||
"https://associated1.com": "example rationale", | ||
}, | ||
} | ||
] | ||
} | ||
rws_check = RwsCheck(rws_sites=json_dict, etlds=None, icanns=set(["ca"])) | ||
rws_check.validate_schema("SCHEMA.json") | ||
|
||
def test_valid_service(self): | ||
json_dict = { | ||
"sets": [ | ||
{ | ||
"contact": "[email protected]", | ||
"primary": "https://primary.com", | ||
"serviceSites": ["https://service1.com"], | ||
"rationaleBySite": { | ||
"https://service1.com": "example rationale", | ||
}, | ||
} | ||
] | ||
} | ||
rws_check = RwsCheck(rws_sites=json_dict, etlds=None, icanns=set(["ca"])) | ||
rws_check.validate_schema("SCHEMA.json") | ||
|
||
def test_valid_ccTLDs(self): | ||
json_dict = { | ||
"sets": [ | ||
{ | ||
"contact": "[email protected]", | ||
"primary": "https://primary.com", | ||
"ccTLDs": {"https://primary.com": ["https://primary.ca"]}, | ||
} | ||
] | ||
} | ||
rws_check = RwsCheck(rws_sites=json_dict, etlds=None, icanns=set(["ca"])) | ||
rws_check.validate_schema("SCHEMA.json") | ||
|
||
def test_valid_full(self): | ||
json_dict = { | ||
"sets": [ | ||
{ | ||
"contact": "[email protected]", | ||
"primary": "https://primary.com", | ||
"associatedSites": ["https://associated1.com"], | ||
"serviceSites": ["https://service1.com"], | ||
"rationaleBySite": { | ||
"https://associated1.com": "example rationale", | ||
"https://service1.com": "example rationale", | ||
}, | ||
"ccTLDs": {"https://associated1.com": ["https://associated1.ca"]}, | ||
} | ||
] | ||
} | ||
rws_check = RwsCheck(rws_sites=json_dict, etlds=None, icanns=set(["ca"])) | ||
rws_check.validate_schema("SCHEMA.json") | ||
|
||
def test_duplicate_set(self): | ||
entry = { | ||
"contact": "[email protected]", | ||
"primary": "https://primary.com", | ||
"associatedSites": ["https://associated1.com"], | ||
"serviceSites": ["https://service1.com"], | ||
"rationaleBySite": { | ||
"https://associated1.com": "example rationale", | ||
"https://service1.com": "example rationale", | ||
}, | ||
"ccTLDs": {"https://associated1.com": ["https://associated1.ca"]}, | ||
} | ||
json_dict = {"sets": [entry, entry]} | ||
rws_check = RwsCheck(rws_sites=json_dict, etlds=None, icanns=set(["ca"])) | ||
with self.assertRaises(ValidationError): | ||
rws_check.validate_schema("SCHEMA.json") | ||
|
||
def test_no_primary(self): | ||
json_dict = { | ||
"sets": [ | ||
|
@@ -101,6 +182,19 @@ def test_no_primary(self): | |
with self.assertRaises(ValidationError): | ||
rws_check.validate_schema("SCHEMA.json") | ||
|
||
def test_primary_only(self): | ||
json_dict = { | ||
"sets": [ | ||
{ | ||
"contact": "[email protected]", | ||
"primary": "https://primary.com", | ||
} | ||
] | ||
} | ||
rws_check = RwsCheck(rws_sites=json_dict, etlds=None, icanns=set(["ca"])) | ||
with self.assertRaises(ValidationError): | ||
rws_check.validate_schema("SCHEMA.json") | ||
|
||
def test_no_rationaleBySite(self): | ||
json_dict = { | ||
"sets": [ | ||
|
@@ -150,6 +244,71 @@ def test_no_contact(self): | |
with self.assertRaises(ValidationError): | ||
rws_check.validate_schema("SCHEMA.json") | ||
|
||
def test_nonunique_associated_sites(self): | ||
json_dict = { | ||
"sets": [ | ||
{ | ||
"contact": "[email protected]", | ||
"primary": "https://primary.com", | ||
"associatedSites": [ | ||
"https://associated1.com", | ||
"https://associated1.com", | ||
], | ||
"rationaleBySite": { | ||
"https://associated1.com": "example rationale", | ||
}, | ||
} | ||
] | ||
} | ||
rws_check = RwsCheck(rws_sites=json_dict, etlds=None, icanns=set(["ca"])) | ||
with self.assertRaises(ValidationError): | ||
rws_check.validate_schema("SCHEMA.json") | ||
|
||
def test_nonunique_service_sites(self): | ||
json_dict = { | ||
"sets": [ | ||
{ | ||
"contact": "[email protected]", | ||
"primary": "https://primary.com", | ||
"serviceSites": [ | ||
"https://service1.com", | ||
"https://service1.com", | ||
], | ||
"rationaleBySite": { | ||
"https://service1.com": "example rationale", | ||
}, | ||
} | ||
] | ||
} | ||
rws_check = RwsCheck(rws_sites=json_dict, etlds=None, icanns=set(["ca"])) | ||
with self.assertRaises(ValidationError): | ||
rws_check.validate_schema("SCHEMA.json") | ||
|
||
def test_unexpected_top_level_property(self): | ||
json_dict = {"sets": [], "foo": True} | ||
rws_check = RwsCheck(rws_sites=json_dict, etlds=None, icanns=set(["ca"])) | ||
with self.assertRaises(ValidationError): | ||
rws_check.validate_schema("SCHEMA.json") | ||
|
||
def test_unexpected_set_level_property(self): | ||
json_dict = { | ||
"sets": [ | ||
{ | ||
"contact": "[email protected]", | ||
"primary": "https://primary.com", | ||
"associatedSites": ["https://associated1.com"], | ||
"rationaleBySite": { | ||
"https://associated1.com": "example rationale", | ||
}, | ||
"ccTLDs": {"https://associated1.com": ["https://associated1.ca"]}, | ||
"foo": True, | ||
} | ||
] | ||
} | ||
rws_check = RwsCheck(rws_sites=json_dict, etlds=None, icanns=set(["ca"])) | ||
with self.assertRaises(ValidationError): | ||
rws_check.validate_schema("SCHEMA.json") | ||
|
||
|
||
class TestRwsSetEqual(unittest.TestCase): | ||
def test_equal_case(self): | ||
|