コード例 #1
0
    def test_handle_url_with_json_and_stream_url(self, console, args):
        stream = Mock()
        streams = dict(worst=Mock(), best=stream)
        plugin = Mock(FakePlugin(),
                      module="fake",
                      arguments=[],
                      streams=Mock(return_value=streams))

        with patch("streamlink_cli.main.streamlink",
                   resolve_url=Mock(return_value=plugin)):
            handle_url()
            self.assertEqual(console.msg.mock_calls, [])
            self.assertEqual(console.msg_json.mock_calls,
                             [call(dict(plugin="fake", streams=streams))])
            self.assertEqual(console.error.mock_calls, [])
            if is_py3:
                console.msg_json.mock_calls.clear()

                console.json = False
                handle_url()
                self.assertEqual(console.msg.mock_calls,
                                 [call("{0}", stream.to_manifest_url())])
                self.assertEqual(console.msg_json.mock_calls, [])
                self.assertEqual(console.error.mock_calls, [])
                console.msg_json.mock_calls.clear()
                """ fails
コード例 #2
0
    def test_handle_url_with_json_and_stream_url(self, console, args):
        stream = Mock()
        streams = dict(worst=Mock(), best=stream)

        class _FakePlugin(FakePlugin):
            _streams = streams

        with patch("streamlink_cli.main.streamlink",
                   resolve_url=Mock(return_value=(_FakePlugin, ""))):
            handle_url()
            self.assertEqual(console.msg.mock_calls, [])
            self.assertEqual(console.msg_json.mock_calls, [
                call(plugin="fake",
                     metadata=dict(id=u"test-id-1234-5678",
                                   author=u"Tѥst Āuƭhǿr",
                                   category=None,
                                   title=u"Test Title"),
                     streams=streams)
            ])
            self.assertEqual(console.error.mock_calls, [])
            console.msg_json.mock_calls *= 0

            console.json = False
            handle_url()
            self.assertEqual(console.msg.mock_calls,
                             [call("{0}", stream.to_manifest_url())])
            self.assertEqual(console.msg_json.mock_calls, [])
            self.assertEqual(console.error.mock_calls, [])
            console.msg.mock_calls *= 0

            stream.to_manifest_url.side_effect = TypeError()
            handle_url()
            self.assertEqual(console.msg.mock_calls, [])
            self.assertEqual(console.msg_json.mock_calls, [])
            self.assertEqual(
                console.exit.mock_calls,
                [call("The stream specified cannot be translated to a URL")])
            console.exit.mock_calls *= 0