From ec426b38e1af4c75f433ce2849193490c409199f Mon Sep 17 00:00:00 2001 From: aviiciii Date: Mon, 10 Jul 2023 19:45:48 +0530 Subject: [PATCH 01/11] fixing webpages --- world_universities_and_domains.json | 56 ++++++++++++++--------------- 1 file changed, 28 insertions(+), 28 deletions(-) diff --git a/world_universities_and_domains.json b/world_universities_and_domains.json index bb175abd..fefe4317 100644 --- a/world_universities_and_domains.json +++ b/world_universities_and_domains.json @@ -30156,16 +30156,16 @@ "country": "China" }, { - "web_pages": [ - "https://shcc.edu.cn/" - ], - "name": "Shanghai Customs College", - "alpha_two_code": "CN", - "state-province": null, - "domains": [ - "shcc.edu.cn" - ], - "country": "China" + "web_pages": [ + "https://shcc.edu.cn/" + ], + "name": "Shanghai Customs College", + "alpha_two_code": "CN", + "state-province": null, + "domains": [ + "shcc.edu.cn" + ], + "country": "China" }, { "web_pages": [ @@ -47901,7 +47901,7 @@ }, { "web_pages": [ - "www.iiit-bh.ac.in/" + "https://www.iiit-bh.ac.in/" ], "name": "International Institute of Information Technology, Bhubaneswar", "alpha_two_code": "IN", @@ -47913,7 +47913,7 @@ }, { "web_pages": [ - "www.iiitb.ac.in/" + "https://www.iiitb.ac.in/" ], "name": "International Institute of Information Technology, Bangalore", "alpha_two_code": "IN", @@ -116681,7 +116681,7 @@ }, { "web_pages": [ - "www.hbc.edu.cn" + "https://www.hbc.edu.cn" ], "name": "Hubei Business College", "alpha_two_code": "CN", @@ -116693,7 +116693,7 @@ }, { "web_pages": [ - "www.fom.de" + "https://www.fom.de" ], "name": "FOM Hochschule für Oekonomie & Management", "alpha_two_code": "DE", @@ -116705,7 +116705,7 @@ }, { "web_pages": [ - "www.thm.de" + "https://www.thm.de" ], "name": "Technische Hochschule Mittelhessen", "alpha_two_code": "DE", @@ -116717,7 +116717,7 @@ }, { "web_pages": [ - "www.hwg-lu.de" + "https://www.hwg-lu.de" ], "name": "Hochschule für Wirtschaft und Gesellschaft Ludwigshafen", "alpha_two_code": "DE", @@ -116741,7 +116741,7 @@ }, { "web_pages": [ - "www.leuphana.de" + "https://www.leuphana.de" ], "name": "Leuphana Universität Lüneburg", "alpha_two_code": "DE", @@ -118568,7 +118568,7 @@ }, { "web_pages": [ - "gsfcuni.edu.in" + "https://gsfcuni.edu.in" ], "name": "GSFC University", "alpha_two_code": "IN", @@ -118580,7 +118580,7 @@ }, { "web_pages": [ - "nwu.ac.za" + "https://nwu.ac.za" ], "name": "North-West Univeristy", "alpha_two_code": "ZA", @@ -118592,7 +118592,7 @@ }, { "web_pages": [ - "tudublin.ie" + "https://tudublin.ie" ], "name": "Technological University Dublin", "alpha_two_code": "IE", @@ -118604,7 +118604,7 @@ }, { "web_pages": [ - "www.keio.ac.jp" + "https://www.keio.ac.jp" ], "name": "Keio University", "alpha_two_code": "JP", @@ -118616,7 +118616,7 @@ }, { "web_pages": [ - "tamut.edu" + "https://tamut.edu" ], "name": "Texas A&M University-Texarkana", "alpha_two_code": "US", @@ -118628,7 +118628,7 @@ }, { "web_pages": [ - "ais.com.sg" + "https://ais.com.sg" ], "name": "Australian International School", "alpha_two_code": "SG", @@ -118640,7 +118640,7 @@ }, { "web_pages": [ - "akfaryarsiptk.ac.id" + "https://akfaryarsiptk.ac.id" ], "name": "Akademi Farmasi Yarsis Pekanbaru", "alpha_two_code": "ID", @@ -118652,7 +118652,7 @@ }, { "web_pages": [ - "alayen.edu.iq" + "https://alayen.edu.iq" ], "name": "Alayen University", "alpha_two_code": "IQ", @@ -118664,7 +118664,7 @@ }, { "web_pages": [ - "web.ub.edu" + "https://web.ub.edu" ], "name": "University of Barcelona", "alpha_two_code": "ES", @@ -118676,7 +118676,7 @@ }, { "web_pages": [ - "cruzeirodosul.edu.br" + "https://cruzeirodosul.edu.br" ], "name": "Cruzeiro do Sul University", "alpha_two_code": "BR", @@ -118688,7 +118688,7 @@ }, { "web_pages": [ - "ifsp.edu.br" + "https://ifsp.edu.br" ], "name": "Federal Institute of Education", "alpha_two_code": "Science and Technology of S\u00e3o Paulo", From ab571df997c0e4700f43c8280256dd8928cd1cdb Mon Sep 17 00:00:00 2001 From: aviiciii Date: Mon, 10 Jul 2023 20:02:54 +0530 Subject: [PATCH 02/11] fixed webpages --- world_universities_and_domains.json | 32 +++++++++-------------------- 1 file changed, 10 insertions(+), 22 deletions(-) diff --git a/world_universities_and_domains.json b/world_universities_and_domains.json index fefe4317..de6deea2 100644 --- a/world_universities_and_domains.json +++ b/world_universities_and_domains.json @@ -30156,16 +30156,16 @@ "country": "China" }, { - "web_pages": [ - "https://shcc.edu.cn/" - ], - "name": "Shanghai Customs College", - "alpha_two_code": "CN", - "state-province": null, - "domains": [ - "shcc.edu.cn" - ], - "country": "China" + "web_pages": [ + "https://shcc.edu.cn/" + ], + "name": "Shanghai Customs College", + "alpha_two_code": "CN", + "state-province": null, + "domains": [ + "shcc.edu.cn" + ], + "country": "China" }, { "web_pages": [ @@ -116691,18 +116691,6 @@ ], "country": "China" }, - { - "web_pages": [ - "https://www.fom.de" - ], - "name": "FOM Hochschule für Oekonomie & Management", - "alpha_two_code": "DE", - "state-province": null, - "domains": [ - "fom-net.de" - ], - "country": "Germany" - }, { "web_pages": [ "https://www.thm.de" From 11e7ad232ccb53b229c2ee8bc2d41232c61ac880 Mon Sep 17 00:00:00 2001 From: aviiciii Date: Mon, 10 Jul 2023 20:16:48 +0530 Subject: [PATCH 03/11] added webpage url validation --- tests/test_domains.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/tests/test_domains.py b/tests/test_domains.py index 54b2ae5e..4f55978d 100644 --- a/tests/test_domains.py +++ b/tests/test_domains.py @@ -15,6 +15,12 @@ def test_json_is_valid(self): for domain in university["domains"]: self.assertTrue(validators.domain(domain)) self.assertIn("web_pages", university) + self.assertIsInstance(university["web_pages"], list) + for web_page in university["web_pages"]: + self.assertTrue(validators.url(web_page)) self.assertIn("alpha_two_code", university) self.assertIn("state-province", university) self.assertIn("country", university) + +if __name__ == "__main__": + unittest.main() \ No newline at end of file From 4c288fcf2fbad65df81d522c3ebf52d80cc4503f Mon Sep 17 00:00:00 2001 From: aviiciii Date: Mon, 10 Jul 2023 20:28:53 +0530 Subject: [PATCH 04/11] add validation error message --- tests/test_domains.py | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/tests/test_domains.py b/tests/test_domains.py index 4f55978d..4a4da68d 100644 --- a/tests/test_domains.py +++ b/tests/test_domains.py @@ -9,18 +9,20 @@ def test_json_is_valid(self): 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) + self.assertIn("name", university, msg="University Name is missing") + self.assertIn("domains", university, msg="University Domains are missing") + self.assertIsInstance(university["domains"], list, msg="University Domains must be a list") for domain in university["domains"]: - self.assertTrue(validators.domain(domain)) - self.assertIn("web_pages", university) - self.assertIsInstance(university["web_pages"], list) + self.assertTrue(validators.domain(domain), msg=f"Invalid domain: {domain}") + self.assertIn("web_pages", university, msg="University Web Pages are missing") + self.assertIsInstance(university["web_pages"], list, msg="University Web Pages must be a list") for web_page in university["web_pages"]: - self.assertTrue(validators.url(web_page)) - self.assertIn("alpha_two_code", university) - self.assertIn("state-province", university) - self.assertIn("country", university) + self.assertTrue(validators.url(web_page), msg=f"Invalid web page: {web_page}") + self.assertIn("alpha_two_code", university, msg="University Alpha Two Code is missing") + self.assertIn("state-province", university, msg="University State/Province is missing") + self.assertIn("country", university, msg="University Country is missing") + +# Run tests locally if __name__ == "__main__": unittest.main() \ No newline at end of file From bb44d71bb00a6671ace03370844e655dca16184c Mon Sep 17 00:00:00 2001 From: aviiciii Date: Mon, 10 Jul 2023 21:03:25 +0530 Subject: [PATCH 05/11] added testing of datatype for all fields --- tests/test_domains.py | 39 +++++++++++++++++++++++++++------------ 1 file changed, 27 insertions(+), 12 deletions(-) diff --git a/tests/test_domains.py b/tests/test_domains.py index 4a4da68d..ef577662 100644 --- a/tests/test_domains.py +++ b/tests/test_domains.py @@ -1,27 +1,42 @@ import json import unittest - import validators - class DomainsTests(unittest.TestCase): - def test_json_is_valid(self): + def setUp(self): 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.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: 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") + self.assertIn("domains", university, msg="University Domains are missing") - self.assertIsInstance(university["domains"], list, msg="University Domains must be a list") - for domain in university["domains"]: - self.assertTrue(validators.domain(domain), msg=f"Invalid domain: {domain}") + 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}") + self.assertIn("web_pages", university, msg="University Web Pages are missing") - self.assertIsInstance(university["web_pages"], list, msg="University Web Pages must be a list") - for web_page in university["web_pages"]: - self.assertTrue(validators.url(web_page), msg=f"Invalid web page: {web_page}") + 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}") + self.assertIn("alpha_two_code", university, msg="University Alpha Two Code is missing") + self.assertIsInstance(university["alpha_two_code"], (str, type(None)), msg="University Alpha Two Code must be a string or null") + self.assertIn("state-province", university, msg="University State/Province is missing") - self.assertIn("country", university, msg="University Country is missing") + self.assertIsInstance(university["state-province"], (str, type(None)), msg="University State/Province must be a string or null") + 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__": From 8dcfb74cacb04b8ca9a7691147525867f4089c8b Mon Sep 17 00:00:00 2001 From: aviiciii Date: Mon, 10 Jul 2023 21:25:09 +0530 Subject: [PATCH 06/11] check if length of alpha two code is 2 --- tests/test_domains.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/tests/test_domains.py b/tests/test_domains.py index ef577662..9522c76c 100644 --- a/tests/test_domains.py +++ b/tests/test_domains.py @@ -4,6 +4,7 @@ class DomainsTests(unittest.TestCase): def setUp(self): + """Load the JSON file into a variable""" with open("world_universities_and_domains.json", encoding="utf-8") as json_file: self.valid_json = json.load(json_file) @@ -29,8 +30,11 @@ def test_university_json_structure(self): if web_page is not None: self.assertTrue(validators.url(web_page), msg=f"Invalid web page: {web_page}") - self.assertIn("alpha_two_code", university, msg="University Alpha Two Code is missing") - self.assertIsInstance(university["alpha_two_code"], (str, type(None)), msg="University Alpha Two Code must be a string or null") + 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") + # check if length is 2 + if university["alpha_two_code"] is not None: + self.assertEqual(len(university["alpha_two_code"]), 2, msg="Country Alpha Two Code must be 2 characters long") 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") From c8bd29cf2f4f3b52d87c65375e072346fa02e678 Mon Sep 17 00:00:00 2001 From: aviiciii Date: Mon, 10 Jul 2023 21:28:53 +0530 Subject: [PATCH 07/11] fixed country codes --- world_universities_and_domains.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/world_universities_and_domains.json b/world_universities_and_domains.json index de6deea2..5cb12807 100644 --- a/world_universities_and_domains.json +++ b/world_universities_and_domains.json @@ -118679,7 +118679,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" @@ -118967,7 +118967,7 @@ "https://csueastbay.edu" ], "name": "California State University", - "alpha_two_code": "East Bay", + "alpha_two_code": "US", "state-province": null, "domains": [ "csueastbay.edu" From 892013d99f4c39cf5d441dd2906379393aef7918 Mon Sep 17 00:00:00 2001 From: aviiciii Date: Mon, 10 Jul 2023 21:29:16 +0530 Subject: [PATCH 08/11] edited msg --- tests/test_domains.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_domains.py b/tests/test_domains.py index 9522c76c..369346a3 100644 --- a/tests/test_domains.py +++ b/tests/test_domains.py @@ -34,7 +34,7 @@ def test_university_json_structure(self): self.assertIsInstance(university["alpha_two_code"], (str, type(None)), msg="Country Alpha Two Code must be a string or null") # check if length is 2 if university["alpha_two_code"] is not None: - self.assertEqual(len(university["alpha_two_code"]), 2, msg="Country Alpha Two Code must be 2 characters long") + self.assertEqual(len(university["alpha_two_code"]), 2, msg=f"Country Alpha Two Code must be 2 characters long: {university['alpha_two_code']}") 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") From 7215894b2615eb734431a739eb0a1fcc2946750f Mon Sep 17 00:00:00 2001 From: aviiciii Date: Mon, 10 Jul 2023 21:35:58 +0530 Subject: [PATCH 09/11] Added comments --- tests/test_domains.py | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/tests/test_domains.py b/tests/test_domains.py index 369346a3..3ad3e657 100644 --- a/tests/test_domains.py +++ b/tests/test_domains.py @@ -11,9 +11,10 @@ def setUp(self): 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: @@ -21,7 +22,7 @@ def test_university_json_structure(self): 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: @@ -29,19 +30,18 @@ def test_university_json_structure(self): 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") - # check if length is 2 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() \ No newline at end of file +# if __name__ == "__main__": +# unittest.main() \ No newline at end of file From f0da229473c12165f9e98d240c602401cbd8edfd Mon Sep 17 00:00:00 2001 From: aviiciii Date: Mon, 10 Jul 2023 22:03:52 +0530 Subject: [PATCH 10/11] bump travis to python 3.11 --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 398a0a80..a003a378 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,6 +1,6 @@ language: python python: - - '3.6' + - '3.11' script: - cd tests - pip install -r requirements.txt From 2384c831394a725804a466f58ed96ef1bffcedcc Mon Sep 17 00:00:00 2001 From: aviiciii Date: Tue, 11 Jul 2023 00:19:24 +0530 Subject: [PATCH 11/11] formatted using black --- tests/test_domains.py | 80 +++++++++++++++++++++++++++++++++++-------- 1 file changed, 65 insertions(+), 15 deletions(-) diff --git a/tests/test_domains.py b/tests/test_domains.py index 3ad3e657..732dedef 100644 --- a/tests/test_domains.py +++ b/tests/test_domains.py @@ -1,7 +1,9 @@ import json import unittest + import validators + class DomainsTests(unittest.TestCase): def setUp(self): """Load the JSON file into a variable""" @@ -13,35 +15,83 @@ def test_university_json_structure(self): 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") + 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") + 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") + 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}") + 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") + 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") + 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}") + 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") + 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']}") + 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") + 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") + self.assertIsInstance( + university["country"], + (str, type(None)), + msg="University Country must be a string or null", + ) + # Run tests locally # if __name__ == "__main__": -# unittest.main() \ No newline at end of file +# unittest.main()