def test_get_memo_field(self, MockSongImport): """ Test the :mod:`db_get_field` module """ for test_results in GET_MEMO_FIELD_TEST_RESULTS: # GIVEN: A mocked out SongImport class, a mocked out "manager", a mocked out memo_file and an encoding mocked_manager = MagicMock() mocked_memo_file = MagicMock() importer = EasyWorshipSongImport(mocked_manager, file_paths=[]) importer.memo_file = mocked_memo_file importer.encoding = TEST_DATA_ENCODING # WHEN: Supplied with test fields and test field descriptions importer.fields = TEST_FIELDS importer.field_descriptions = TEST_FIELD_DESCS field_index = test_results[0] mocked_memo_file.read.return_value = test_results[1] get_field_result = test_results[2]['return'] get_field_read_calls = test_results[2]['read'] get_field_seek_calls = test_results[2]['seek'] # THEN: db_get_field should return the appropriate value with the appropriate mocked objects being # called assert importer.db_get_field(field_index) == get_field_result for call in get_field_read_calls: mocked_memo_file.read.assert_any_call(call) for call in get_field_seek_calls: if isinstance(call, int): mocked_memo_file.seek.assert_any_call(call) else: mocked_memo_file.seek.assert_any_call(call[0], call[1])
def test_get_memo_field(self): """ Test the :mod:`get_field` module """ for test_results in GET_MEMO_FIELD_TEST_RESULTS: # GIVEN: A mocked out SongImport class, a mocked out "manager", a mocked out memo_file and an encoding with patch('openlp.plugins.songs.lib.importers.easyworship.SongImport'): mocked_manager = MagicMock() mocked_memo_file = MagicMock() importer = EasyWorshipSongImport(mocked_manager, filenames=[]) importer.memo_file = mocked_memo_file importer.encoding = TEST_DATA_ENCODING # WHEN: Supplied with test fields and test field descriptions importer.fields = TEST_FIELDS importer.field_descriptions = TEST_FIELD_DESCS field_index = test_results[0] mocked_memo_file.read.return_value = test_results[1] get_field_result = test_results[2]['return'] get_field_read_calls = test_results[2]['read'] get_field_seek_calls = test_results[2]['seek'] # THEN: get_field should return the appropriate value with the appropriate mocked objects being called self.assertEqual(importer.get_field(field_index), get_field_result) for call in get_field_read_calls: mocked_memo_file.read.assert_any_call(call) for call in get_field_seek_calls: if isinstance(call, int): mocked_memo_file.seek.assert_any_call(call) else: mocked_memo_file.seek.assert_any_call(call[0], call[1])
def get_memo_field_test(self): """ Test the :mod:`get_field` module """ for test_results in GET_MEMO_FIELD_TEST_RESULTS: # GIVEN: A mocked out SongImport class, a mocked out "manager", a mocked out memo_file and an encoding with patch('openlp.plugins.songs.lib.importers.easyworship.SongImport'): mocked_manager = MagicMock() mocked_memo_file = MagicMock() importer = EasyWorshipSongImport(mocked_manager, filenames=[]) importer.memo_file = mocked_memo_file importer.encoding = TEST_DATA_ENCODING # WHEN: Supplied with test fields and test field descriptions importer.fields = TEST_FIELDS importer.field_descriptions = TEST_FIELD_DESCS field_index = test_results[0] mocked_memo_file.read.return_value = test_results[1] get_field_result = test_results[2]['return'] get_field_read_calls = test_results[2]['read'] get_field_seek_calls = test_results[2]['seek'] # THEN: get_field should return the appropriate value with the appropriate mocked objects being called self.assertEqual(importer.get_field(field_index), get_field_result) for call in get_field_read_calls: mocked_memo_file.read.assert_any_call(call) for call in get_field_seek_calls: if isinstance(call, int): mocked_memo_file.seek.assert_any_call(call) else: mocked_memo_file.seek.assert_any_call(call[0], call[1])
def test_get_field(self, MockSongImport): """ Test the :mod:`db_get_field` module """ # GIVEN: A mocked out SongImport class, a mocked out "manager", an encoding and some test data and known results mocked_manager = MagicMock() importer = EasyWorshipSongImport(mocked_manager, file_paths=[]) importer.encoding = TEST_DATA_ENCODING importer.fields = TEST_FIELDS importer.field_descriptions = TEST_FIELD_DESCS field_results = [(0, b'A Heart Like Thine'), (1, 100), (2, 102), (3, True), (6, None), (7, None)] # WHEN: Called with test data for field_index, result in field_results: return_value = importer.db_get_field(field_index) # THEN: db_get_field should return the known results assert return_value == result, 'db_get_field should return "%s" when called with "%s"' % \ (result, TEST_FIELDS[field_index])
def test_get_field(self): """ Test the :mod:`get_field` module """ # GIVEN: A mocked out SongImport class, a mocked out "manager", an encoding and some test data and known results with patch('openlp.plugins.songs.lib.importers.easyworship.SongImport'): mocked_manager = MagicMock() importer = EasyWorshipSongImport(mocked_manager, filenames=[]) importer.encoding = TEST_DATA_ENCODING importer.fields = TEST_FIELDS importer.field_descriptions = TEST_FIELD_DESCS field_results = [(0, b'A Heart Like Thine'), (1, 100), (2, 102), (3, True), (6, None), (7, None)] # WHEN: Called with test data for field_index, result in field_results: return_value = importer.get_field(field_index) # THEN: get_field should return the known results self.assertEqual(return_value, result, 'get_field should return "%s" when called with "%s"' % (result, TEST_FIELDS[field_index]))
def get_field_test(self): """ Test the :mod:`get_field` module """ # GIVEN: A mocked out SongImport class, a mocked out "manager", an encoding and some test data and known results with patch('openlp.plugins.songs.lib.importers.easyworship.SongImport'): mocked_manager = MagicMock() importer = EasyWorshipSongImport(mocked_manager, filenames=[]) importer.encoding = TEST_DATA_ENCODING importer.fields = TEST_FIELDS importer.field_descriptions = TEST_FIELD_DESCS field_results = [(0, b'A Heart Like Thine'), (1, 100), (2, 102), (3, True), (6, None), (7, None)] # WHEN: Called with test data for field_index, result in field_results: return_value = importer.get_field(field_index) # THEN: get_field should return the known results self.assertEqual(return_value, result, 'get_field should return "%s" when called with "%s"' % (result, TEST_FIELDS[field_index]))