Beispiel #1
0
class RiddimguideSearchEngineIntegrationTest(unittest.TestCase):

    def setUp(self):
        parser_factory = RiddimguideBeautifulSoupParserFactory()
        http_client = RequestsHttpClient(Session())

        self.engine = RiddimguideSearchEngine(parser_factory, http_client)

    def test_search_with_one_result(self):

        tunes = self.engine.search('bob marley exodus')

        tune = {'artist': 'Bob Marley & Wailers',
                'song': 'Exodus',
                'riddim': 'Exodus',
                'year': '1977',
                'label': 'Tuff Gong',
                'producer': 'Robert Nesta \'Bob\' Marley & The Wailers'}
        self.assertEquals(tune, tunes[0])

    def test_search_with_paging(self):

        tunes = self.engine.search('bob marley')

        tune = {'artist': 'Bob Marley & Wailers credited as The Wailers',
                'song': 'Love And Affection',
                'riddim': 'Love And Affection',
                'year': '1965',
                'label': 'Ska Beat',
                'producer': ''}
        self.assertEquals(tune, tunes[-1])
Beispiel #2
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)