本文整理汇总了Python中tests.functional.MagicMock.id方法的典型用法代码示例。如果您正苦于以下问题:Python MagicMock.id方法的具体用法?Python MagicMock.id怎么用?Python MagicMock.id使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类tests.functional.MagicMock
的用法示例。
在下文中一共展示了MagicMock.id方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_display_results_cclinumber
# 需要导入模块: from tests.functional import MagicMock [as 别名]
# 或者: from tests.functional.MagicMock import id [as 别名]
def test_display_results_cclinumber(self):
"""
Test displaying song search results sorted by CCLI number with basic song
"""
# GIVEN: Search results sorted by CCLI number, plus a mocked QtListWidgetItem
with patch('openlp.core.lib.QtWidgets.QListWidgetItem') as MockedQListWidgetItem, \
patch('openlp.core.lib.QtCore.Qt.UserRole') as MockedUserRole:
mock_search_results = []
mock_song = MagicMock()
mock_song_temp = MagicMock()
mock_song.id = 1
mock_song.title = 'My Song'
mock_song.sort_key = 'My Song'
mock_song.ccli_number = '12345'
mock_song.temporary = False
mock_song_temp.id = 2
mock_song_temp.title = 'My Temporary'
mock_song_temp.sort_key = 'My Temporary'
mock_song_temp.ccli_number = '12346'
mock_song_temp.temporary = True
mock_search_results.append(mock_song)
mock_search_results.append(mock_song_temp)
mock_qlist_widget = MagicMock()
MockedQListWidgetItem.return_value = mock_qlist_widget
# WHEN: I display song search results sorted by CCLI number
self.media_item.display_results_cclinumber(mock_search_results)
# THEN: The current list view is cleared, the widget is created, and the relevant attributes set
self.media_item.list_view.clear.assert_called_with()
MockedQListWidgetItem.assert_called_once_with('12345 (My Song)')
mock_qlist_widget.setData.assert_called_once_with(MockedUserRole, mock_song.id)
self.media_item.list_view.addItem.assert_called_once_with(mock_qlist_widget)
示例2: test_load_objects
# 需要导入模块: from tests.functional import MagicMock [as 别名]
# 或者: from tests.functional.MagicMock import id [as 别名]
def test_load_objects(self, mocked_set_case_insensitive_completer):
"""
Test the _load_objects() method
"""
# GIVEN: A song edit form and some mocked stuff
mocked_class = MagicMock()
mocked_class.name = 'Author'
mocked_combo = MagicMock()
mocked_combo.count.return_value = 0
mocked_cache = MagicMock()
mocked_object = MagicMock()
mocked_object.name = 'Charles'
mocked_object.id = 1
mocked_manager = MagicMock()
mocked_manager.get_all_objects.return_value = [mocked_object]
self.edit_song_form.manager = mocked_manager
# WHEN: _load_objects() is called
self.edit_song_form._load_objects(mocked_class, mocked_combo, mocked_cache)
# THEN: All the correct methods should have been called
self.edit_song_form.manager.get_all_objects.assert_called_once_with(mocked_class)
mocked_combo.clear.assert_called_once_with()
mocked_combo.count.assert_called_once_with()
mocked_combo.addItem.assert_called_once_with('Charles')
mocked_cache.append.assert_called_once_with('Charles')
mocked_combo.setItemData.assert_called_once_with(0, 1)
mocked_set_case_insensitive_completer.assert_called_once_with(mocked_cache, mocked_combo)
mocked_combo.setCurrentIndex.assert_called_once_with(-1)
mocked_combo.setCurrentText.assert_called_once_with('')
示例3: test_display_results_song
# 需要导入模块: from tests.functional import MagicMock [as 别名]
# 或者: from tests.functional.MagicMock import id [as 别名]
def test_display_results_song(self):
"""
Test displaying song search results with basic song
"""
# GIVEN: Search results, plus a mocked QtListWidgetItem
with patch('openlp.core.lib.QtWidgets.QListWidgetItem') as MockedQListWidgetItem, \
patch('openlp.core.lib.QtCore.Qt.UserRole') as MockedUserRole:
mock_search_results = []
mock_song = MagicMock()
mock_song.id = 1
mock_song.title = 'My Song'
mock_song.sort_key = 'My Song'
mock_song.authors = []
mock_song_temp = MagicMock()
mock_song_temp.id = 2
mock_song_temp.title = 'My Temporary'
mock_song_temp.sort_key = 'My Temporary'
mock_song_temp.authors = []
mock_author = MagicMock()
mock_author.display_name = 'My Author'
mock_song.authors.append(mock_author)
mock_song_temp.authors.append(mock_author)
mock_song.temporary = False
mock_song_temp.temporary = True
mock_search_results.append(mock_song)
mock_search_results.append(mock_song_temp)
mock_qlist_widget = MagicMock()
MockedQListWidgetItem.return_value = mock_qlist_widget
self.media_item.auto_select_id = 1
# WHEN: I display song search results
self.media_item.display_results_song(mock_search_results)
# THEN: The current list view is cleared, the widget is created, and the relevant attributes set
self.media_item.list_view.clear.assert_called_with()
self.media_item.save_auto_select_id.assert_called_with()
MockedQListWidgetItem.assert_called_once_with('My Song (My Author)')
mock_qlist_widget.setData.assert_called_once_with(MockedUserRole, mock_song.id)
self.media_item.list_view.addItem.assert_called_once_with(mock_qlist_widget)
self.media_item.list_view.setCurrentItem.assert_called_with(mock_qlist_widget)
示例4: test_build_remote_search
# 需要导入模块: from tests.functional import MagicMock [as 别名]
# 或者: from tests.functional.MagicMock import id [as 别名]
def test_build_remote_search(self):
"""
Test results for the remote search api
"""
# GIVEN: A Song and a search a JSON array should be returned.
mock_song = MagicMock()
mock_song.id = 123
mock_song.title = 'My Song'
mock_song.search_title = 'My Song'
mock_song.alternate_title = 'My alternative'
self.media_item.search_entire = MagicMock()
self.media_item.search_entire.return_value = [mock_song]
# WHEN: I process a search
search_results = self.media_item.search('My Song', False)
# THEN: The correct formatted results are returned
self.assertEqual(search_results, [[123, 'My Song', 'My alternative']])
示例5: test_process_verse_no_text
# 需要导入模块: from tests.functional import MagicMock [as 别名]
# 或者: from tests.functional.MagicMock import id [as 别名]
def test_process_verse_no_text(self):
"""
Test the process_verse() method when there's no text
"""
# GIVEN: An importer and a mocked method
importer = WordProjectBible(MagicMock(), path='.', name='.', filename='kj.zip')
mocked_db_book = MagicMock()
mocked_db_book.id = 1
chapter_number = 1
verse_number = 1
verse_text = ''
# WHEN: process_verse() is called
with patch.object(importer, 'create_verse') as mocked_create_verse:
importer.process_verse(mocked_db_book, chapter_number, verse_number, verse_text)
# THEN: The create_verse() method should NOT have been called
assert mocked_create_verse.call_count == 0
示例6: test_process_verse
# 需要导入模块: from tests.functional import MagicMock [as 别名]
# 或者: from tests.functional.MagicMock import id [as 别名]
def test_process_verse(self):
"""
Test the process_verse() method
"""
# GIVEN: An importer and a mocked method
importer = WordProjectBible(MagicMock(), path='.', name='.', filename='kj.zip')
mocked_db_book = MagicMock()
mocked_db_book.id = 1
chapter_number = 1
verse_number = 1
verse_text = ' In the beginning, God created the heavens and the earth '
# WHEN: process_verse() is called
with patch.object(importer, 'create_verse') as mocked_create_verse:
importer.process_verse(mocked_db_book, chapter_number, verse_number, verse_text)
# THEN: The create_verse() method should have been called
mocked_create_verse.assert_called_once_with(1, 1, 1, 'In the beginning, God created the heavens and the earth')