Example #1
0
    def test_search(self):
        parser_1 = Mock()
        parser_1.next.return_value = "next_url"
        parser_1.tunes.return_value = [{"one": 1}, {"two": 2}]

        parser_2 = Mock()
        parser_2.next.return_value = False
        parser_2.tunes.return_value = [{"three": 3}, {"four": 4}]

        parser_factory = Mock()
        parser_factory_returns = [parser_1, parser_2]

        def parser_factory_mock(*args):
            return parser_factory_returns.pop(0)

        parser_factory.from_html = Mock(side_effect=parser_factory_mock)

        http_client = Mock()
        http_client_returns = ["page 1", "page 2"]

        def http_client_mock(*args):
            return http_client_returns.pop(0)

        http_client.get = Mock(side_effect=http_client_mock)

        engine = RiddimguideSearchEngine(parser_factory, http_client)

        tunes = engine.search("query")

        expected_calls = [call("http://www.riddimguide.com/tunes?q=query"), call("http://www.riddimguide.com/next_url")]
        self.assertEquals(expected_calls, http_client.get.call_args_list)

        expected_calls = [call("page 1"), call("page 2")]
        self.assertEquals(expected_calls, parser_factory.from_html.call_args_list)

        expected_tunes = [{"one": 1}, {"two": 2}, {"three": 3}, {"four": 4}]
        self.assertEquals(expected_tunes, tunes)
Example #2
0
    def test_apply(self):
        self.humanize_operation.apply(self.song)

        expected_setitem_calls = [call('title', 'One Love'),
                                  call('artist', 'Bob Marley'),
                                  call('album', 'Exodus')]
        actual_setitem_calls = self.song.__setitem__.call_args_list

        for expected_call in expected_setitem_calls:
            self.assertTrue(expected_call in actual_setitem_calls)

        expected_contains_calls = [call('title'), call('artist'),
                                   call('album')]
        actual_contains_calls = self.song.__contains__.call_args_list

        for expected_call in expected_contains_calls:
            self.assertTrue(expected_call in actual_contains_calls)