def check_data(self, activity_data, record): assert_equal(activity_data['type'], record.type) assert_equal(activity_data['date'], format_datetime_field(record.created)) if record.video: assert_equal(activity_data['video'], record.video.video_id) assert_equal( activity_data['video_uri'], reverse('api:video-detail', kwargs={ 'video_id': record.video.video_id, }, request=APIRequestFactory().get('/'))) else: assert_equal(activity_data['video'], None) assert_equal(activity_data['video_uri'], None) if record.language_code: assert_equal(activity_data['language'], record.language_code) assert_equal( activity_data['language_uri'], reverse('api:subtitle-language-detail', kwargs={ 'video_id': record.video.video_id, 'language_code': record.language_code, }, request=APIRequestFactory().get('/'))) else: assert_equal(activity_data['language'], None) assert_equal(activity_data['language_uri'], None) assert_equal(activity_data['user'], user_field_data(record.user))
def check_response_data(self, response, sub_format): subtitle_data = babelsubs.to(self.version.get_subtitles(), sub_format) if sub_format == 'json': subtitle_data = json.loads(subtitle_data) assert_equal(response.data['version_number'], self.version.version_number) assert_equal(response.data['sub_format'], sub_format) assert_equal(response.data['subtitles'], subtitle_data) assert_equal(response.data['author'], user_field_data(self.version.author)) assert_equal( response.data['language'], { 'code': self.version.language_code, 'name': self.version.get_language_code_display(), 'dir': 'ltr', }) assert_equal(response.data['title'], self.version.title) assert_equal(response.data['description'], self.version.description) assert_equal(response.data['metadata'], {}) assert_equal(response.data['video_title'], self.video.title_display()) assert_equal(response.data['video_description'], self.video.description) assert_equal( response.data['actions_uri'], reverse('api:subtitle-actions', kwargs={ 'video_id': self.video.video_id, 'language_code': self.version.language_code, }, request=APIRequestFactory().get('/'))) assert_equal( response.data['notes_uri'], reverse('api:subtitle-notes', kwargs={ 'video_id': self.video.video_id, 'language_code': self.version.language_code, }, request=APIRequestFactory().get('/'))) assert_equal( response.data['resource_uri'], reverse('api:subtitles', kwargs={ 'video_id': self.video.video_id, 'language_code': self.version.language_code, }, request=APIRequestFactory().get('/'))) assert_equal( response.data['site_uri'], reverse('videos:subtitleversion_detail', kwargs={ 'video_id': self.video.video_id, 'lang': self.version.language_code, 'lang_id': self.version.subtitle_language_id, 'version_id': self.version.id, }, request=APIRequestFactory().get('/')))
def test_versions_field(self): user1 = UserFactory(username='******') user2 = UserFactory(username='******') self.make_version('en', visibility='public', author=user1) self.make_version('en', visibility='private', author=user2) serializer_data = self.get_serializer_data() assert_equal(serializer_data['num_versions'], 2) assert_equal(serializer_data['versions'], [ { 'author': user_field_data(user2), 'published': False, 'version_no': 2, }, { 'author': user_field_data(user1), 'published': True, 'version_no': 1, }, ])
def test_hiding_private_versions(self): # Test show_private_versions being False self.show_private_versions.return_value = False self.make_version('en', visibility='private', author=self.user) self.make_version('en', visibility='public', author=self.user) serializer_data = self.get_serializer_data() assert_equal(serializer_data['num_versions'], 1) assert_equal(serializer_data['versions'], [ { 'author': user_field_data(self.user), 'published': True, 'version_no': 2, }, ]) # check the arguments passed to show_private_versions assert_equal(self.show_private_versions.call_args, mock.call('en'))
def test_list(self): note = SubtitleNote.objects.create(user=self.user, video=self.video, language_code='en', body='test note') # also create a note from another language. This one shouldn't be # included in the reply SubtitleNote.objects.create(user=self.user, video=self.video, language_code='fr', body='wrong test note') response = self.client.get(self.api_path) assert_equal(response.status_code, 200) data = json.loads(response.content) assert_equal(data['objects'], [{ 'user': user_field_data(self.user), 'body': 'test note', 'created': format_datetime_field(note.created), }])
def test_output(self): assert_equal(self.field.to_representation(self.user), user_field_data(self.user))