Skip to content

Commit 8d7a9ba

Browse files
authored
FIX CI for test_stats_view.py (#1374)
1 parent d01acee commit 8d7a9ba

File tree

1 file changed

+27
-23
lines changed

1 file changed

+27
-23
lines changed

pod/video/tests/test_stats_view.py

Lines changed: 27 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
"""Esup-Pod Stats view test cases.
2+
3+
* run with 'python manage.py test pod.video.tests.test_stats_view'
4+
"""
15
from unittest import skipUnless
26
from django.http import JsonResponse
37
from datetime import date
@@ -132,10 +136,10 @@ def setUp(self) -> None:
132136
USE_STATS_VIEW = True
133137
except NoReverseMatch:
134138
USE_STATS_VIEW = False
135-
print("Statistics URL defined =======>: " + USE_STATS_VIEW)
139+
print("Statistics URL defined =======>: %s" % USE_STATS_VIEW)
136140

137141
@skipUnless(USE_STATS_VIEW, "Require URL video_stats_view")
138-
def test_stats_view_GET_request_video(self):
142+
def test_stats_view_GET_request_video(self) -> None:
139143
response = self.client.get(self.stat_video_url)
140144
# Check that the view function is stats_view
141145
self.assertEqual(response.resolver_match.func, stats_view)
@@ -166,19 +170,17 @@ def test_stats_view_GET_request_video(self):
166170
"""
167171

168172
@skipUnless(USE_STATS_VIEW, "Require activate URL video_stats_view")
169-
def test_stats_view_GET_request_videos(self):
173+
def test_stats_view_GET_request_videos(self) -> None:
170174
stat_url_videos = reverse("video:video_stats_view")
171175
response = self.client.get(stat_url_videos, {"from": "videos"})
172176
self.assertContains(response, b"Pod video viewing statistics", status_code=200)
173177

174-
@skipUnless(USE_STATS_VIEW, "Require acitvate URL video_stats_view")
175-
def test_stats_view_GET_request_channel(self):
176-
# print("ABCDE " + self.stat_channel_url)
178+
@skipUnless(USE_STATS_VIEW, "Require activate URL video_stats_view")
179+
def test_stats_view_GET_request_channel(self) -> None:
177180
response = self.client.get(self.stat_channel_url)
178181
# Check that the view function is stats_view
179182
self.assertEqual(response.resolver_match.func, stats_view)
180-
# Check that the response is 200 OK.
181-
# Check that the response contains the expected title
183+
# Check that the response is 200 OK and contains the expected title
182184
self.assertContains(
183185
response,
184186
(
@@ -187,18 +189,18 @@ def test_stats_view_GET_request_channel(self):
187189
),
188190
status_code=200,
189191
)
190-
# Check that the response is 404 Not Found.
191-
# Check that the response contains the error message
192+
slug = "0001_channeldoesnotexist"
193+
# Check that the response is 404 Not Found and contains the error message
192194
stat_channel_url = (
193-
reverse("video:video_stats_view", kwargs={"slug": "0001_channeldoesnotexist"})
195+
reverse("video:video_stats_view", kwargs={"slug": slug})
194196
+ "?from=channel"
195197
)
196198
response = self.client.get(stat_channel_url)
197-
msg = b"The following channel does not exist or contain any videos: %b"
198-
self.assertContains(response, msg % b"0001_channeldoesnotexist", status_code=404)
199+
msg = "The following channel” type target does not exist or contains no videos: %s" % slug
200+
self.assertContains(response, msg, status_code=404)
199201

200202
@skipUnless(USE_STATS_VIEW, "Require URL video_stats_view")
201-
def test_stats_view_GET_request_theme(self):
203+
def test_stats_view_GET_request_theme(self) -> None:
202204
response = self.client.get(self.stat_theme_url)
203205
# Check that the view function is stats_view
204206
self.assertEqual(response.resolver_match.func, stats_view)
@@ -212,24 +214,26 @@ def test_stats_view_GET_request_theme(self):
212214
),
213215
status_code=200,
214216
)
217+
218+
slug_t = "0001_themedoesnotexist"
215219
# Check that the response is 404 Not Found.
216220
# Check that the response contains the error message
217221
stat_theme_url = (
218222
reverse(
219223
"video:video_stats_view",
220224
kwargs={
221225
"slug": "0001_channeldoesnotexist",
222-
"slug_t": "0001_themedoesnotexist",
226+
"slug_t": slug_t,
223227
},
224228
)
225229
+ "?from=theme"
226230
)
227231
response = self.client.get(stat_theme_url)
228-
msg = b"The following theme does not exist or contain any videos: %b"
229-
self.assertContains(response, msg % b"0001_themedoesnotexist", status_code=404)
232+
msg = "The following theme” type target does not exist or contains no videos: %s" % slug_t
233+
self.assertContains(response, msg, status_code=404)
230234

231235
@skipUnless(USE_STATS_VIEW, "Require activate URL video_stats_view")
232-
def test_stats_view_POST_request_video(self):
236+
def test_stats_view_POST_request_video(self) -> None:
233237
data = [
234238
{
235239
"title": self.video.title,
@@ -248,7 +252,7 @@ def test_stats_view_POST_request_video(self):
248252
self.assertEqual(response.content, expected_content)
249253

250254
@skipUnless(USE_STATS_VIEW, "Require activate URL video_stats_view")
251-
def test_stats_view_POST_request_videos(self):
255+
def test_stats_view_POST_request_videos(self) -> None:
252256
stat_url_videos = reverse("video:video_stats_view")
253257
response = self.client.post(stat_url_videos)
254258
# Check that the view function is stats_view
@@ -270,7 +274,7 @@ def test_stats_view_POST_request_videos(self):
270274
)
271275

272276
@skipUnless(USE_STATS_VIEW, "Require URL video_stats_view")
273-
def test_stats_view_POST_request_channel(self):
277+
def test_stats_view_POST_request_channel(self) -> None:
274278
response = self.client.post(self.stat_channel_url)
275279
# Check that the view function is stats_view
276280
self.assertEqual(response.resolver_match.func, stats_view)
@@ -291,7 +295,7 @@ def test_stats_view_POST_request_channel(self):
291295
)
292296

293297
@skipUnless(USE_STATS_VIEW, "Require URL video_stats_view")
294-
def test_stats_view_POST_request_theme(self):
298+
def test_stats_view_POST_request_theme(self) -> None:
295299
response = self.client.post(self.stat_theme_url)
296300
# Check that the view function is stats_view
297301
self.assertEqual(response.resolver_match.func, stats_view)
@@ -312,7 +316,7 @@ def test_stats_view_POST_request_theme(self):
312316
)
313317

314318
@skipUnless(USE_STATS_VIEW, "Require URL video_stats_view")
315-
def test_stats_view_GET_request_video_access_rights(self):
319+
def test_stats_view_GET_request_video_access_rights(self) -> None:
316320
"""Test video restrictions (by password, by group, or private video)."""
317321
# *********** Test restricted by password ************ #
318322
password = "ThisVideoRequireAPassword"
@@ -415,7 +419,7 @@ def test_stats_view_GET_request_video_access_rights(self):
415419
del response
416420
del password
417421

418-
def tearDown(self):
422+
def tearDown(self) -> None:
419423
del self.video
420424
del self.video2
421425
del self.video3

0 commit comments

Comments
 (0)