コード例 #1
0
ファイル: search_test.py プロジェクト: dstenb/pylaunchr-mpd
class TestMpdSearchStore(unittest.TestCase):

    def setUp(self):
        self.sender = MagicMock(spec=MpdCommandSender)

        self.search = MpdSearchStore(self.sender)

        self.observer = MagicMock(spec=SearchStoreListener)
        self.search.add_listener(self.observer)

    def tearDown(self):
        pass

    def test_search_ok(self):
        args = ["artist", "test"]

        self.search.begin_search(args)

        sender_calls = [call.send("search", args, self.search._on_load)]
        self.assertListEqual(self.sender.mock_calls, sender_calls)

        observer_calls = [call.search_started(self.search)]
        self.assertListEqual(self.observer.mock_calls, observer_calls)
        self.observer.reset_mock()

        result = CallbackResult(CALLBACK_OK, "search", args, SEARCH_RESULTS)
        self.search._on_load(result)

        observer_calls = [call.store_changed(self.search),
                          call.search_finished(self.search)]
        self.assertListEqual(self.observer.mock_calls, observer_calls)

        expected = [Song(item) for item in SEARCH_RESULTS]
        self.assertListEqual(list(self.search), expected)

    def test_search_failed(self):
        args = ["artist", "test"]

        self.search.begin_search(args)

        sender_calls = [call.send("search", args, self.search._on_load)]
        self.assertListEqual(self.sender.mock_calls, sender_calls)

        observer_calls = [call.search_started(self.search)]
        self.assertListEqual(self.observer.mock_calls, observer_calls)
        self.observer.reset_mock()

        result = CallbackResult(CALLBACK_ERR_NOT_CONNECTED, "search", args,
                error=None)
        self.search._on_load(result)

        observer_calls = [call.store_changed(self.search),
                          call.search_cleared(self.search),
                          call.search_failed(self.search)]
        self.assertListEqual(self.observer.mock_calls, observer_calls)

        self.assertListEqual(list(self.search), [])
コード例 #2
0
ファイル: search_test.py プロジェクト: dstenb/pylaunchr-mpd
    def setUp(self):
        self.sender = MagicMock(spec=MpdCommandSender)

        self.search = MpdSearchStore(self.sender)

        self.observer = MagicMock(spec=SearchStoreListener)
        self.search.add_listener(self.observer)