示例#1
0
 def test_attempt_load_not_music(self):
     path_to_file1, path_to_file2 = self.paths_to_not_music[: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="audio")
             uploaded_file2 = SimpleUploadedFile(name=file2name, content=file2.read(), content_type="audio")
     data = {"title": file1name}
     files = {"path_to_mp3": uploaded_file1, "path_to_ogg": uploaded_file2}
     form = MusicForm(data, files)
     self.assertTrue(form.is_bound)
     self.assertTrue(form.errors)
     translation.activate("en")
     expected_errors_ENG = {
         "path_to_mp3": ["Type of file not supported (format of file must be only MP3)"],
         "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_mp3": ["Тип файла не поддерживается (формат файла должен быть только MP3)"],
         "path_to_ogg": ["Тип файла не поддерживается (формат файла должен быть только OGG)"],
     }
     self.assertDictEqual(form.errors, expected_errors_RUS)
     self.assertFalse(form.is_valid())
示例#2
0
 def test_load_music(self):
     for path_to_file_mp3 in self.paths_to_music:
         full_filename = os.path.split(path_to_file_mp3)[1]
         filename, extension = os.path.splitext(full_filename)
         path_to_ogg = path_to_file_mp3[:-4] + ".ogg"
         with open(path_to_file_mp3, "rb") as mp3_file:
             with open(path_to_ogg, "rb") as ogg_file:
                 uploaded_music_mp3 = SimpleUploadedFile(
                     name=filename, content=mp3_file.read(), content_type="audio/mp3"
                 )
                 uploaded_music_ogg = SimpleUploadedFile(
                     name=filename, content=ogg_file.read(), content_type="audio/ogg"
                 )
         data = {"title": filename}
         files = {"path_to_mp3": uploaded_music_mp3, "path_to_ogg": uploaded_music_ogg}
         form = MusicForm(data, files)
         self.assertTrue(form.is_bound)
         self.assertFalse(form.errors)
         self.assertTrue(form.is_valid())