本文整理匯總了Python中mock.NonCallableMock.width方法的典型用法代碼示例。如果您正苦於以下問題:Python NonCallableMock.width方法的具體用法?Python NonCallableMock.width怎麽用?Python NonCallableMock.width使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類mock.NonCallableMock
的用法示例。
在下文中一共展示了NonCallableMock.width方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: test_volume_pages
# 需要導入模塊: from mock import NonCallableMock [as 別名]
# 或者: from mock.NonCallableMock import width [as 別名]
def test_volume_pages(self, mockpaginator, mockrepo):
mockvol = NonCallableMock(spec=Volume)
mockvol.pid = 'vol:1'
mockvol.title = 'Lecoq, the detective'
mockvol.date = ['1801']
# second object retrieved from fedora is page, for layout
mockvol.width = 150
mockvol.height = 200
# volume url needed to identify annotations for pages in this volume
mockvol.get_absolute_url.return_value = reverse('books:volume',
kwargs={'pid': mockvol.pid})
mockrepo.return_value.get_object.return_value = mockvol
mockvol.find_solr_pages = MagicMock()
mockvol.find_solr_pages.return_value.count = 3
mockvol.find_solr_pages.__len__.return_value = 3
mockpage = Mock(width=640, height=400)
mockvol.pages = [mockpage]
vol_page_url = reverse('books:pages', kwargs={'pid': mockvol.pid})
response = self.client.get(vol_page_url)
# volume method should be used to find pages
self.assert_(call() in mockvol.find_solr_pages.call_args_list)
# volume should be set in context
self.assert_(mockvol, response.context['vol'])
# annotated pages should be empty for anonymous user
self.assertEqual({}, response.context['annotated_pages'])
# log in as a regular user
self.client.login(**self.user_credentials['user'])
testuser = get_user_model().objects.get(username=self.user_credentials['user']['username'])
page1_url = reverse('books:page', kwargs={'vol_pid': mockvol.pid, 'pid': 'page:1'})
page2_url = reverse('books:page', kwargs={'vol_pid': mockvol.pid, 'pid': 'page:2'})
page3_url = reverse('books:page', kwargs={'vol_pid': mockvol.pid, 'pid': 'page:3'})
mockvol.page_annotation_count.return_value = {
absolutize_url(page1_url): 5,
absolutize_url(page2_url): 2,
page3_url: 13
}
response = self.client.get(vol_page_url)
mockvol.page_annotation_count.assert_called_with(testuser)
annotated_pages = response.context['annotated_pages']
# counts should be preserved; urls should be non-absolute
# whether they started that way or not
self.assertEqual(5, annotated_pages[absolutize_url(page1_url)])
self.assertEqual(2, annotated_pages[absolutize_url(page2_url)])
self.assertEqual(13, annotated_pages[page3_url])