diff --git a/src/event.py b/src/event.py index 140d743..b66a7b0 100644 --- a/src/event.py +++ b/src/event.py @@ -25,8 +25,11 @@ def parse_location(event_json): f"{event_json['venue']['state']} {event_json['venue']['zip']}" ) - if event_json["venue"]["lat"] is not None and event_json["venue"]["lat"]: - return f"lat/long: {event_json['venue']['lat']}, {event_json['venue']['lat']}" + if ( + event_json["venue"]["lat"] is not None + and event_json["venue"]["lon"] is not None + ): + return f"lat/long: {event_json['venue']['lat']}, {event_json['venue']['lon']}" return f"{event_json['venue']['name']}" diff --git a/tests/conftest.py b/tests/conftest.py index 3151153..70acf63 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -101,3 +101,36 @@ def mock_slack_bolt_async_app(request, monkeypatch): Monkeypatch slack_bolt.async_app's AsyncApp with our stub """ monkeypatch.setattr(f"{request.param}.SLACK_APP", mocks.AsyncApp()) + + +@pytest.fixture +def sample_event_date(): + """Return fully-populated event dictionary""" + return { + "event_name": "Tankin' Around Greenville", + "group_name": "Greenville Tank Enthusiasts", + "group_url": "https://www.tankinaroundgreenville.com", + "venue": { + "name": "Gower Estates Park", + "address": "24 Evelyn Ave,", + "city": "Greenville", + "state": "SC", + "zip": "29607", + "country": "US", + "lat": "34.8300191", + "lon": "-82.3510954", + }, + "url": "https://www.eventbrite.com/e/tanks-are-cool-123456789101", + "time": "2023-12-12T22:30:00Z", + "tags": "", + "rsvp_count": None, + "created_at": "2023-11-15T18:50:35Z", + "description": "Join us for a special event as we take a group trip to local parks to admire " + + "and appreciate the decommissioned military tanks that are on display.", + "uuid": "e70fb83b-df54-4333-9f02-1746ec1d62ee", + "nid": "1", + "data_as_of": "2023-12-07T16:40:14Z", + "status": "upcoming", + "service_id": "123456789101", + "service": "eventbrite", + }.copy() diff --git a/tests/test_event.py b/tests/test_event.py new file mode 100644 index 0000000..4101dbb --- /dev/null +++ b/tests/test_event.py @@ -0,0 +1,43 @@ +""" +Tests the parsing of events data +""" + +import event + + +def test_parsing_location_of_event_with_full_details(sample_event_date): + """Happy path scenario where all event fields are populated""" + result = event.parse_location(sample_event_date) + + assert result == "Gower Estates Park at 24 Evelyn Ave, Greenville, SC 29607" + + +def test_parsing_location_of_event_with_missing_venue(sample_event_date): + """Tests that the location is returned as None if a venue isn't provided""" + event_data_without_venue = sample_event_date + event_data_without_venue["venue"] = None + + result = event.parse_location(event_data_without_venue) + + assert result is None + + +def test_parsing_location_of_event_missing_state(sample_event_date): + """Ensure coordinates are returned if the state is missing from venue info""" + event_data_without_state = sample_event_date + event_data_without_state["venue"]["state"] = None + + result = event.parse_location(event_data_without_state) + + assert result == "lat/long: 34.8300191, -82.3510954" + + +def test_parsing_location_of_event_missing_state_and_latitude(sample_event_date): + """Ensure venue name is returned if state and latitude are missing from venue info""" + event_data_without_state_and_lat = sample_event_date + event_data_without_state_and_lat["venue"]["state"] = None + event_data_without_state_and_lat["venue"]["lat"] = None + + result = event.parse_location(event_data_without_state_and_lat) + + assert result == "Gower Estates Park"