Пример #1
0
    def test_convert_video_status(self):
        """
        Verifies that convert_video_status works as expected.
        """
        video = self.previous_uploads[0]

        # video status should be failed if it's in upload state for more than 24 hours
        video['created'] = datetime(2016, 1, 1, 10, 10, 10, 0, pytz.UTC)
        status = convert_video_status(video)
        self.assertEqual(status, StatusDisplayStrings.get('upload_failed'))

        # `invalid_token` should be converted to `youtube_duplicate`
        video['created'] = datetime.now(pytz.UTC)
        video['status'] = 'invalid_token'
        status = convert_video_status(video)
        self.assertEqual(status, StatusDisplayStrings.get('youtube_duplicate'))

        # for all other status, there should not be any conversion
        statuses = StatusDisplayStrings._STATUS_MAP.keys()  # pylint: disable=protected-access
        statuses.remove('invalid_token')
        for status in statuses:
            video['status'] = status
            new_status = convert_video_status(video)
            self.assertEqual(new_status, StatusDisplayStrings.get(status))
Пример #2
0
    def test_convert_video_status(self):
        """
        Verifies that convert_video_status works as expected.
        """
        video = self.previous_uploads[0]

        # video status should be failed if it's in upload state for more than 24 hours
        video['created'] = datetime(2016, 1, 1, 10, 10, 10, 0, pytz.UTC)
        status = convert_video_status(video)
        self.assertEqual(status, StatusDisplayStrings.get('upload_failed'))

        # `invalid_token` should be converted to `youtube_duplicate`
        video['created'] = datetime.now(pytz.UTC)
        video['status'] = 'invalid_token'
        status = convert_video_status(video)
        self.assertEqual(status, StatusDisplayStrings.get('youtube_duplicate'))

        # for all other status, there should not be any conversion
        statuses = StatusDisplayStrings._STATUS_MAP.keys()  # pylint: disable=protected-access
        statuses.remove('invalid_token')
        for status in statuses:
            video['status'] = status
            new_status = convert_video_status(video)
            self.assertEqual(new_status, StatusDisplayStrings.get(status))
Пример #3
0
 def _check_csv_response(self, expected_profiles):
     """
     Check that the response is a valid CSV response containing rows
     corresponding to previous_uploads and including the expected profiles.
     """
     response = self.client.get(self.url)
     self.assertEqual(response.status_code, 200)
     self.assertEqual(
         response["Content-Disposition"],
         "attachment; filename={course}_video_urls.csv".format(course=self.course.id.course)
     )
     response_reader = StringIO(response.content)
     reader = csv.DictReader(response_reader, dialect=csv.excel)
     self.assertEqual(
         reader.fieldnames,
         (
             ["Name", "Duration", "Date Added", "Video ID", "Status"] +
             ["{} URL".format(profile) for profile in expected_profiles]
         )
     )
     rows = list(reader)
     self.assertEqual(len(rows), len(self.previous_uploads))
     for i, row in enumerate(rows):
         response_video = {
             key.decode("utf-8"): value.decode("utf-8") for key, value in row.items()
         }
         # Videos should be returned by creation date descending
         original_video = self.previous_uploads[-(i + 1)]
         self.assertEqual(response_video["Name"], original_video["client_video_id"])
         self.assertEqual(response_video["Duration"], str(original_video["duration"]))
         dateutil.parser.parse(response_video["Date Added"])
         self.assertEqual(response_video["Video ID"], original_video["edx_video_id"])
         self.assertEqual(response_video["Status"], convert_video_status(original_video))
         for profile in expected_profiles:
             response_profile_url = response_video["{} URL".format(profile)]
             original_encoded_for_profile = next(
                 (
                     original_encoded
                     for original_encoded in original_video["encoded_videos"]
                     if original_encoded["profile"] == profile
                 ),
                 None
             )
             if original_encoded_for_profile:
                 self.assertEqual(response_profile_url, original_encoded_for_profile["url"])
             else:
                 self.assertEqual(response_profile_url, "")
Пример #4
0
 def _check_csv_response(self, expected_profiles):
     """
     Check that the response is a valid CSV response containing rows
     corresponding to previous_uploads and including the expected profiles.
     """
     response = self.client.get(self.url)
     self.assertEqual(response.status_code, 200)
     self.assertEqual(
         response["Content-Disposition"],
         "attachment; filename={course}_video_urls.csv".format(course=self.course.id.course)
     )
     response_reader = StringIO(response.content)
     reader = csv.DictReader(response_reader, dialect=csv.excel)
     self.assertEqual(
         reader.fieldnames,
         (
             ["Name", "Duration", "Date Added", "Video ID", "Status"] +
             ["{} URL".format(profile) for profile in expected_profiles]
         )
     )
     rows = list(reader)
     self.assertEqual(len(rows), len(self.previous_uploads))
     for i, row in enumerate(rows):
         response_video = {
             key.decode("utf-8"): value.decode("utf-8") for key, value in row.items()
         }
         # Videos should be returned by creation date descending
         original_video = self.previous_uploads[-(i + 1)]
         self.assertEqual(response_video["Name"], original_video["client_video_id"])
         self.assertEqual(response_video["Duration"], str(original_video["duration"]))
         dateutil.parser.parse(response_video["Date Added"])
         self.assertEqual(response_video["Video ID"], original_video["edx_video_id"])
         self.assertEqual(response_video["Status"], convert_video_status(original_video))
         for profile in expected_profiles:
             response_profile_url = response_video["{} URL".format(profile)]
             original_encoded_for_profile = next(
                 (
                     original_encoded
                     for original_encoded in original_video["encoded_videos"]
                     if original_encoded["profile"] == profile
                 ),
                 None
             )
             if original_encoded_for_profile:
                 self.assertEqual(response_profile_url, original_encoded_for_profile["url"])
             else:
                 self.assertEqual(response_profile_url, "")
Пример #5
0
 def test_get_json(self):
     response = self.client.get_json(self.url)
     self.assertEqual(response.status_code, 200)
     response_videos = json.loads(response.content)['videos']
     self.assertEqual(len(response_videos), len(self.previous_uploads))
     for i, response_video in enumerate(response_videos):
         # Videos should be returned by creation date descending
         original_video = self.previous_uploads[-(i + 1)]
         self.assertEqual(
             set(response_video.keys()),
             set([
                 'edx_video_id', 'client_video_id', 'created', 'duration',
                 'status', 'course_video_image_url'
             ]))
         dateutil.parser.parse(response_video['created'])
         for field in ['edx_video_id', 'client_video_id', 'duration']:
             self.assertEqual(response_video[field], original_video[field])
         self.assertEqual(response_video['status'],
                          convert_video_status(original_video))
Пример #6
0
 def test_get_json(self):
     response = self.client.get_json(self.url)
     self.assertEqual(response.status_code, 200)
     response_videos = json.loads(response.content)["videos"]
     self.assertEqual(len(response_videos), len(self.previous_uploads))
     for i, response_video in enumerate(response_videos):
         # Videos should be returned by creation date descending
         original_video = self.previous_uploads[-(i + 1)]
         self.assertEqual(
             set(response_video.keys()),
             set([
                 "edx_video_id", "client_video_id", "created", "duration",
                 "status"
             ]))
         dateutil.parser.parse(response_video["created"])
         for field in ["edx_video_id", "client_video_id", "duration"]:
             self.assertEqual(response_video[field], original_video[field])
         self.assertEqual(response_video["status"],
                          convert_video_status(original_video))
Пример #7
0
 def test_get_json(self):
     response = self.client.get_json(self.url)
     self.assertEqual(response.status_code, 200)
     response_videos = json.loads(response.content)["videos"]
     self.assertEqual(len(response_videos), len(self.previous_uploads))
     for i, response_video in enumerate(response_videos):
         # Videos should be returned by creation date descending
         original_video = self.previous_uploads[-(i + 1)]
         self.assertEqual(
             set(response_video.keys()),
             set(["edx_video_id", "client_video_id", "created", "duration", "status"])
         )
         dateutil.parser.parse(response_video["created"])
         for field in ["edx_video_id", "client_video_id", "duration"]:
             self.assertEqual(response_video[field], original_video[field])
         self.assertEqual(
             response_video["status"],
             convert_video_status(original_video)
         )
Пример #8
0
 def test_get_json(self):
     response = self.client.get_json(self.url)
     self.assertEqual(response.status_code, 200)
     response_videos = json.loads(response.content)['videos']
     self.assertEqual(len(response_videos), len(self.previous_uploads))
     for i, response_video in enumerate(response_videos):
         # Videos should be returned by creation date descending
         original_video = self.previous_uploads[-(i + 1)]
         self.assertEqual(
             set(response_video.keys()),
             set(['edx_video_id', 'client_video_id', 'created', 'duration', 'status', 'course_video_image_url'])
         )
         dateutil.parser.parse(response_video['created'])
         for field in ['edx_video_id', 'client_video_id', 'duration']:
             self.assertEqual(response_video[field], original_video[field])
         self.assertEqual(
             response_video['status'],
             convert_video_status(original_video)
         )