-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_teemup.py
141 lines (112 loc) · 3.64 KB
/
test_teemup.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
from datetime import datetime
import json
from zoneinfo import ZoneInfo
import pytest
from teemup import parse_next_state, parse_venue, parse
@pytest.fixture
def response_content() -> str:
with open("test_fixtures/response_content.html") as f:
return f.read()
def test_parse(response_content: str):
event = parse(response_content)[0]
assert event["description"].startswith("Hello Python lovers and data wizards!")
assert event["ends_at"] == datetime(
2024, 11, 7, 21, tzinfo=ZoneInfo("Europe/Prague")
)
assert event["group_name"] == "PyData Prague"
assert event["starts_at"] == datetime(
2024, 11, 7, 18, tzinfo=ZoneInfo("Europe/Prague")
)
assert event["title"] == "PyData Prague #23 - Low agent intelligence threat"
assert event["url"] == "https://www.meetup.com/pydata-prague/events/304008256/"
assert event["venue"] == {
"name": "Rapid 7 (Scott.Weber Workspace - Praga Studios)",
"address": "Pernerova 702/39",
"city": "Hlavní město Praha",
"state": None,
"country": "cz",
}
def test_parse_produces_timezone_aware_starts_at(response_content: str):
events = parse(response_content)
assert all([event["starts_at"].tzinfo for event in events])
def test_parse_produces_timezone_aware_ends_at(response_content: str):
events = parse(response_content)
assert all([event["ends_at"].tzinfo for event in events])
def test_parse_produces_expected_keys(response_content: str):
events = parse(response_content)
assert sorted(events[0].keys()) == [
"description",
"ends_at",
"group_name",
"starts_at",
"title",
"url",
"venue",
]
def test_parse_produces_expected_venue_keys(response_content: str):
events = parse(response_content)
venue = events[0]["venue"]
assert venue is not None
assert sorted(venue.keys()) == [
"address",
"city",
"country",
"name",
"state",
]
def test_parse_next_state_can_deal_with_missing_venue():
with open("test_fixtures/next_state_missing_venue.json") as f:
next_state = json.load(f)
events = parse_next_state(next_state)
event_with_missing_venue = [event for event in events if event["venue"] is None][0]
assert sorted(event_with_missing_venue.keys()) == [
"description",
"ends_at",
"group_name",
"starts_at",
"title",
"url",
"venue",
]
def test_parse_next_state_can_deal_with_online_venue():
with open("test_fixtures/next_state_online_venue.json") as f:
next_state = json.load(f)
events = parse_next_state(next_state)
event_with_online_venue = [event for event in events if event["venue"] is None][0]
assert sorted(event_with_online_venue.keys()) == [
"description",
"ends_at",
"group_name",
"starts_at",
"title",
"url",
"venue",
]
def test_parse_venue():
venue = {
"__typename": "Venue",
"id": "27152599",
"name": "Pipedrive",
"address": "Pernerova 697/35, Karlín",
"city": "Praha-Praha 8",
"state": "",
"country": "cz",
}
assert parse_venue(venue) == {
"name": "Pipedrive",
"address": "Pernerova 697/35, Karlín",
"city": "Praha-Praha 8",
"state": None,
"country": "cz",
}
def test_parse_online_venue():
venue = {
"__typename": "Venue",
"id": "26906060",
"name": "Online event",
"address": "",
"city": "",
"state": "",
"country": "",
}
assert parse_venue(venue) is None