Skip to content

Commit

Permalink
test: Add unit tests for new parse_known_venues() function and update…
Browse files Browse the repository at this point in the history
… other tests for new event object dict contents
  • Loading branch information
essteer committed Aug 18, 2024
1 parent 3125a56 commit 7361224
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 4 deletions.
26 changes: 22 additions & 4 deletions tests/test_app.py → tests/test_pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,23 +46,31 @@ 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:
self.assertIn("weekday", match)
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"""
Expand All @@ -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:
Expand All @@ -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__":
Expand Down
16 changes: 16 additions & 0 deletions tests/test_transform.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -12,6 +13,7 @@
parse_genres,
parse_band_name,
parse_all_bands_and_genres,
parse_known_venues
)


Expand Down Expand Up @@ -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()

0 comments on commit 7361224

Please sign in to comment.