Ejemplo n.º 1
0
    def test_no_key(self, mock_requests, mock_api_keys):
        from plugins import youtube

        bot.config.get_api_key.return_value = None

        with pytest.raises(youtube.NoApiKeyError):
            youtube.get_video_description("foobar")
Ejemplo n.º 2
0
    def test_http_error(self, mock_requests, mock_api_keys):
        from plugins import youtube

        mock_requests.add(
            'GET',
            self.api_url.format(id='foobar', key='APIKEY'),
            match_querystring=True,
            json={'error': {'code': 500}},
            status=500,
        )

        with pytest.raises(youtube.APIError, match="Unknown error"):
            youtube.get_video_description('foobar')
Ejemplo n.º 3
0
    def test_no_key(self, mock_requests, mock_api_keys):
        from plugins import youtube

        mock_requests.add(
            'GET',
            self.api_url.format(id='foobar', key='APIKEY'),
            match_querystring=True,
            json={'error': {'code': 403}},
            status=403,
        )

        with pytest.raises(youtube.APIError, match="YouTube API is off"):
            youtube.get_video_description('foobar')
Ejemplo n.º 4
0
    def test_no_results(self, mock_requests, mock_api_keys):
        from plugins import youtube

        data = deepcopy(video_data)
        del data["items"][0]

        mock_requests.add(
            "GET",
            self.api_url.format(id="phL7P6gtZRM", key="APIKEY"),
            match_querystring=True,
            json=data,
        )

        with pytest.raises(youtube.NoResultsError):
            youtube.get_video_description("phL7P6gtZRM")
Ejemplo n.º 5
0
    def test_http_error(self, mock_requests, mock_api_keys):
        from plugins import youtube

        mock_requests.add(
            "GET",
            self.api_url.format(id="foobar", key="APIKEY"),
            match_querystring=True,
            json={
                "error": {
                    "code": 500,
                    "errors": [{"domain": "foo", "reason": "bar"}],
                },
            },
            status=500,
        )

        with pytest.raises(youtube.APIError, match=r"API Error \(foo/bar\)"):
            youtube.get_video_description("foobar")
Ejemplo n.º 6
0
    def test_no_results(self, mock_requests, mock_api_keys):
        from plugins import youtube

        data = deepcopy(video_data)
        del data['items'][0]

        mock_requests.add(
            'GET',
            self.api_url.format(id='phL7P6gtZRM', key='APIKEY'),
            match_querystring=True,
            json=data,
        )

        assert youtube.get_video_description('phL7P6gtZRM') is None
Ejemplo n.º 7
0
    def test_success_no_duration(self, mock_requests, mock_api_keys):
        from plugins import youtube

        data = deepcopy(video_data)
        del data['items'][0]['contentDetails']['duration']

        mock_requests.add(
            'GET',
            self.api_url.format(id='phL7P6gtZRM', key='APIKEY'),
            match_querystring=True,
            json=data,
        )

        result = '\x02some title\x02'

        assert youtube.get_video_description('phL7P6gtZRM') == result
Ejemplo n.º 8
0
    def test_success(self, mock_requests, mock_api_keys):
        from plugins import youtube

        mock_requests.add(
            'GET',
            self.api_url.format(id='phL7P6gtZRM', key='APIKEY'),
            match_querystring=True,
            json=video_data,
        )

        result = (
            '\x02some title\x02 - length \x0217m 2s\x02 - '
            '4,633 likes, 31 dislikes (\x0299.3\x02%) - '
            '\x0268,905\x02 views - \x02a channel\x02 on \x022019.10.10\x02')

        assert youtube.get_video_description('phL7P6gtZRM') == result
Ejemplo n.º 9
0
    def test_success_no_duration(self, mock_requests, mock_api_keys):
        from plugins import youtube

        data = deepcopy(video_data)
        del data["items"][0]["contentDetails"]["duration"]

        mock_requests.add(
            "GET",
            self.api_url.format(id="phL7P6gtZRM", key="APIKEY"),
            match_querystring=True,
            json=data,
        )

        result = "\x02some title\x02"

        assert youtube.get_video_description("phL7P6gtZRM") == result
Ejemplo n.º 10
0
    def test_success_no_likes(self, mock_requests, mock_api_keys):
        from plugins import youtube

        data = deepcopy(video_data)
        del data['items'][0]['statistics']['likeCount']

        mock_requests.add(
            'GET',
            self.api_url.format(id='phL7P6gtZRM', key='APIKEY'),
            match_querystring=True,
            json=data,
        )

        result = (
            '\x02some title\x02 - length \x0217m 2s\x02 - \x0268,905\x02 views - '
            '\x02a channel\x02 on \x022019.10.10\x02')

        assert youtube.get_video_description('phL7P6gtZRM') == result
Ejemplo n.º 11
0
    def test_success_no_likes(self, mock_requests, mock_api_keys):
        from plugins import youtube

        data = deepcopy(video_data)
        del data["items"][0]["statistics"]["likeCount"]

        mock_requests.add(
            "GET",
            self.api_url.format(id="phL7P6gtZRM", key="APIKEY"),
            match_querystring=True,
            json=data,
        )

        result = (
            "\x02some title\x02 - length \x0217m 2s\x02 - \x0268,905\x02 views - "
            "\x02a channel\x02 on \x022019.10.10\x02")

        assert youtube.get_video_description("phL7P6gtZRM") == result
Ejemplo n.º 12
0
    def test_success_nsfw(self, mock_requests, mock_api_keys):
        from plugins import youtube

        data = deepcopy(video_data)
        data['items'][0]['contentDetails']['contentRating'] = "18+"

        mock_requests.add(
            'GET',
            self.api_url.format(id='phL7P6gtZRM', key='APIKEY'),
            match_querystring=True,
            json=data,
        )

        result = (
            '\x02some title\x02 - length \x0217m 2s\x02 - '
            '4,633 likes, 31 dislikes (\x0299.3\x02%) - '
            '\x0268,905\x02 views - \x02a channel\x02 on \x022019.10.10\x02 - '
            '\x034NSFW\x02')

        assert youtube.get_video_description('phL7P6gtZRM') == result
Ejemplo n.º 13
0
    def test_success_nsfw(self, mock_requests, mock_api_keys):
        from plugins import youtube

        data = deepcopy(video_data)
        data["items"][0]["contentDetails"]["contentRating"] = {
            "ytRating": "ytAgeRestricted"
        }

        mock_requests.add(
            "GET",
            self.api_url.format(id="phL7P6gtZRM", key="APIKEY"),
            match_querystring=True,
            json=data,
        )

        result = (
            "\x02some title\x02 - length \x0217m 2s\x02 - "
            "4,633 likes, 31 dislikes (\x0299.3\x02%) - "
            "\x0268,905\x02 views - \x02a channel\x02 on \x022019.10.10\x02 - "
            "\x0304NSFW\x0f")

        assert youtube.get_video_description("phL7P6gtZRM") == result