def test_deprecated_aliases(self): language = SubtitleLanguageFactory(video=self.video, language_code='es') self.run_update(language, { 'is_original': True, 'is_complete': True, }) self.video = test_utils.reload_obj(self.video) assert_equal(self.video.primary_audio_language_code, 'es') assert_equal(test_utils.reload_obj(language).subtitles_complete, True)
def test_is_complete_null(self): # when is_complete is None, we leave subtitles_complete alone language = self.video.subtitle_language('en') language.subtitles_complete = False language.save() data = { 'subtitles': SubtitleSetFactory().to_xml(), 'is_complete': None, } self.run_create(data) assert_false(test_utils.reload_obj(language).subtitles_complete) language.subtitles_complete = True language.save() self.run_create(data) assert_true(test_utils.reload_obj(language).subtitles_complete)
def test_change_soft_limits(language, language_client): language_client.put({'soft_limit_cps': 30, 'soft_limit_lines': None}) language = test_utils.reload_obj(language) assert language.soft_limit_cps == 30 assert language.soft_limit_lines is None assert language.soft_limit_cpl is None
def test_cant_change_username(self): orig_username = self.user.username response = self.client.put(self.detail_url(self.user), data={ 'username': '******', }) assert_equal(response.status_code, status.HTTP_200_OK) assert_equal(test_utils.reload_obj(self.user).username, orig_username)
def test_permission_check(self, get_workflow): workflow = get_workflow.return_value workflow.user_can_delete_subtitles.return_value = False response = self.client.delete(self.url) assert_equal(response.status_code, status.HTTP_403_FORBIDDEN) assert_false(test_utils.reload_obj(self.version).is_deleted()) assert_equal(workflow.user_can_delete_subtitles.call_args, mock.call(self.user, self.language_code))
def test_null_team_string(self): # sending the string "null" for team should work the same as sending # None TeamVideoFactory(video=self.video) result = self.run_update({ 'team': 'null', }) assert_equal(test_utils.reload_obj(result).get_team_video(), None)
def test_publish_primary_audio_language_updates_video(self): # When we publish a version for the primary audio language, we should # update the video's metadata TeamVideoFactory(video=self.video) self.video.update_metadata({'speaker-name': 'Speaker1'}) self.video = test_utils.reload_obj(self.video) self.video.primary_audio_language_code = 'en' self.video.save() version = pipeline.add_subtitles(self.video, 'en', None, visibility='private', metadata={'speaker-name': 'Speaker2'}) version.publish() self.video = test_utils.reload_obj(self.video) self.assertEquals(self.video.get_metadata(), {'speaker-name': 'Speaker2'})
def check_put(self, data): orig_user_data = self.user.__dict__.copy() response = self.client.put(self.detail_url(self.user), data=data) assert_equal(response.status_code, status.HTTP_200_OK, response.content) user = test_utils.reload_obj(self.user) self.check_user_data(user, data, orig_user_data) assert_equals(user.created_by, None) self.assert_response_data_correct(response, user, get=False)
def test_approve(self): app = self.application_by_status[Application.STATUS_PENDING] response = self.client.put(self.detail_url(app), { 'status': 'Approved', }) app = test_utils.reload_obj(app) assert_equal(app.status, Application.STATUS_APPROVED) assert_not_equal(app.modified, None) assert_true(self.team.user_is_member(app.user))
def test_update(self): task = self.task_factory(language='es') response = self.client.put(self.detail_url(task), { 'priority': 3 }) assert_equal(response.status_code, status.HTTP_200_OK, response.content) assert_equal(test_utils.reload_obj(task).priority, 3) self.check_task_creation_extra(task, assigned=False)
def test_update(self): project = ProjectFactory(team=self.team) response = self.client.put(self.detail_url(project), data={ 'description': 'New description', }) assert_equal(response.status_code, status.HTTP_200_OK, response.content) assert_equal(test_utils.reload_obj(project).description, 'New description')
def test_update_team(self): team = TeamFactory() response = self.client.put(self.detail_url(team), data={ 'name': 'New Name', }) assert_equal(response.status_code, status.HTTP_200_OK, response.content) team = test_utils.reload_obj(team) assert_equal(team.name, 'New Name')
def test_deny(self): app = self.application_by_status[Application.STATUS_PENDING] response = self.client.put(self.detail_url(app), { 'status': 'Denied', }) assert_equal(response.status_code, status.HTTP_200_OK, response.content) app = test_utils.reload_obj(app) assert_equal(app.status, Application.STATUS_DENIED) assert_not_equal(app.modified, None)
def test_assign(self): task = self.task_factory(language='es') response = self.client.put(self.detail_url(task), { 'assignee': self.member.username, }) assert_equal(response.status_code, status.HTTP_200_OK, response.content) task = test_utils.reload_obj(task) assert_equal(task.assignee, self.member) self.check_task_creation_extra(task, assigned=True)
def test_update_without_team_or_project(self): # if we run an update without team or project field, we should keep it # in its current place team = TeamFactory(slug='team', admin=self.user) project = ProjectFactory(team=team) TeamVideoFactory(video=self.video, team=team, project=project) self.run_update({'title': 'new-title'}) team_video = test_utils.reload_obj(self.video).get_team_video() assert_equal(team_video.team, team) assert_equal(team_video.project, project)
def test_change_role(self): member = TeamMemberFactory(team=self.team, role=TeamMember.ROLE_CONTRIBUTOR) response = self.client.put(self.detail_url(member.user), data={ 'role': 'admin', }) assert_equal(response.status_code, status.HTTP_200_OK, response.content) assert_equal(test_utils.reload_obj(member).role, TeamMember.ROLE_ADMIN)
def test_setup_callback(self): # Test the setup_callback param def setup_callback(video, video_url): video.title = 'setup_callback title' video, video_url = Video.add(MockVideoType(self.url), self.user, setup_callback) assert_equal(video.title, 'setup_callback title') # check that we saved the data to the DB assert_equal( test_utils.reload_obj(video).title, 'setup_callback title')
def test_set_approved(self): # I have no clue why a client would change the approved field # manually, but the old API supported it. task = self.task_factory(language='es') response = self.client.put(self.detail_url(task), { 'approved': 'Rejected', }) assert_equal(response.status_code, status.HTTP_200_OK, response.content) assert_equal(test_utils.reload_obj(task).approved, Task.APPROVED_IDS['Rejected']) self.check_task_creation_extra(task, assigned=False)
def test_complete_assigns_task(self): task = self.task_factory(language='es') pipeline.add_subtitles(self.team_video.video, 'es', None, author=self.member) response = self.client.put(self.detail_url(task), { 'complete': 1, }) assert_equal(response.status_code, status.HTTP_200_OK, response.content) task = test_utils.reload_obj(task) assert_equal(task.approved, Task.APPROVED_IDS['Approved']) assert_equal(task.assignee, self.user)
def test_username_in_put(self): # test the username field being in a PUT request. It doesn't really # make sense in this case so we should just ignore it member = TeamMemberFactory(team=self.team, role=TeamMember.ROLE_CONTRIBUTOR) response = self.client.put(self.detail_url(member.user), data={ 'username': '******', 'role': 'admin', }) assert_equal(response.status_code, status.HTTP_200_OK, response.content) assert_equal(test_utils.reload_obj(member).role, TeamMember.ROLE_ADMIN)
def test_add_metadata_for_primary_language_updates_video(self): # When we set metadata for the primary audio language, we should # update the video's metadata self.video.update_metadata({'speaker-name': 'Speaker1'}) self.video.primary_audio_language_code = 'en' self.video.save() version = pipeline.add_subtitles(self.video, 'en', None, metadata={'speaker-name': 'Speaker2'}) self.video = test_utils.reload_obj(self.video) self.assertEquals(self.video.get_metadata(), {'speaker-name': 'Speaker2'})
def test_add_metadata_for_other_languages_dont_update_video(self): # When we set metadata for a language other than the primary audio # language, it shouldn't update the video self.video.update_metadata({'speaker-name': 'Speaker1'}) self.video.primary_audio_language_code = 'en' self.video.save() version = pipeline.add_subtitles(self.video, 'fr', None, metadata={'speaker-name': 'Speaker2'}) self.video = test_utils.reload_obj(self.video) self.assertEquals(self.video.get_metadata(), {'speaker-name': 'Speaker1'})
def test_send_back(self): task = self.task_factory(language='es', assignee=self.member) pipeline.add_subtitles(self.team_video.video, 'es', None, author=self.member) task.approved = Task.APPROVED_IDS['Approved'] task.complete() review_task = self.team_video.task_set.incomplete().get() response = self.client.put(self.detail_url(review_task), { 'send_back': 1, }) assert_equal(response.status_code, status.HTTP_200_OK, response.content) assert_equal(test_utils.reload_obj(review_task).approved, Task.APPROVED_IDS['Rejected'])
def test_add_metadata_for_private_versions_dont_update_video(self): # When we set metadata for the primary audio language, but the version # is private, we shouldn't update the video's metadata TeamVideoFactory(video=self.video) self.video.update_metadata({'speaker-name': 'Speaker1'}) self.video.primary_audio_language_code = 'en' self.video.save() version = pipeline.add_subtitles(self.video, 'en', None, visibility='private', metadata={'speaker-name': 'Speaker2'}) self.video = test_utils.reload_obj(self.video) self.assertEquals(self.video.get_metadata(), {'speaker-name': 'Speaker1'})
def test_change_checks_permissions(self): #def can_assign_role(team, user, role, to_user): self.can_assign_role.return_value = False member = TeamMemberFactory(team=self.team, role=TeamMember.ROLE_CONTRIBUTOR) response = self.client.put(self.detail_url(member.user), data={ 'username': member.user, 'role': TeamMember.ROLE_ADMIN, }) assert_equal(response.status_code, status.HTTP_403_FORBIDDEN) assert_equal(test_utils.reload_obj(member).role, TeamMember.ROLE_CONTRIBUTOR) assert_equal(self.can_assign_role.call_args, mock.call(self.team, self.user, TeamMember.ROLE_ADMIN, member.user))
def test_set_project(self): project = ProjectFactory() self.run_update({ 'team': project.team.slug, 'project': project.slug, }) team_video = self.video.get_team_video() assert_equal(team_video.project, project) # None signifies the default project self.run_update({ 'team': project.team.slug, 'project': None, }) assert_true( test_utils.reload_obj(team_video).project.is_default_project)
def test_dfxp_serializer(self): video = get_video() sl_en = make_subtitle_language(video, 'en') video.primary_audio_language_code = 'en' video.save() make_subtitle_version(sl_en, [(100, 200, 'Here we go!')], title='title') sl_en = reload_obj(sl_en) content = self._download_subs(sl_en, 'dfxp') serialized = DFXPParser(content) subtitle_set = serialized.to_internal() self.assertEqual(len(subtitle_set), 1) start, end, content, meta = list(subtitle_set)[0] self.assertEqual(start, 100) self.assertEqual(end, 200) self.assertEqual(content, 'Here we go!')
def test_submit_video_has_no_primary_audio_language(self): # test submitting when the primary audio language code is needed self.video.primary_audio_language_code = '' form = self.make_form({ 'primary_audio_language_code': 'en', 'subtitle_language_code': 'fr', }) self.assertEquals(form.is_valid(), True) # handle_post should set the primary_audio_language_code, then # redirect to the editor response = form.handle_post() self.video = test_utils.reload_obj(self.video) self.assertEquals(self.video.primary_audio_language_code, 'en') self.check_redirect(response, 'fr') # try the same thing without primary_audio_language_code being # present. self.video.primary_audio_language_code = '' form = self.make_form({ 'subtitle_language_code': 'fr', }) self.assertEquals(form.is_valid(), False)
def test_set_original(self): response = self.client.put(self.detail_url(self.other_url), {'original': True}) assert_equal(response.status_code, status.HTTP_200_OK, response.content) assert_true(test_utils.reload_obj(self.other_url).original)
def get_serialized_data(self): video_serializer = VideoSerializer(test_utils.reload_obj(self.video), context=self.serializer_context) return video_serializer.data