def test_stats_view_POST_request_video(self): data = [{ "title": self.video.title, "slug": self.video.slug, **get_all_views_count(self.video.id) }, { "min_date": TODAY }] expected_content = JsonResponse(data, safe=False).content response = self.client.post(self.stat_video_url) # Check that the view function is stats_view self.assertEqual(response.resolver_match.func, stats_view) # Check that the response is 200 OK and self.assertEqual(response.status_code, 200) # the content contains the title of the video and expected data self.assertEqual(response.content, expected_content)
def test_stats_view_POST_request_theme(self): response = self.client.post(self.stat_theme_url) # Check that the view function is stats_view self.assertEqual(response.resolver_match.func, stats_view) # Check that the response is 200 OK and self.assertEqual(response.status_code, 200) videos_expected = [self.video, self.video2] for video in videos_expected: data = { "title": video.title, "slug": video.slug, **get_all_views_count(video.id), } # the content contains the expected data self.assertIn(json.dumps(data), response.content.decode("utf-8")) # the content contains the expected data self.assertContains( response, json.dumps({"min_date": TODAY.strftime("%Y-%m-%d")}))
def test_stats_view_POST_request_video(self): views = get_all_views_count(self.video.id, TODAY) data = [{ "title": self.video.title, "slug": self.video.slug, "day": views[0], "month": views[1], "year": views[2], "since_created": views[3]}] data.append({"min_date": TODAY}) expected_content = JsonResponse(data, safe=False).content response = self.client.post(self.stat_video_url) # Check that the view function is stats_view self.assertEqual(response.resolver_match.func, stats_view) # Check that the response is 200 OK and self.assertEqual(response.status_code, 200) # the content contains the title of the video and expected data self.assertEqual(response.content, expected_content)
def test_stats_view_POST_request_videos(self): stat_url_videos = reverse("video_stats_view") response = self.client.post(stat_url_videos) # Check that the view function is stats_view self.assertEqual(response.resolver_match.func, stats_view) # Check that the response is 200 OK and self.assertEqual(response.status_code, 200) videos_expected = [self.video, self.video2, self.video3] for video in videos_expected: views = get_all_views_count(video.id, TODAY) data = { "title": self.video.title, "slug": self.video.slug, "day": views[0], "month": views[1], "year": views[2], "since_created": views[3]} # the content contains the title of the video and expected data self.assertIn(json.dumps(data), response.content.decode("utf-8")) # the content contains the title of the video and expected data self.assertContains( response, json.dumps({"min_date": TODAY.strftime("%Y-%m-%d")}))