コード例 #1
0
    def test_handle_stream_with_json_and_stream_url(self, console, args):
        stream = Mock()
        streams = dict(best=stream)

        plugin = FakePlugin("")
        plugin._streams = streams

        handle_stream(plugin, streams, "best")
        self.assertEqual(console.msg.mock_calls, [])
        self.assertEqual(console.msg_json.mock_calls, [
            call(stream,
                 metadata=dict(id=u"test-id-1234-5678",
                               author=u"Tѥst Āuƭhǿr",
                               category=None,
                               title=u"Test Title"))
        ])
        self.assertEqual(console.error.mock_calls, [])
        console.msg_json.mock_calls *= 0

        console.json = False
        handle_stream(plugin, streams, "best")
        self.assertEqual(console.msg.mock_calls,
                         [call("{0}", stream.to_url())])
        self.assertEqual(console.msg_json.mock_calls, [])
        self.assertEqual(console.error.mock_calls, [])
        console.msg.mock_calls *= 0

        stream.to_url.side_effect = TypeError()
        handle_stream(plugin, streams, "best")
        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")])
コード例 #2
0
    def test_handle_stream_with_json_and_stream_url(self, console, args):
        stream = Mock()
        streams = dict(best=stream)
        plugin = Mock(FakePlugin(),
                      module="fake",
                      arguments=[],
                      streams=Mock(return_value=streams))

        handle_stream(plugin, streams, "best")
        self.assertEqual(console.msg.mock_calls, [])
        self.assertEqual(console.msg_json.mock_calls, [call(stream)])
        self.assertEqual(console.error.mock_calls, [])
        if is_py3:
            console.msg_json.mock_calls.clear()

            console.json = False
            handle_stream(plugin, streams, "best")
            self.assertEqual(console.msg.mock_calls,
                             [call("{0}", stream.to_url())])
            self.assertEqual(console.msg_json.mock_calls, [])
            self.assertEqual(console.error.mock_calls, [])
            console.msg.mock_calls.clear()

            stream.to_url.side_effect = TypeError()
            handle_stream(plugin, streams, "best")
            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")])