Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create test_filter.py #510

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
118 changes: 118 additions & 0 deletions tests/test_filter.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
import unittest
from university-domains-list import filter


class CountryFilterTests(unittest.TestCase):
def setUp(self):
# Sample source data
self.source_data = [
{
"name": "Kharkiv National University",
"domains": ["student.karazin.ua", "karazin.ua"],
"web_pages": ["https://karazin.ua"],
"country": "Ukraine",
"alpha_two_code": "UA",
"state-province": None
},
{
"name": "Universidad Técnica Federico Santa María",
"domains": ["usm.cl"],
"web_pages": ["https://usm.cl"],
"country": "Chile",
"alpha_two_code": "CL",
"state-province": None
},
{
"name": "IÉSEG School of Management",
"domains": ["ieseg.fr"],
"web_pages": ["https://ieseg.fr"],
"country": "France",
"alpha_two_code": "FR",
"state-province": None
},
{
"name": "Sun Yat-Sen University",
"domains": ["mail2.sysu.edu.cn", "mail.sysu.edu.cn"],
"web_pages": ["https://sysu.edu.cn"],
"country": "China",
"alpha_two_code": "CN",
"state-province": None
}
]

def test_single_country_scope(self):
filtered_output = country_filter(self.source_data, "China")
expected_output = [
{
"name": "Sun Yat-Sen University",
"domains": ["mail2.sysu.edu.cn", "mail.sysu.edu.cn"],
"web_pages": ["https://sysu.edu.cn"],
"country": "China",
"alpha_two_code": "CN",
"state-province": None
}
]
self.assertEqual(filtered_output, expected_output)

def test_multiple_country_scopes(self):
filtered_output = country_filter(self.source_data, ["China", "France"])
expected_output = [
{
"name": "IÉSEG School of Management",
"domains": ["ieseg.fr"],
"web_pages": ["https://ieseg.fr"],
"country": "France",
"alpha_two_code": "FR",
"state-province": None
},
{
"name": "Sun Yat-Sen University",
"domains": ["mail2.sysu.edu.cn", "mail.sysu.edu.cn"],
"web_pages": ["https://sysu.edu.cn"],
"country": "China",
"alpha_two_code": "CN",
"state-province": None
}
]
self.assertEqual(filtered_output, expected_output)

def test_non_existent_country_scope(self):
filtered_output = country_filter(self.source_data, "Germany")
expected_output = []
self.assertEqual(filtered_output, expected_output)

def test_case_sensitivity(self):
filtered_output = country_filter(self.source_data, ["CHINA", "france"])
expected_output = [
{
"name": "IÉSEG School of Management",
"domains": ["ieseg.fr"],
"web_pages": ["https://ieseg.fr"],
"country": "France",
"alpha_two_code": "FR",
"state-province": None
},
{
"name": "Sun Yat-Sen University",
"domains": ["mail2.sysu.edu.cn", "mail.sysu.edu.cn"],
"web_pages": ["https://sysu.edu.cn"],
"country": "China",
"alpha_two_code": "CN",
"state-province": None
}
]
self.assertEqual(filtered_output, expected_output)

def test_empty_source_data(self):
filtered_output = country_filter([], "China")
expected_output = []
self.assertEqual(filtered_output, expected_output)

def test_empty_country_scopes(self):
filtered_output = country_filter(self.source_data, [])
expected_output = self.source_data
self.assertEqual(filtered_output, expected_output)


if __name__ == '__main__':
unittest.main()