Repository: jdepoix/youtube-transcript-api
File: youtube_transcript_api/test/test_cli.py (Python)

Code before:
    def test_argument_parsing__languages(self):
        parsed_args = YouTubeTranscriptCli('v1 v2 --languages de en'.split())._parse_args()
        self.assertEqual(parsed_args.video_ids, ['v1', 'v2'])
        self.assertEqual(parsed_args.json, False)
        self.assertEqual(parsed_args.languages, ['de', 'en'])

    def test_argument_parsing__proxies(self):
        parsed_args = YouTubeTranscriptCli(
            'v1 v2 --http-proxy http://user:pass@domain:port'.split()
        )._parse_args()
        self.assertEqual(parsed_args.http_proxy, 'http://user:pass@domain:port')

        parsed_args = YouTubeTranscriptCli(
            'v1 v2 --https-proxy https://user:pass@domain:port'.split()
        )._parse_args()
        self.assertEqual(parsed_args.https_proxy, 'https://user:pass@domain:port')

    def test_run(self):
        YouTubeTranscriptApi.get_transcripts = MagicMock(return_value=([], []))
        YouTubeTranscriptCli('v1 v2 --languages de en'.split()).run()

        YouTubeTranscriptApi.get_transcripts.assert_called_once_with(
            ['v1', 'v2'],
            languages=['de', 'en'],
            continue_after_error=True,
            proxies={"http": "", "https": ""}
        )

    def test_run__json_output(self):
        YouTubeTranscriptApi.get_transcripts = MagicMock(return_value=([{'boolean': True}], []))
        output = YouTubeTranscriptCli('v1 v2 --languages de en --json'.split()).run()

        # will fail if output is not valid json
        json.loads(output)


Review comment (suggestion):
I guess if no proxy options are set you would want `proxies=None`. Otherwise the `if proxies: ...` calls which happen later on will always be true and therefore `requests.get(..., proxies={...})` will always be called even though no proxy options are set.

Code after:
        self.assertEqual(parsed_args.json, True)
        self.assertEqual(parsed_args.languages, [])

        parsed_args = YouTubeTranscriptCli('--json v1 v2'.split())._parse_args()
        self.assertEqual(parsed_args.video_ids, ['v1', 'v2'])
        self.assertEqual(parsed_args.json, True)
        self.assertEqual(parsed_args.languages, [])

    def test_argument_parsing__languages(self):
        parsed_args = YouTubeTranscriptCli('v1 v2 --languages de en'.split())._parse_args()
        self.assertEqual(parsed_args.video_ids, ['v1', 'v2'])
        self.assertEqual(parsed_args.json, False)
        self.assertEqual(parsed_args.languages, ['de', 'en'])

    def test_argument_parsing__proxies(self):
        parsed_args = YouTubeTranscriptCli(
            'v1 v2 --http-proxy http://user:pass@domain:port'.split()
        )._parse_args()
        self.assertEqual(parsed_args.http_proxy, 'http://user:pass@domain:port')

        parsed_args = YouTubeTranscriptCli(
            'v1 v2 --https-proxy https://user:pass@domain:port'.split()
        )._parse_args()
        self.assertEqual(parsed_args.https_proxy, 'https://user:pass@domain:port')

        parsed_args = YouTubeTranscriptCli(
            'v1 v2 --http-proxy http://user:pass@domain:port --https-proxy https://user:pass@domain:port'.split()
        )._parse_args()
        self.assertEqual(parsed_args.http_proxy, 'http://user:pass@domain:port')
        self.assertEqual(parsed_args.https_proxy, 'https://user:pass@domain:port')

        parsed_args = YouTubeTranscriptCli(
            'v1 v2'.split()
        )._parse_args()
        self.assertEqual(parsed_args.http_proxy, '')
        self.assertEqual(parsed_args.https_proxy, '')

    def test_run(self):
        YouTubeTranscriptApi.get_transcripts = MagicMock(return_value=([], []))
        YouTubeTranscriptCli('v1 v2 --languages de en'.split()).run()

        YouTubeTranscriptApi.get_transcripts.assert_called_once_with(
            ['v1', 'v2'],
            languages=['de', 'en'],
            continue_after_error=True,
            proxies=None
        )

    def test_run__json_output(self):
        YouTubeTranscriptApi.get_transcripts = MagicMock(return_value=([{'boolean': True}], []))
        output = YouTubeTranscriptCli('v1 v2 --languages de en --json'.split()).run()