예제 #1
0
    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)
예제 #2
0
    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), [])