示例#1
0
    def test_video_published_email_sent_to_user(self):
        # Setup data - Create a Request with status 4, and a video
        request = create_request(100, self.normal_user,
                                 Request.Statuses.UPLOADED)
        video = create_video(300, request, Video.Statuses.PENDING)

        # Video data to be patched
        data = {
            "editor_id": self.staff_user.id,
            "additional_data": {
                "editing_done": True,
                "coding": {
                    "website": True
                },
                "publishing": {
                    "website": "https://example.com"
                },
            },
        }

        # Authorized staff user and update video data
        self.authorize_user(self.staff_user)
        response = self.client.patch(
            f"/api/v1/admin/requests/{request.id}/videos/{video.id}", data)
        self.assertEqual(response.status_code, status.HTTP_200_OK)

        # Check if e-mail was sent to the right people
        self.assertEqual(len(mail.outbox), 1)
        self.assertIn(self.normal_user.email, mail.outbox[0].to)
        self.assertIn(self.pr_responsible.email, mail.outbox[0].bcc)
        self.assertIn(settings.DEFAULT_REPLY_EMAIL, mail.outbox[0].reply_to)
        self.assertEqual(mail.outbox[0].subject,
                         f"{video.request.title} | Új videót publikáltunk")
示例#2
0
 def setUp(self):
     user = create_user()
     self.request = create_request(100, user)
     self.crew_member = create_crew(200, self.request, user, "Test")
     self.video = create_video(300, self.request)
     self.comment = create_comment(400, self.request, user, False)
     self.rating = create_rating(500, self.video, user)
示例#3
0
    def test_sentinel_user_on_user_delete(self):
        user = create_user()
        request = create_request(100, user, responsible=user)
        video = create_video(200, request, editor=user)
        create_crew(300, request, user, "Test")
        create_comment(400, request, user, False)
        create_rating(500, video, user)

        request.refresh_from_db()

        self.assertEqual(request.requester, user)
        self.assertEqual(request.responsible, user)
        self.assertEqual(request.videos.get().editor, user)
        self.assertEqual(request.crew.get().member, user)
        self.assertEqual(request.comments.get().author, user)
        self.assertEqual(request.videos.get().ratings.get().author, user)

        user.delete()
        request.refresh_from_db()

        sentinel_user = get_sentinel_user()
        self.assertEqual(request.requester, sentinel_user)
        self.assertEqual(request.responsible, sentinel_user)
        self.assertEqual(request.videos.get().editor, sentinel_user)
        self.assertFalse(request.crew.exists())
        self.assertEqual(request.comments.get().author, sentinel_user)
        self.assertEqual(request.videos.get().ratings.get().author,
                         sentinel_user)
示例#4
0
    def setUp(self):
        self.url = "/api/v1/admin/requests"
        self.user = create_user(is_admin=True)
        url = reverse("login_obtain_jwt_pair")
        resp = self.client.post(
            url,
            {
                "username": self.user.username,
                "password": get_default_password()
            },
            format="json",
        )
        token = resp.data["access"]
        self.client.credentials(HTTP_AUTHORIZATION=f"Bearer {token}")

        self.request1 = create_request(100,
                                       self.user,
                                       start="2020-03-10T19:30:00+0100")
        self.request2 = create_request(101,
                                       self.user,
                                       start="2020-07-07T19:30:00+0100")
        self.request3 = create_request(102,
                                       self.user,
                                       start="2020-12-24T19:30:00+0100")

        self.video1 = create_video(200, self.request1)
        self.video2 = create_video(201, self.request2)
        self.video2.additional_data = {
            "aired": [
                "2020-01-12",
                "2019-11-25",
                "2020-10-25",
                "2018-05-19",
                "2020-07-14",
            ]
        }
        self.video2.save()
        self.video3 = create_video(202, self.request3)
        self.video3.additional_data = {
            "aired": [
                "2019-03-03",
                "2020-04-04",
                "2018-02-02",
            ],
            "length": 152,
        }
        self.video3.save()
示例#5
0
 def test_video_additional_data_validation(self):
     request = create_request(100, self.user)
     video = create_video(200, request)
     response = self.client.patch(
         f"{self.url}/{request.id}/videos/{video.id}",
         {"additional_data": {"randomKey": "randomValue"}},
     )
     self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)
     self.assertIn(
         "Additional properties are not allowed ('randomKey' was unexpected)",
         response.data["additional_data"][0],
     )
示例#6
0
    def test_video_additional_data_aired_get_sorted_by_date(self):
        request = create_request(100, self.user)
        video = create_video(200, request)

        data = {
            "additional_data": {
                "aired": [
                    "2020-01-12",
                    "2019-11-25",
                    "2020-10-25",
                    "2018-05-19",
                    "2020-07-14",
                ]
            }
        }

        response = self.client.patch(f"{self.url}/{request.id}/videos/{video.id}", data)
        self.assertEqual(response.status_code, status.HTTP_200_OK)
        self.assertListEqual(
            response.data["additional_data"]["aired"],
            ["2020-10-25", "2020-07-14", "2020-01-12", "2019-11-25", "2018-05-19"],
        )
    def setUp(self):
        self.url = "/api/v1/users"
        self.admin = create_user(is_admin=True)
        self.staff = create_user(is_staff=True)
        self.user = create_user()

        # Worked on Requests
        # 20 weeks before today
        self.request1 = create_request(100,
                                       self.user,
                                       start="2020-07-07T20:00:00+0100",
                                       responsible=self.admin)
        self.request2 = create_request(101,
                                       self.user,
                                       start="2020-07-13T20:00:00+0100",
                                       responsible=self.staff)
        create_crew(200, self.request1, self.admin, "Cameraman")
        create_crew(201, self.request2, self.admin, "Technician")
        create_crew(202, self.request1, self.staff, "Reporter")
        create_video(300, self.request1, editor=self.admin)
        create_video(301, self.request1, editor=self.staff)

        # Before 2020-11-01
        self.request3 = create_request(102,
                                       self.user,
                                       start="2020-10-10T20:00:00+0100",
                                       responsible=self.admin)
        self.request4 = create_request(103,
                                       self.user,
                                       start="2020-10-25T20:00:00+0100",
                                       responsible=self.staff)
        create_crew(203, self.request3, self.admin, "Cameraman")
        create_crew(204, self.request4, self.admin, "Technician")
        create_crew(205, self.request3, self.staff, "Reporter")
        create_video(302, self.request3, editor=self.admin)
        create_video(303, self.request3, editor=self.staff)

        # Between 2020-11-01 and 2020-12-01
        self.request5 = create_request(104,
                                       self.user,
                                       start="2020-11-10T20:00:00+0100",
                                       responsible=self.admin)
        self.request6 = create_request(105,
                                       self.user,
                                       start="2020-11-25T20:00:00+0100",
                                       responsible=self.staff)
        create_crew(206, self.request5, self.admin, "Cameraman")
        create_crew(207, self.request5, self.admin, "Technician")
        create_crew(208, self.request5, self.staff, "Reporter")
        create_crew(209, self.request6, self.staff, "Technician")
        create_video(304, self.request5, editor=self.staff)
        create_video(305, self.request6, editor=self.staff)

        # After 2020-12-01
        self.request7 = create_request(106,
                                       self.user,
                                       start="2020-12-10T20:00:00+0100",
                                       responsible=self.admin)
        self.request8 = create_request(107,
                                       self.user,
                                       start="2020-12-25T20:00:00+0100",
                                       responsible=self.staff)
        create_crew(210, self.request8, self.admin, "Cameraman")
        create_crew(211, self.request7, self.staff, "Reporter")
        create_crew(212, self.request8, self.staff, "Technician")
        create_video(306, self.request7, editor=self.admin)
        create_video(307, self.request8, editor=self.admin)
        create_video(308, self.request7, editor=self.staff)
        create_video(309, self.request8, editor=self.staff)
示例#8
0
    def test_weekly_staff_email_sending(self, mock_email_staff_weekly_tasks,
                                        frozen_time):
        # Create test Requests - Recording
        # Should be included
        rec1 = create_request(100,
                              self.normal_user,
                              start="2020-11-16T04:16:13+0100")
        rec2 = create_request(
            101,
            self.normal_user,
            Request.Statuses.ACCEPTED,
            start="2020-11-21T21:41:57+0100",
        )
        # Should not be included
        rec3 = create_request(
            102, self.normal_user,
            start="2020-11-15T10:01:24+0100")  # previous week
        rec4 = create_request(103,
                              self.normal_user,
                              start="2020-11-24T17:22:05+0100")  # next week
        rec5 = create_request(
            104,
            self.normal_user,
            Request.Statuses.EDITED,
            start="2020-11-20T14:55:45+0100",
        )  # this week but wrong status

        # Create test Requests - Editing
        # Should be included
        edit1 = create_request(110, self.normal_user,
                               Request.Statuses.RECORDED)
        edit2 = create_request(111, self.normal_user,
                               Request.Statuses.UPLOADED)
        edit_vid21 = create_video(211, edit2, Video.Statuses.PENDING)
        edit_vid22 = create_video(212, edit2, Video.Statuses.IN_PROGRESS,
                                  self.staff_user)
        # Should not be included
        edit3 = create_request(112, self.normal_user,
                               Request.Statuses.EDITED)  # later status
        edit4 = create_request(
            113, self.normal_user,
            Request.Statuses.RECORDED)  # good status but wrong status video
        edit_vid41 = create_video(213, edit4, Video.Statuses.EDITED)
        edit5 = create_request(
            114, self.normal_user,
            Request.Statuses.EDITED)  # wrong status but good status video
        edit_vid51 = create_video(214, edit5, Video.Statuses.PENDING)
        """
        Case 1: Successful e-mail sending
        """
        # Call management command
        with StringIO() as out:
            call_command("email_weekly_tasks", stdout=out)
            self.assertEqual(out.getvalue(),
                             "Weekly tasks email was sent successfully.\n")

        # Check if fuction was called with correct parameters
        mock_email_staff_weekly_tasks.assert_called_once()

        self.assertEqual(len(mock_email_staff_weekly_tasks.call_args.args[0]),
                         2)
        self.assertIn(rec1, mock_email_staff_weekly_tasks.call_args.args[0])
        self.assertIn(rec2, mock_email_staff_weekly_tasks.call_args.args[0])
        self.assertNotIn(rec3, mock_email_staff_weekly_tasks.call_args.args[0])
        self.assertNotIn(rec4, mock_email_staff_weekly_tasks.call_args.args[0])
        self.assertNotIn(rec5, mock_email_staff_weekly_tasks.call_args.args[0])

        self.assertEqual(len(mock_email_staff_weekly_tasks.call_args.args[1]),
                         1)
        self.assertIn(edit1, mock_email_staff_weekly_tasks.call_args.args[1])
        self.assertNotIn(edit2,
                         mock_email_staff_weekly_tasks.call_args.args[1])
        self.assertNotIn(edit3,
                         mock_email_staff_weekly_tasks.call_args.args[1])
        self.assertNotIn(edit4,
                         mock_email_staff_weekly_tasks.call_args.args[1])
        self.assertNotIn(edit5,
                         mock_email_staff_weekly_tasks.call_args.args[1])

        self.assertEqual(len(mock_email_staff_weekly_tasks.call_args.args[2]),
                         2)
        self.assertIn(edit_vid21,
                      mock_email_staff_weekly_tasks.call_args.args[2])
        self.assertIn(edit_vid22,
                      mock_email_staff_weekly_tasks.call_args.args[2])
        self.assertNotIn(edit_vid41,
                         mock_email_staff_weekly_tasks.call_args.args[2])
        self.assertNotIn(edit_vid51,
                         mock_email_staff_weekly_tasks.call_args.args[2])

        # Check if e-mail was sent to the right people
        self.assertEqual(len(mail.outbox), 1)
        self.assertIn(settings.WEEKLY_TASK_EMAIL, mail.outbox[0].to)
        self.assertEqual(mail.outbox[0].subject,
                         "Eheti forgatások és vágandó anyagok")
        """
        Case 2: No Request for the week.
        """
        # Change time to next month
        frozen_time.move_to("2020-12-21 10:20:30")

        # Change editing objects
        edit1.status = Request.Statuses.EDITED
        edit1.save()
        edit2.status = Request.Statuses.ARCHIVED
        edit2.save()

        # Call management command
        with StringIO() as out:
            call_command("email_weekly_tasks", stdout=out)
            self.assertEqual(out.getvalue(), "No tasks for this week.\n")
示例#9
0
    def test_service_account_should_not_access_other_endpoints(self):
        request = create_request(100, self.user)
        video = create_video(200, request)
        comment = create_comment(300, request, self.user, False)
        rating = create_rating(400, video, self.user)

        # Default API
        # Create Request
        response = self.client.post(self.default_url,
                                    self._create_request_test_data)
        self.assertEqual(response.status_code, status.HTTP_403_FORBIDDEN)

        # List Requests
        response = self.client.get(self.default_url)
        self.assertEqual(response.status_code, status.HTTP_403_FORBIDDEN)

        # Retrieve Request
        response = self.client.get(f"{self.default_url}/{request.id}")
        self.assertEqual(response.status_code, status.HTTP_403_FORBIDDEN)

        # List Videos
        response = self.client.get(f"{self.default_url}/{request.id}/videos")
        self.assertEqual(response.status_code, status.HTTP_403_FORBIDDEN)

        # Retrieve Video
        response = self.client.get(
            f"{self.default_url}/{request.id}/videos/{video.id}")
        self.assertEqual(response.status_code, status.HTTP_403_FORBIDDEN)

        # Create Comment
        response = self.client.post(
            f"{self.default_url}/{request.id}/comments", {"text": "Test"})
        self.assertEqual(response.status_code, status.HTTP_403_FORBIDDEN)

        # List Comments
        response = self.client.get(f"{self.default_url}/{request.id}/comments")
        self.assertEqual(response.status_code, status.HTTP_403_FORBIDDEN)

        # Retrieve Comment
        response = self.client.get(
            f"{self.default_url}/{request.id}/comments/{comment.id}")
        self.assertEqual(response.status_code, status.HTTP_403_FORBIDDEN)

        # Modify Comment
        response = self.client.patch(
            f"{self.default_url}/{request.id}/comments/{comment.id}",
            {"text": "Test"})
        self.assertEqual(response.status_code, status.HTTP_403_FORBIDDEN)

        # Delete Comment
        response = self.client.delete(
            f"{self.default_url}/{request.id}/comments/{comment.id}")
        self.assertEqual(response.status_code, status.HTTP_403_FORBIDDEN)

        # Create Rating
        response = self.client.post(
            f"{self.default_url}/{request.id}/videos/{video.id}/ratings",
            {"rating": 5})
        self.assertEqual(response.status_code, status.HTTP_403_FORBIDDEN)

        # List Ratings
        response = self.client.get(
            f"{self.default_url}/{request.id}/videos/{video.id}/ratings")
        self.assertEqual(response.status_code, status.HTTP_403_FORBIDDEN)

        # Retrieve Rating
        response = self.client.get(
            f"{self.default_url}/{request.id}/videos/{video.id}/ratings/{rating.id}"
        )
        self.assertEqual(response.status_code, status.HTTP_403_FORBIDDEN)

        # Modify Rating
        response = self.client.patch(
            f"{self.default_url}/{request.id}/videos/{video.id}/ratings/{rating.id}",
            {"rating": 5},
        )
        self.assertEqual(response.status_code, status.HTTP_403_FORBIDDEN)

        # Delete Rating
        response = self.client.delete(
            f"{self.default_url}/{request.id}/videos/{video.id}/ratings/{rating.id}"
        )
        self.assertEqual(response.status_code, status.HTTP_403_FORBIDDEN)
示例#10
0
    def setUp(self):
        self.url = "/api/v1/admin/statistics/requests"

        self.admin = create_user(is_admin=True)
        self.staff = create_user(is_staff=True)
        self.user = create_user()

        # Requests before 2020-11-01
        # Requested status
        create_request(100,
                       self.user,
                       Request.Statuses.REQUESTED,
                       start="2020-10-16T20:00:00+0100")
        create_request(101,
                       self.user,
                       Request.Statuses.REQUESTED,
                       start="2020-10-22T20:00:00+0100")
        # In progress (between Accepted and Archived)
        create_request(102,
                       self.user,
                       Request.Statuses.UPLOADED,
                       start="2020-10-05T20:00:00+0100")
        # Completed (Done)
        create_request(103,
                       self.user,
                       Request.Statuses.DONE,
                       start="2020-10-10T20:00:00+0100")
        create_request(104,
                       self.user,
                       Request.Statuses.DONE,
                       start="2020-10-30T20:00:00+0100")
        create_request(105,
                       self.user,
                       Request.Statuses.DONE,
                       start="2020-10-08T20:00:00+0100")
        # Upcoming (Accepted)
        self.upcoming1 = create_request(106,
                                        self.user,
                                        Request.Statuses.ACCEPTED,
                                        start="2020-10-29T20:00:00+0100")
        self.upcoming2 = create_request(107,
                                        self.user,
                                        Request.Statuses.ACCEPTED,
                                        start="2020-10-02T20:00:00+0100")

        # Requests between 2020-11-01 and 2020-12-01
        # Requested status
        create_request(200,
                       self.user,
                       Request.Statuses.REQUESTED,
                       start="2020-11-16T20:00:00+0100")
        create_request(201,
                       self.user,
                       Request.Statuses.REQUESTED,
                       start="2020-11-22T20:00:00+0100")
        # In progress (between Accepted and Archived)
        create_request(202,
                       self.user,
                       Request.Statuses.UPLOADED,
                       start="2020-11-05T20:00:00+0100")
        create_request(203,
                       self.user,
                       Request.Statuses.RECORDED,
                       start="2020-11-10T20:00:00+0100")
        create_request(204,
                       self.user,
                       Request.Statuses.ARCHIVED,
                       start="2020-11-30T20:00:00+0100")
        # Completed (Done)
        create_request(205,
                       self.user,
                       Request.Statuses.DONE,
                       start="2020-11-08T20:00:00+0100")
        # Upcoming (Accepted)
        self.upcoming3 = create_request(206,
                                        self.user,
                                        Request.Statuses.ACCEPTED,
                                        start="2020-11-29T20:00:00+0100")
        self.upcoming4 = create_request(207,
                                        self.user,
                                        Request.Statuses.ACCEPTED,
                                        start="2020-11-02T20:00:00+0100")

        # Requests after 2020-12-01
        # Requested status
        create_request(300,
                       self.user,
                       Request.Statuses.REQUESTED,
                       start="2020-12-16T20:00:00+0100")
        create_request(301,
                       self.user,
                       Request.Statuses.REQUESTED,
                       start="2020-12-22T20:00:00+0100")
        create_request(302,
                       self.user,
                       Request.Statuses.REQUESTED,
                       start="2020-12-05T20:00:00+0100")
        # In progress (between Accepted and Archived)
        create_request(303,
                       self.user,
                       Request.Statuses.RECORDED,
                       start="2020-12-10T20:00:00+0100")
        create_request(304,
                       self.user,
                       Request.Statuses.ARCHIVED,
                       start="2020-12-30T20:00:00+0100")
        # Completed (Done)
        create_request(305,
                       self.user,
                       Request.Statuses.DONE,
                       start="2020-12-08T20:00:00+0100")
        # Upcoming (Accepted)
        self.upcoming5 = create_request(306,
                                        self.user,
                                        Request.Statuses.ACCEPTED,
                                        start="2020-12-29T20:00:00+0100")
        self.upcoming6 = create_request(307,
                                        self.user,
                                        Request.Statuses.ACCEPTED,
                                        start="2020-12-02T20:00:00+0100")

        # Videos before 2020-11-01
        self.video1 = create_video(400, self.upcoming2)
        self.video2 = create_video(401, self.upcoming2)
        self.video3 = create_video(402, self.upcoming2)  # No related rating

        # Video1 ratings - Avg: 4.3
        create_rating(500, self.video1, self.user, 5)
        create_rating(501, self.video1, self.staff, 4)
        create_rating(502, self.video1, self.admin, 4)

        # Video2 ratings - Avg: 3.3
        create_rating(503, self.video2, self.user, 3)
        create_rating(504, self.video2, self.staff, 3)
        create_rating(505, self.video2, self.admin, 4)

        # Videos between 2020-11-01 and 2020-12-01
        self.video4 = create_video(403, self.upcoming4)
        self.video5 = create_video(404, self.upcoming4)
        self.video6 = create_video(405, self.upcoming4)  # No related rating

        # Video4 ratings - Avg: 5.0
        create_rating(506, self.video4, self.user, 5)
        create_rating(507, self.video4, self.staff, 5)
        create_rating(508, self.video4, self.admin, 5)

        # Video5 ratings - Avg: 2.0
        create_rating(509, self.video5, self.user, 2)
        create_rating(510, self.video5, self.staff, 1)
        create_rating(511, self.video5, self.admin, 3)

        # Videos after 2020-12-01
        self.video7 = create_video(406, self.upcoming6)
        self.video8 = create_video(407, self.upcoming6)
        self.video9 = create_video(408, self.upcoming6)  # No related rating

        # Video7 ratings - Avg: 4.0
        create_rating(512, self.video7, self.user, 4)
        create_rating(513, self.video7, self.staff, 4)
        create_rating(514, self.video7, self.admin, 4)

        # Video8 ratings - Avg: 3.6
        create_rating(515, self.video8, self.user, 5)
        create_rating(516, self.video8, self.staff, 3)
        create_rating(517, self.video8, self.admin, 3)