Exemplo n.º 1
0
 def test_200_ok_logged_in(self):
     logged_in_user = AuthenticatedUserFactory()
     project = ProjectFactory(owner=logged_in_user)
     video = VideoFactory(
         project=project, owner=logged_in_user,
         analyzed_transcript={'sentences': [{
             'sentiment': {
                 'score': -0.8,
                 'magnitude': 3.0
             }
         }, {
             'sentiment': {
                 'score': 0.8,
                 'magnitude': 3.0
             }
         }, {
             'sentiment': {
                 'score': 0.0,
                 'magnitude': 0.0
             }
         }]})
     request = self.rf.get('/project/{}/video/view/{}'.format(
         project.pk, video.pk))
     request.user = logged_in_user
     resp = VideoDetailView.as_view()(
         request, project_pk=project.pk, pk=video.pk)
     self.assertEqual(200, resp.status_code)
Exemplo n.º 2
0
 def test_comment_analysis_complete_property(self):
     video = VideoFactory(sentiment=0, magnitude=0, analyzed_transcript={})
     VideoCommentFactory(video=video, analyzed_comment={'foo': 'foo'})
     comment_2 = VideoCommentFactory(video=video, analyzed_comment={})
     self.assertFalse(video.comment_analysis_complete)
     comment_2.analyzed_comment = {'bar': 'bar'}
     comment_2.save()
     self.assertTrue(video.comment_analysis_complete)
Exemplo n.º 3
0
 def test_analysis_complete_property(self):
     video = VideoFactory(sentiment=0, magnitude=0, analyzed_transcript={})
     self.assertFalse(video.analysis_complete)
     video.sentiment = 0.8
     video.magnitude = 0.8
     video.analyzed_transcript = {'foo': 'bar'}
     video.save()
     self.assertTrue(video.analysis_complete)
Exemplo n.º 4
0
 def test_200_ok_logged_in(self):
     logged_in_user = AuthenticatedUserFactory()
     project = ProjectFactory(owner=logged_in_user)
     video = VideoFactory(project=project, owner=logged_in_user)
     request = self.rf.get(
         '/project/{}/video/{}/analysis/comments/'.format(
             project.pk, video.pk))
     request.user = logged_in_user
     resp = VideoCommentListView.as_view()(
         request, project_pk=project.pk, pk=video.pk)
     self.assertEqual(200, resp.status_code)
Exemplo n.º 5
0
 def test_404_logged_in_permission_denied(self):
     # users cant see the details of a project they dont own
     project = ProjectFactory()
     video = VideoFactory(project=project)
     logged_in_user = AuthenticatedUserFactory()
     request = self.rf.get(
         '/project/{}/video/view/{}'.format(project.pk, video.pk))
     request.user = logged_in_user
     with self.assertRaises(Http404):
         VideoDetailView.as_view()(
             request, project_pk=project.pk, pk=video.pk)
Exemplo n.º 6
0
 def test_302_not_logged_in(self):
     project = ProjectFactory()
     video = VideoFactory(project=project)
     request = self.rf.get(
         '/project/{}/video/view/{}'.format(project.pk, video.pk))
     request.user = AnonymousUser()
     resp = VideoDetailView.as_view()(
         request, project_pk=project.pk, pk=video.pk)
     self.assertEqual(resp.status_code, 302)
     self.assertEqual(
         resp._headers['location'][1],
         '/accounts/login/?next=/project/{}/video/view/{}'.format(
             project.pk, video.pk))
Exemplo n.º 7
0
 def test_post_save_created(self):
     with mock.patch('google.appengine.ext.deferred.defer') as mock_defer:
         video = VideoFactory()
         self.assertTrue(mock_defer.called)
         self.assertEqual(2, mock_defer.call_count)
         self.assertEqual(
             mock_defer.call_args_list,
             [
                 mock.call(tasks.youtube_import_comments,
                           video.pk,
                           _queue='comments'),
                 mock.call(tasks.youtube_import_transcript,
                           video.pk,
                           _queue='videos')
             ],
         )
Exemplo n.º 8
0
 def test_post_200_logged_in(self):
     mock_search_resp = [{
         u'snippet': {
             u'categoryId': u'25',
             u'channelId': u'channel1234',
             u'channelTitle': u'channel Title',
             u'description': u'video 1234 description',
             u'liveBroadcastContent': u'none',
             u'localized': {
                 u'description': u'description',
                 u'title': u'Video 1234'
             },
             u'publishedAt': u'2018-01-01T00:00:00.000Z',
             u'tags': [
                 u'tag1',
                 u'tag2',
             ],
             u'thumbnails': {
                 u'default': {
                     u'height': 90,
                     u'url': u'http://example.com/default.jpg',
                     u'width': 120
                 },
                 u'high': {
                     u'height': 360,
                     u'url': u'hhttp://example.com/high.jpg',
                     u'width': 480
                 },
                 u'maxres': {
                     u'height': 720,
                     u'url': u'http://example.com/maxres.jpg',
                     u'width': 1280
                 },
                 u'medium': {
                     u'height': 180,
                     u'url': u'http://example.com/medium.jpg',
                     u'width': 320
                 },
                 u'standard': {
                     u'height': 480,
                     u'url': u'http://example.com/standard.jpg',
                     u'width': 640
                 }
             },
             u'title': u'Video 1234'
         },
         u'statistics': {
             u'commentCount': u'9999',
             u'viewCount': u'9999',
             u'favoriteCount': u'9999',
             u'dislikeCount': u'9999',
             u'likeCount': u'9999'
         },
         u'kind': u'youtube#video',
         u'etag': u'"etag/123456789"',
         u'id': u'video1234'
     }, {
         u'snippet': {
             u'categoryId': u'25',
             u'channelId': u'channel5678',
             u'channelTitle': u'channel Title',
             u'description': u'video 5678 description',
             u'liveBroadcastContent': u'none',
             u'localized': {
                 u'description': u'description',
                 u'title': u'Video 5678'
             },
             u'publishedAt': u'2018-01-01T00:00:00.000Z',
             u'tags': [
                 u'tag1',
                 u'tag2',
             ],
             u'thumbnails': {
                 u'default': {
                     u'height': 90,
                     u'url': u'http://example.com/default.jpg',
                     u'width': 120
                 },
                 u'high': {
                     u'height': 360,
                     u'url': u'hhttp://example.com/high.jpg',
                     u'width': 480
                 },
                 u'maxres': {
                     u'height': 720,
                     u'url': u'http://example.com/maxres.jpg',
                     u'width': 1280
                 },
                 u'medium': {
                     u'height': 180,
                     u'url': u'http://example.com/medium.jpg',
                     u'width': 320
                 },
                 u'standard': {
                     u'height': 480,
                     u'url': u'http://example.com/standard.jpg',
                     u'width': 640
                 }
             },
             u'title': u'Video 5678'
         },
         u'statistics': {
             u'commentCount': u'9999',
             u'viewCount': u'9999',
             u'favoriteCount': u'9999',
             u'dislikeCount': u'9999',
             u'likeCount': u'9999'
         },
         u'kind': u'youtube#video',
         u'etag': u'"etag/123456789"',
         u'id': u'video5678'
     }]
     logged_in_user = AuthenticatedUserFactory()
     project = ProjectFactory(owner=logged_in_user)
     existing_video = VideoFactory(project=project, youtube_id='video5678')
     request = self.rf.post(
         '/project/{}/video/search'.format(project.pk),
         {'keywords': 'kittens'})
     request.user = logged_in_user
     service = mock.Mock()
     service.search.return_value = mock_search_resp
     with mock.patch('dashboard.views.youtube.Client') as mock_yt:
         mock_yt.return_value = service
         resp = VideoSearchView.as_view()(request, pk=project.pk)
         self.assertEqual(200, resp.status_code)
         self.assertEqual(1, len(resp.context_data['formset'].forms))
         self.assertEqual(
             'video1234',
             resp.context_data['formset'].forms[0].initial['youtube_id'])
         self.assertNotEqual(
             existing_video.youtube_id,
             resp.context_data['formset'].forms[0].initial['youtube_id'])
Exemplo n.º 9
0
 def test_unicode_method(self):
     video = VideoFactory.create(name=u'象は鼻が長')
     self.assertEqual(video.__unicode__(), u'象は鼻が長')
Exemplo n.º 10
0
 def test_unicode_method(self):
     video = VideoFactory()
     comment = VideoCommentFactory.create(video=video, comment_raw=u'象は鼻が長')
     self.assertEqual(comment.__unicode__(),
                      u'Video: {} Comment: 象は鼻が長'.format(video.pk))
Exemplo n.º 11
0
 def test_can_be_analyze_property(self):
     video = VideoFactory(transcript='')
     self.assertFalse(video.can_be_analyzed)
     video.transcript = 'foo'
     video.save()
     self.assertTrue(video.can_be_analyzed)
Exemplo n.º 12
0
 def test_post_save_existing(self):
     video = VideoFactory()
     with mock.patch('google.appengine.ext.deferred.defer') as mock_defer:
         video.save()
         self.assertFalse(mock_defer.called)
         self.assertEqual(0, mock_defer.call_count)