Ejemplo n.º 1
0
    def test_start_over_1000_songs(self, mocked_translate):
        """
        Test the start() method of the SearchWorker class when it finds over 1000 songs
        """
        # GIVEN: An importer mock object, some search text and an initialised SearchWorker
        mocked_translate.side_effect = lambda x, y: y
        importer = MagicMock()
        importer.search.return_value = ['song%s' % num for num in range(1050)]
        search_text = 'Jesus'
        worker = SearchWorker(importer, search_text)

        # WHEN: The start() method is called
        with patch.object(worker, 'finished') as mocked_finished, patch.object(worker, 'quit') as mocked_quit, \
                patch.object(worker, 'show_info') as mocked_show_info:
            worker.start()

        # THEN: The "finished" and "quit" signals should be emitted
        importer.search.assert_called_with(search_text, 1000,
                                           worker._found_song_callback)
        mocked_show_info.emit.assert_called_with(
            'More than 1000 results',
            'Your search has returned more than 1000 '
            'results, it has been stopped. Please '
            'refine your search to fetch better '
            'results.')
        mocked_finished.emit.assert_called_with()
        mocked_quit.emit.assert_called_with()
Ejemplo n.º 2
0
    def test_found_song_callback(self):
        """
        Test that when the _found_song_callback() function is called, the "found_song" signal is emitted
        """
        # GIVEN: An importer mock object, some search text and an initialised SearchWorker
        importer = MagicMock()
        search_text = 'Jesus'
        song = {'title': 'Amazing Grace'}
        worker = SearchWorker(importer, search_text)

        # WHEN: The start() method is called
        with patch.object(worker, 'found_song') as mocked_found_song:
            worker._found_song_callback(song)  # pylint: disable=protected-access

        # THEN: The "found_song" signal should have been emitted
        mocked_found_song.emit.assert_called_with(song)
Ejemplo n.º 3
0
    def test_found_song_callback(self):
        """
        Test that when the _found_song_callback() function is called, the "found_song" signal is emitted
        """
        # GIVEN: An importer mock object, some search text and an initialised SearchWorker
        importer = MagicMock()
        search_text = 'Jesus'
        song = {'title': 'Amazing Grace'}
        worker = SearchWorker(importer, search_text)

        # WHEN: The start() method is called
        with patch.object(worker, 'found_song') as mocked_found_song:
            worker._found_song_callback(song)                                   # pylint: disable=protected-access

        # THEN: The "found_song" signal should have been emitted
        mocked_found_song.emit.assert_called_with(song)
Ejemplo n.º 4
0
    def test_start(self):
        """
        Test the start() method of the SearchWorker class
        """
        # GIVEN: An importer mock object, some search text and an initialised SearchWorker
        importer = MagicMock()
        importer.search.return_value = ['song1', 'song2']
        search_text = 'Jesus'
        worker = SearchWorker(importer, search_text)

        # WHEN: The start() method is called
        with patch.object(worker, 'finished') as mocked_finished, patch.object(worker, 'quit') as mocked_quit:
            worker.start()

        # THEN: The "finished" and "quit" signals should be emitted
        importer.search.assert_called_with(search_text, 1000, worker._found_song_callback)
        mocked_finished.emit.assert_called_with()
        mocked_quit.emit.assert_called_with()
Ejemplo n.º 5
0
    def test_start(self):
        """
        Test the start() method of the SearchWorker class
        """
        # GIVEN: An importer mock object, some search text and an initialised SearchWorker
        importer = MagicMock()
        importer.search.return_value = ['song1', 'song2']
        search_text = 'Jesus'
        worker = SearchWorker(importer, search_text)

        # WHEN: The start() method is called
        with patch.object(worker, 'finished') as mocked_finished, patch.object(worker, 'quit') as mocked_quit:
            worker.start()

        # THEN: The "finished" and "quit" signals should be emitted
        importer.search.assert_called_with(search_text, 1000, worker._found_song_callback)
        mocked_finished.emit.assert_called_with()
        mocked_quit.emit.assert_called_with()
Ejemplo n.º 6
0
    def test_constructor(self):
        """
        Test the SearchWorker constructor
        """
        # GIVEN: An importer mock object and some search text
        importer = MagicMock()
        search_text = 'Jesus'

        # WHEN: The search worker is created
        worker = SearchWorker(importer, search_text)

        # THEN: The correct values should be set
        assert importer is worker.importer, 'The importer should be the right object'
        assert search_text == worker.search_text, 'The search text should be correct'
Ejemplo n.º 7
0
    def test_start_over_1000_songs(self, mocked_translate):
        """
        Test the start() method of the SearchWorker class when it finds over 1000 songs
        """
        # GIVEN: An importer mock object, some search text and an initialised SearchWorker
        mocked_translate.side_effect = lambda x, y: y
        importer = MagicMock()
        importer.search.return_value = ['song%s' % num for num in range(1050)]
        search_text = 'Jesus'
        worker = SearchWorker(importer, search_text)

        # WHEN: The start() method is called
        with patch.object(worker, 'finished') as mocked_finished, patch.object(worker, 'quit') as mocked_quit, \
                patch.object(worker, 'show_info') as mocked_show_info:
            worker.start()

        # THEN: The "finished" and "quit" signals should be emitted
        importer.search.assert_called_with(search_text, 1000, worker._found_song_callback)
        mocked_show_info.emit.assert_called_with('More than 1000 results', 'Your search has returned more than 1000 '
                                                                           'results, it has been stopped. Please '
                                                                           'refine your search to fetch better '
                                                                           'results.')
        mocked_finished.emit.assert_called_with()
        mocked_quit.emit.assert_called_with()