Example #1
0
 def test_check_authorization_individual(self):
     # test check_authorization when linked to a user
     tpa = test_factories.create_third_party_account(self.vurl)
     tpa.users.add(test_factories.create_user())
     # FIXME: should this return True if the user for the ThirdPartyAccount
     # doesn't match the user of the video?
     self.assertEquals(check_authorization(self.video), (True, True))
Example #2
0
    def test_check_authorization_team(self):
        # test check_authorization when linked to a team
        team = test_factories.create_team()
        tpa = test_factories.create_third_party_account(self.vurl)
        tpa.teams.add(team)

        self.assertEquals(check_authorization(self.video), (False, False))
        test_factories.create_team_video(team, video=self.video)
        self.assertEquals(check_authorization(self.video), (True, True))
Example #3
0
    def test_retrieval(self):
        tpa = test_factories.create_third_party_account(self.vurl)
        tpa.users.add(test_factories.create_user())

        with self.assertRaises(ImproperlyConfigured):
            ThirdPartyAccount.objects.always_push_account()

        setattr(settings, 'YOUTUBE_ALWAYS_PUSH_USERNAME', tpa.username)
        self.assertEquals(ThirdPartyAccount.objects.always_push_account(), tpa)
Example #4
0
    def test_resolve_ownership(self):
        tpa = test_factories.create_third_party_account(self.vurl)

        # test with a video that should be linked to an account
        owner = ThirdPartyAccount.objects.resolve_ownership(self.vurl)
        self.assertEquals(owner, tpa)

        # test with a video that shouldn't be linked to an account
        video, _ = Video.get_or_create_for_url(
            'http://www.youtube.com/watch?v=pQ9qX8lcaBQ')
        video_url = video.get_primary_videourl_obj()
        owner = ThirdPartyAccount.objects.resolve_ownership(video_url)
        self.assertEquals(owner, None)
Example #5
0
    def test_mirror_on_third_party(self):
        tpa = test_factories.create_third_party_account(self.vurl)
        tpa.users.add(test_factories.create_user())
        self.make_language_complete()
        lang = self.video.subtitle_language()

        version = self.video.subtitle_language().get_tip()

        youtube_type_mock = mock.Mock(spec=YoutubeVideoType)
        spec = 'videos.types.video_type_registrar.video_type_for_url'
        with mock.patch(spec) as video_type_for_url_mock:
            video_type_for_url_mock.return_value = youtube_type_mock
            ThirdPartyAccount.objects.mirror_on_third_party(
                self.video, 'en', UPDATE_VERSION_ACTION, version)

        youtube_type_mock.update_subtitles.assert_called_once_with(
            version, tpa)
Example #6
0
    def test_resolve_ownership_with_bad_username(self):
        # for some reason, some of our VideoURL objects have the full name in
        # onwer_username instead of the username.  In that case, we should
        # re-fetch the video type, use that username, and update the
        # owner_username field

        # create 2 accounts with the same full name
        account = test_factories.create_third_party_account(
            self.vurl, full_name='Amara Test')
        other_account = ThirdPartyAccount.objects.create(
            type=self.vurl.type,
            username='******',
            full_name='Amara Test',
            oauth_access_token='123',
            oauth_refresh_token='')
        # force the vurl to have the full name in owner_username
        self.vurl.owner_username = '******'
        self.vurl.save()
        # try calling resolve_ownership.
        self.assertEquals(
            ThirdPartyAccount.objects.resolve_ownership(self.vurl), account)
        # resolve_ownership should also fix the owner_username
        self.assertEquals(self.vurl.owner_username, 'amaratestuser')
Example #7
0
 def test_check_authorization_not_linked(self):
     # test check_authorization when not linked to a user or team
     test_factories.create_third_party_account(self.vurl)
     self.assertEquals(check_authorization(self.video), (False, False))