Skip to content

Commit

Permalink
Merge pull request #523 from aviiciii/testing
Browse files Browse the repository at this point in the history
Changes to CI tests
  • Loading branch information
yigitguler authored Jul 14, 2023
2 parents e2030e3 + 2384c83 commit 05ae50b
Show file tree
Hide file tree
Showing 3 changed files with 92 additions and 15 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
language: python
python:
- '3.6'
- '3.11'
script:
- cd tests
- pip install -r requirements.txt
Expand Down
101 changes: 89 additions & 12 deletions tests/test_domains.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,93 @@


class DomainsTests(unittest.TestCase):
def test_json_is_valid(self):
def setUp(self):
"""Load the JSON file into a variable"""
with open("world_universities_and_domains.json", encoding="utf-8") as json_file:
valid_json = json.load(json_file)
for university in valid_json:
self.assertIn("name", university)
self.assertIn("domains", university)
self.assertIsInstance(university["domains"], list)
for domain in university["domains"]:
self.assertTrue(validators.domain(domain))
self.assertIn("web_pages", university)
self.assertIn("alpha_two_code", university)
self.assertIn("state-province", university)
self.assertIn("country", university)
self.valid_json = json.load(json_file)

def test_university_json_structure(self):
"""Test the structure of each university entry in the JSON file"""
for university in self.valid_json:
# Name
self.assertIn("name", university, msg="University Name is missing")
self.assertIsInstance(
university["name"],
(str, type(None)),
msg="University Name must be a string or null",
)
# Domains
self.assertIn("domains", university, msg="University Domains are missing")
self.assertIsInstance(
university["domains"],
(list, type(None)),
msg="University Domains must be a list or null",
)
if university["domains"] is not None:
for domain in university["domains"]:
self.assertIsInstance(
domain,
(str, type(None)),
msg="University Domain must be a string or null",
)
if domain is not None:
self.assertTrue(
validators.domain(domain), msg=f"Invalid domain: {domain}"
)
# Web Pages
self.assertIn(
"web_pages", university, msg="University Web Pages are missing"
)
self.assertIsInstance(
university["web_pages"],
(list, type(None)),
msg="University Web Pages must be a list or null",
)
if university["web_pages"] is not None:
for web_page in university["web_pages"]:
self.assertIsInstance(
web_page,
(str, type(None)),
msg="University Web Page must be a string or null",
)
if web_page is not None:
self.assertTrue(
validators.url(web_page),
msg=f"Invalid web page: {web_page}",
)
# Alpha Two Code
self.assertIn(
"alpha_two_code", university, msg="Country Alpha Two Code is missing"
)
self.assertIsInstance(
university["alpha_two_code"],
(str, type(None)),
msg="Country Alpha Two Code must be a string or null",
)
if university["alpha_two_code"] is not None:
self.assertEqual(
len(university["alpha_two_code"]),
2,
msg=f"Country Alpha Two Code must be 2 characters long: {university['alpha_two_code']}",
)
# State/Province
self.assertIn(
"state-province", university, msg="University State/Province is missing"
)
self.assertIsInstance(
university["state-province"],
(str, type(None)),
msg="University State/Province must be a string or null",
)
# Country
self.assertIn("country", university, msg="University Country is missing")
self.assertIsInstance(
university["country"],
(str, type(None)),
msg="University Country must be a string or null",
)


# Run tests locally
# if __name__ == "__main__":
# unittest.main()
4 changes: 2 additions & 2 deletions world_universities_and_domains.json
Original file line number Diff line number Diff line change
Expand Up @@ -118680,7 +118680,7 @@
"https://ifsp.edu.br"
],
"name": "Federal Institute of Education",
"alpha_two_code": "Science and Technology of S\u00e3o Paulo",
"alpha_two_code": "BR",
"state-province": null,
"domains": [
"aluno.ifsp.edu.br"
Expand Down Expand Up @@ -118968,7 +118968,7 @@
"https://csueastbay.edu"
],
"name": "California State University",
"alpha_two_code": "East Bay",
"alpha_two_code": "US",
"state-province": null,
"domains": [
"csueastbay.edu"
Expand Down

0 comments on commit 05ae50b

Please sign in to comment.