Ejemplo n.º 1
0
 def test_attempt_load_not_video(self):
     path_to_file1, path_to_file2 = self.paths_to_not_video[:2]
     full_file1name = os.path.split(path_to_file1)[1]
     full_file2name = os.path.split(path_to_file2)[1]
     file1name = os.path.splitext(full_file1name)[0]
     file2name = os.path.splitext(full_file2name)[0]
     with open(path_to_file1, "rb") as file1:
         with open(path_to_file2, "rb") as file2:
             uploaded_file1 = SimpleUploadedFile(name=file1name, content=file1.read(), content_type="video")
             uploaded_file2 = SimpleUploadedFile(name=file2name, content=file2.read(), content_type="video")
     data = {"title": file1name}
     files = {"path_to_mp4": uploaded_file1, "path_to_ogg": uploaded_file2}
     form = VideoForm(data, files)
     self.assertTrue(form.is_bound)
     self.assertTrue(form.errors)
     translation.activate("en")
     expected_errors_ENG = {
         "path_to_mp4": ["Type of file not supported (format of file must be only MP4)"],
         "path_to_ogg": ["Type of file not supported (format of file must be only OGG)"],
     }
     self.assertDictEqual(form.errors, expected_errors_ENG)
     translation.activate("ru")
     expected_errors_RUS = {
         "path_to_mp4": ["Тип файла не поддерживается (формат файла должен быть только MP4)"],
         "path_to_ogg": ["Тип файла не поддерживается (формат файла должен быть только OGG)"],
     }
     self.assertDictEqual(form.errors, expected_errors_RUS)
     self.assertFalse(form.is_valid())
Ejemplo n.º 2
0
 def test_load_video(self):
     for path_to_file_mp4 in self.paths_to_video:
         full_filename = os.path.split(path_to_file_mp4)[1]
         filename, extension = os.path.splitext(full_filename)
         path_to_ogg = path_to_file_mp4[:-4] + ".ogv"
         with open(path_to_file_mp4, "rb") as mp4_file:
             with open(path_to_ogg, "rb") as ogg_file:
                 uploaded_video_mp4 = SimpleUploadedFile(
                     name=filename, content=mp4_file.read(), content_type="video/mp4"
                 )
                 uploaded_video_ogg = SimpleUploadedFile(
                     name=filename, content=ogg_file.read(), content_type="video/ogg"
                 )
         data = {"title": filename}
         files = {"path_to_mp4": uploaded_video_mp4, "path_to_ogg": uploaded_video_ogg}
         form = VideoForm(data, files)
         self.assertTrue(form.is_bound)
         self.assertFalse(form.errors)
         self.assertTrue(form.is_valid())