-
Notifications
You must be signed in to change notification settings - Fork 21
/
test_NetflixTvShows.py
221 lines (177 loc) · 7.89 KB
/
test_NetflixTvShows.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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
import unittest
from datetime import datetime
from NetflixTvShow import NetflixTvHistory, NetflixTvShow
def test_addSingleTvShow():
"""Test to add a single episode and check if all information is correctly parsed"""
netflixHistory = NetflixTvHistory()
ret = netflixHistory.addEntry(
"Peaky Blinders – Gangs of Birmingham: Staffel 1: Geschenk des Teufels",
"03.10.21",
)
assert ret is not False
assert netflixHistory.hasTvShow("Peaky Blinders – Gangs of Birmingham")
assert netflixHistory.shows[0].name == "Peaky Blinders – Gangs of Birmingham"
assert int(netflixHistory.shows[0].seasons[0].number) == 1
assert netflixHistory.shows[0].seasons[0].name is None
assert (
netflixHistory.shows[0].seasons[0].episodes[0].watchedAt[0]
== "2021-10-03T20:15:00.00Z"
)
def test_addMultipleTvShows():
"""Test to add 3 episodes of 2 different shows and check that both shows and number of episodes are correct"""
netflixHistory = NetflixTvHistory()
ret1 = netflixHistory.addEntry(
"Peaky Blinders – Gangs of Birmingham: Staffel 1: Geschenk des Teufels",
"03.10.21",
)
ret2 = netflixHistory.addEntry("Haus des Geldes: Teil 5: Wunschdenken", "03.12.21")
ret3 = netflixHistory.addEntry(
"Haus des Geldes: Teil 5: Sicherheitsventil", "03.12.21"
)
assert ret1 is ret2 is ret3 is True
assert netflixHistory.hasTvShow("Peaky Blinders – Gangs of Birmingham") is True
assert netflixHistory.hasTvShow("Haus des Geldes")
assert (
len(netflixHistory.getTvShow("Haus des Geldes").getSeasonByNumber(5).episodes)
== 2
)
def test_addMovie():
"""Test to add a movie and check if it was recoginzied as a movie"""
netflixHistory = NetflixTvHistory()
netflixHistory.addEntry("Spider-Man: Far from Home", "16.09.21")
assert netflixHistory.getMovie("Spider-Man: Far from Home") is not None
assert netflixHistory.movies[0].watchedAt[0] == "2021-09-16T20:15:00.00Z"
class TestNetflixTvHistory(unittest.TestCase):
def setUp(self):
self.history = NetflixTvHistory()
def test_getTvShow(self):
self.assertIsNone(self.history.getTvShow("Stranger Things"))
showName = "Breaking Bad"
show = NetflixTvShow(showName)
self.history.shows.append(show)
self.assertEqual(self.history.getTvShow(showName), show)
self.assertIsNone(self.history.getTvShow("The Office"))
def test_addEntry_tvshow_regex1(self):
entryTitle = "Breaking Bad: Season 3: Fly"
entryDate = datetime.now()
self.history.addEntry(entryTitle, entryDate.strftime("%d.%m.%y"))
show = self.history.getTvShow("Breaking Bad")
self.assertIsNotNone(show)
season = show.getSeasonByNumber(3)
self.assertIsNotNone(season)
episode = season.getEpisodeByName("Fly")
self.assertIsNotNone(episode)
self.assertIn(
entryDate.replace(hour=20, minute=15, second=0).strftime(
"%Y-%m-%dT%H:%M:%S.00Z"
),
episode.watchedAt,
)
def test_addEntry_tvshow_regex2(self):
entryTitle = (
"Die außergewoehnlichsten Haeuser der Welt: Staffel 2 – Teil B: Spanien"
)
entryDate = datetime.now()
self.history.addEntry(entryTitle, entryDate.strftime("%d.%m.%y"))
show = self.history.getTvShow("Die außergewoehnlichsten Haeuser der Welt")
self.assertIsNotNone(show)
season = show.getSeasonByNumber(2)
self.assertIsNotNone(season)
episode = season.getEpisodeByName("Spanien")
self.assertIsNotNone(episode)
self.assertIn(
entryDate.replace(hour=20, minute=15, second=0).strftime(
"%Y-%m-%dT%H:%M:%S.00Z"
),
episode.watchedAt,
)
def test_addEntry_tvshow_regex3(self):
entryTitle = "The Falcon and The Winter Soldier: Miniseries: Episode 6"
entryDate = datetime.now()
self.history.addEntry(entryTitle, entryDate.strftime("%d.%m.%y"))
show = self.history.getTvShow("The Falcon and The Winter Soldier")
self.assertIsNotNone(show)
season = show.getSeasonByNumber(1)
self.assertIsNotNone(season)
episode = season.getEpisodeByName("Episode 6")
self.assertIsNotNone(episode)
self.assertIn(
entryDate.replace(hour=20, minute=15, second=0).strftime(
"%Y-%m-%dT%H:%M:%S.00Z"
),
episode.watchedAt,
)
def test_addEntry_tvshow_regex4(self):
entryTitle = "American Horror Story: Murder House: Nachgeburt"
entryDate = datetime.now()
self.history.addEntry(entryTitle, entryDate.strftime("%d.%m.%y"))
show = self.history.getTvShow("American Horror Story")
self.assertIsNotNone(show)
season = show.getSeasonByName("Murder House")
self.assertIsNotNone(season)
episode = season.getEpisodeByName("Nachgeburt")
self.assertIsNotNone(episode)
self.assertIn(
entryDate.replace(hour=20, minute=15, second=0).strftime(
"%Y-%m-%dT%H:%M:%S.00Z"
),
episode.watchedAt,
)
def test_addEntry_tvshow_regex5(self):
entryTitle = "King Arthur: Legend of the Sword"
entryDate = datetime.now()
self.history.addEntry(entryTitle, entryDate.strftime("%d.%m.%y"))
movie = self.history.getMovie("King Arthur: Legend of the Sword")
self.assertIsNotNone(movie)
self.assertIn(
entryDate.replace(hour=20, minute=15, second=0).strftime(
"%Y-%m-%dT%H:%M:%S.00Z"
),
movie.watchedAt,
)
def test_addEntry_tvshow_regex6(self):
entryTitle = "The Mandalorian: Chapter 9"
entryDate = datetime.now()
self.history.addEntry(entryTitle, entryDate.strftime("%d.%m.%y"))
show = self.history.getTvShow("The Mandalorian")
self.assertIsNotNone(show)
season = show.getSeasonByNumber(1)
self.assertIsNotNone(season)
episode = season.getEpisodeByName("Chapter 9")
self.assertIsNotNone(episode)
self.assertIn(
entryDate.replace(hour=20, minute=15, second=0).strftime(
"%Y-%m-%dT%H:%M:%S.00Z"
),
episode.watchedAt,
)
def test_addEntry_tvshow_regex_invalid(self):
entryTitle = "Invalid show format"
entryDate = datetime.now()
self.history.addEntry(entryTitle, entryDate.strftime("%d.%m.%y"))
# nothing should have been added
self.assertEqual(len(self.history.shows), 0)
self.assertEqual(len(self.history.movies), 1) # a movie can have any name
class TestNetflixTvShow(unittest.TestCase):
def setUp(self):
self.show = NetflixTvShow("Stranger Things")
def test_addSeason(self):
season1 = self.show.addSeason(1, "The Vanishing of Will Byers")
season2 = self.show.addSeason(2, "The Mind Flayer")
self.assertEqual(len(self.show.seasons), 2)
self.assertIn(season1, self.show.seasons)
self.assertIn(season2, self.show.seasons)
def test_getSeasonByNumber(self):
season1 = self.show.addSeason(1, "The Vanishing of Will Byers")
season2 = self.show.addSeason(2, "The Mind Flayer")
self.assertEqual(self.show.getSeasonByNumber(1), season1)
self.assertEqual(self.show.getSeasonByNumber(2), season2)
self.assertIsNone(self.show.getSeasonByNumber(3))
def test_getSeasonByName(self):
season1 = self.show.addSeason(1, "The Vanishing of Will Byers")
season2 = self.show.addSeason(2, "The Mind Flayer")
self.assertEqual(
self.show.getSeasonByName("The Vanishing of Will Byers"), season1
)
self.assertEqual(self.show.getSeasonByName("The Mind Flayer"), season2)
self.assertIsNone(self.show.getSeasonByName("The Upside Down"))