Esempio n. 1
0
    def test_process_books_completes(self):
        """
        Test process_books when it processes all books
        """
        # GIVEN: An instance of OSISBible Importer and two mocked books
        self.mocked_find_and_create_book.side_effect = ['db_book1', 'db_book2']
        with patch.object(OSISBible,
                          'process_chapters') as mocked_process_chapters:
            importer = OSISBible(MagicMock(),
                                 path='.',
                                 name='.',
                                 file_path=None)

            book1 = MagicMock()
            book1.get.return_value = 'Name1'
            book2 = MagicMock()
            book2.get.return_value = 'Name2'
            mocked_data = MagicMock(**{'xpath.return_value': [book1, book2]})
            importer.language_id = 10
            importer.session = MagicMock()
            importer.stop_import_flag = False

            # WHEN: Calling process_books with the two books
            importer.process_books(mocked_data)

            # THEN: find_and_create_book and process_books should be called with the details from the mocked books
            assert self.mocked_find_and_create_book.call_args_list == [
                call('Name1', 2, 10),
                call('Name2', 2, 10)
            ]
            assert mocked_process_chapters.call_args_list == [
                call('db_book1', book1),
                call('db_book2', book2)
            ]
            assert importer.session.commit.call_count == 2
Esempio n. 2
0
    def test_process_books_stop_import(self):
        """
        Test process_books when stop_import is set to True
        """
        # GIVEN: An instance of OSISBible adn some mocked data
        importer = OSISBible(MagicMock(), path='.', name='.', file_path=None)
        mocked_data = MagicMock(**{'xpath.return_value': ['Book']})

        # WHEN: stop_import_flag is set to True and process_books is called
        importer.stop_import_flag = True
        importer.process_books(mocked_data)

        # THEN: find_and_create_book should not have been called
        assert self.mocked_find_and_create_book.called is False