Exemple #1
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))
Exemple #2
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))
Exemple #3
0
 def test_check_authorization_no_account(self):
     # test check_authorization with no ThirdPartyAccount set up
     self.assertEquals(check_authorization(self.video), (False, False))
Exemple #4
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))
Exemple #5
0
    def add_credit_to_description(self, video):
        """
        Get the entry information from Youtube, extract the original
        description, prepend the description with Amara credits and push it
        back to Youtube.

        If our update call doesn't succeed on the first try, we refresh the
        access token and try again.

        If the existing description starts with the credit text, we just
        return.
        """
        from accountlinker.models import add_amara_description_credit, check_authorization
        from apps.videos.templatetags.videos_tags import shortlink_for_video

        if not should_add_credit(video=video):
            return False

        is_authorized, _ = check_authorization(video)

        if not is_authorized:
            return False

        uri = self.upload_uri_base % self.youtube_video_id

        entry = self.GetVideoEntry(uri=uri)
        entry = entry.to_string()
        entry = gdata.youtube.YouTubeVideoEntryFromString(entry)

        old_description = entry.media.description.text or ''

        if old_description:
            old_description = old_description.decode("utf-8")

        video_url = shortlink_for_video(video)

        language_code = video.language

        if not language_code:
            language_code = 'en'

        new_description = add_amara_description_credit(old_description,
                                                       video_url,
                                                       language_code)

        if new_description == old_description:
            return True

        entry.media.description.text = new_description
        entry = entry.ToString()

        status_code = self._make_update_request(uri, entry)

        if status_code == 401:
            self.refresh()
            status_code = self._make_update_request(uri, entry)

        if status_code == 200:
            Meter('youtube.description_changed').inc()
            return True

        return False