diff --git a/tests/test_app.py b/tests/test_pipeline.py similarity index 81% rename from tests/test_app.py rename to tests/test_pipeline.py index a2e1cf3..8dea520 100644 --- a/tests/test_app.py +++ b/tests/test_pipeline.py @@ -46,11 +46,15 @@ def test_expected_fields_present(self): self.assertIn("month", match) self.assertIn("date", match) self.assertIn("desc", match) - self.assertIn("venue", match) self.assertIn("open", match) self.assertIn("close", match) self.assertIn("bands", match) self.assertIn("tickets", match) + if "venue" in match: + self.assertIn("address_en", match) + self.assertIn("address_cn", match) + else: + self.assertIn("address_raw", match) # NOTE: this test relies on external source, check source if not found matches = data_pipeline(TEST_URL) for match in matches: @@ -58,11 +62,15 @@ def test_expected_fields_present(self): self.assertIn("month", match) self.assertIn("date", match) self.assertIn("desc", match) - self.assertIn("venue", match) self.assertIn("open", match) self.assertIn("close", match) self.assertIn("bands", match) self.assertIn("tickets", match) + if "venue" in match: + self.assertIn("address_en", match) + self.assertIn("address_cn", match) + else: + self.assertIn("address_raw", match) def test_match_content_types_correct(self): """Test values in each match dict are of expected types""" @@ -76,11 +84,16 @@ def test_match_content_types_correct(self): self.assertIsInstance(match["month"], int) self.assertIsInstance(match["date"], int) self.assertIsInstance(match["desc"], str) - self.assertIsInstance(match["venue"], str) self.assertIsInstance(match["open"], str) self.assertIsInstance(match["close"], str) self.assertIsInstance(match["bands"], list) self.assertIsInstance(match["tickets"], dict) + if "venue" in match: + self.assertIsInstance(match["venue"], str) + self.assertIsInstance(match["address_en"], str) + self.assertIsInstance(match["address_cn"], str) + else: + self.assertIsInstance(match["address_raw"], str) # NOTE: this test relies on external source, check source if not found matches = data_pipeline(TEST_URL) for match in matches: @@ -91,11 +104,16 @@ def test_match_content_types_correct(self): self.assertIsInstance(match["month"], int) self.assertIsInstance(match["date"], int) self.assertIsInstance(match["desc"], str) - self.assertIsInstance(match["venue"], str) self.assertIsInstance(match["open"], str) self.assertIsInstance(match["close"], str) self.assertIsInstance(match["bands"], list) self.assertIsInstance(match["tickets"], dict) + if "venue" in match: + self.assertIsInstance(match["venue"], str) + self.assertIsInstance(match["address_en"], str) + self.assertIsInstance(match["address_cn"], str) + else: + self.assertIsInstance(match["address_raw"], str) if __name__ == "__main__": diff --git a/tests/test_transform.py b/tests/test_transform.py index 78d1049..7bb245e 100644 --- a/tests/test_transform.py +++ b/tests/test_transform.py @@ -3,6 +3,7 @@ import unittest sys.path.append(os.path.join(os.path.dirname(__file__))) +from src.utils.maps import ADDRESS_MAP from src.utils.transform import ( convert_days_to_digits, convert_to_24_hour_time, @@ -12,6 +13,7 @@ parse_genres, parse_band_name, parse_all_bands_and_genres, + parse_known_venues ) @@ -270,5 +272,19 @@ def test_output_values(self): ) +class TestParseKnownVenues(unittest.TestCase): + def test_no_matches(self): + """Unknown venues should return None""" + fake_venue = "qwerty" + venue = parse_known_venues(fake_venue) + self.assertIsNone(venue) + + def test_known_matches(self): + """Known venues should return string that is key in ADDRESS_MAP""" + real_venue = "Maggie Choo’s, G/F Chinachem Hollywood Centre, Central, 中環華懋荷李活中心" + venue = parse_known_venues(real_venue) + self.assertIn(venue, ADDRESS_MAP) + + if __name__ == "__main__": unittest.main()