本文整理汇总了Python中mock.NonCallableMock类的典型用法代码示例。如果您正苦于以下问题:Python NonCallableMock类的具体用法?Python NonCallableMock怎么用?Python NonCallableMock使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了NonCallableMock类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get
def get(self, **params):
request = NonCallableMock(spec_set=[
"write", "finish", "setResponseCode", "setHeader", "args",
"method", "processing"
])
request.method = "GET"
request.args = {k: [v] for k, v in params.items()}
@contextlib.contextmanager
def processing():
yield
request.processing = processing
yield self.resource._async_render_GET(request)
self.assertTrue(request.finish.called)
if request.setResponseCode.called:
response_code = request.setResponseCode.call_args[0][0]
else:
response_code = 200
response_json = "".join(
call[0][0] for call in request.write.call_args_list
)
response_body = json.loads(response_json)
if response_code == 200:
self.check_response(response_body)
defer.returnValue((response_code, response_body))
示例2: test_volume_export
def test_volume_export(self, mockrepo):
mockobj = NonCallableMock()
mockobj.pid = 'vol:1'
mockobj.title = 'Lecoq, the detective'
mockobj.volume = 'V.1'
mockobj.date = ['1801']
mockrepo.return_value.get_object.return_value = mockobj
# to support for last modified conditional
mockobj.ocr.created = datetime.now()
# anonymous
export_url = reverse('books:webexport', kwargs={'pid': mockobj.pid})
response = self.client.get(export_url)
self.assertContains(response,
'''<div class="alert alert-warning">Export functionality is only available
to logged in users.</div>''',
msg_prefix='Anonymous user should see warning when viewing export page',
html=True)
# log in as a regular user
self.client.login(**self.user_credentials['user'])
response = self.client.get(export_url)
self.assert_('export_form' in response.context,
'export form should be set in response context for logged in user')
self.assertContains(response, 'Export to GitHub requires a GitHub account.',
msg_prefix='user should see a warning about github account')
示例3: STALE_test_invite_join_public
def STALE_test_invite_join_public(self):
room_id = "#foo:blue"
user_id = "@bob:red"
target_user_id = "@bob:red"
content = {"membership": Membership.JOIN}
event = self.hs.get_event_factory().create_event(
etype=RoomMemberEvent.TYPE,
user_id=user_id,
target_user_id=target_user_id,
room_id=room_id,
membership=Membership.JOIN,
content=content,
)
joined = ["red", "blue", "green"]
self.state_handler.handle_new_event.return_value = defer.succeed(True)
self.datastore.get_joined_hosts_for_room.return_value = (
defer.succeed(joined)
)
store_id = "store_id_fooo"
self.datastore.store_room_member.return_value = defer.succeed(store_id)
self.datastore.get_room.return_value = defer.succeed(None)
prev_state = NonCallableMock(name="prev_state")
prev_state.membership = Membership.INVITE
prev_state.sender = "@foo:blue"
self.datastore.get_room_member.return_value = defer.succeed(prev_state)
# Actual invocation
yield self.room_member_handler.change_membership(event)
self.assertTrue(self.federation.handle_new_event.called)
args = self.federation.handle_new_event.call_args[0]
invite_join_event = args[0]
self.assertTrue(InviteJoinEvent.TYPE, invite_join_event.TYPE)
self.assertTrue("blue", invite_join_event.target_host)
self.assertTrue("foo", invite_join_event.room_id)
self.assertTrue(user_id, invite_join_event.user_id)
self.assertFalse(hasattr(invite_join_event, "state_key"))
self.assertEquals(
set(["blue"]),
set(invite_join_event.destinations)
)
self.federation.get_state_for_room.assert_called_once_with(
"blue", "foo"
)
self.assertFalse(self.datastore.store_room_member.called)
self.assertFalse(self.notifier.on_new_room_event.called)
self.assertFalse(self.state_handler.handle_new_event.called)
示例4: _inject_mock_invalid_consumer
def _inject_mock_invalid_consumer(self, uuid=None):
"""For chaning injected consumer identity to one that fails is_valid()
Returns the injected identity if it need to be examined.
"""
invalid_identity = NonCallableMock(name='InvalidIdentityMock')
invalid_identity.is_valid = Mock(return_value=False)
invalid_identity.uuid = uuid or "INVALIDCONSUMERUUID"
inj.provide(inj.IDENTITY, invalid_identity)
return invalid_identity
示例5: test_clean_up_remove_68_pem
def test_clean_up_remove_68_pem(self, mock_remove, mock_isfile):
mock_product_directory = NonCallableMock(spec=ProductDirectory)
mock_product_directory.path = "/some/path"
inj.provide(inj.PROD_DIR, mock_product_directory)
self.engine.db = MagicMock()
mock_isfile.side_effect = iter([True, True])
self.engine.clean_up([])
mock_remove.assert_called_with("/some/path/68.pem")
self.engine.db.delete.assert_called_with("68")
self.engine.db.write.assert_called_with()
示例6: _inject_mock_valid_consumer
def _inject_mock_valid_consumer(self, uuid=None):
"""For changing injected consumer identity to one that passes is_valid()
Returns the injected identity if it need to be examined.
"""
identity = NonCallableMock(name='ValidIdentityMock')
identity.uuid = uuid or "VALIDCONSUMERUUID"
identity.is_valid = Mock(return_value=True)
identity.cert_dir_path = "/not/a/real/path/to/pki/consumer/"
inj.provide(inj.IDENTITY, identity)
return identity
示例7: setUp
def setUp(self):
# By default mock that we are registered. Individual test cases
# can override if they are testing disconnected scenario.
id_mock = NonCallableMock(name='FixtureIdentityMock')
id_mock.exists_and_valid = Mock(return_value=True)
id_mock.uuid = 'fixture_identity_mock_uuid'
id_mock.name = 'fixture_identity_mock_name'
# Don't really care about date ranges here:
self.mock_calc = NonCallableMock()
self.mock_calc.calculate.return_value = None
inj.provide(inj.IDENTITY, id_mock)
inj.provide(inj.PRODUCT_DATE_RANGE_CALCULATOR, self.mock_calc)
inj.provide(inj.ENTITLEMENT_STATUS_CACHE, stubs.StubEntitlementStatusCache())
inj.provide(inj.PROD_STATUS_CACHE, stubs.StubProductStatusCache())
inj.provide(inj.OVERRIDE_STATUS_CACHE, stubs.StubOverrideStatusCache())
inj.provide(inj.PROFILE_MANAGER, stubs.StubProfileManager())
# By default set up an empty stub entitlement and product dir.
# Tests need to modify or create their own but nothing should hit
# the system.
self.ent_dir = stubs.StubEntitlementDirectory()
inj.provide(inj.ENT_DIR, self.ent_dir)
self.prod_dir = stubs.StubProductDirectory()
inj.provide(inj.PROD_DIR, self.prod_dir)
# Installed products manager needs PROD_DIR injected first
inj.provide(inj.INSTALLED_PRODUCTS_MANAGER, stubs.StubInstalledProductsManager())
self.stub_cp_provider = stubs.StubCPProvider()
self._release_versions = []
self.stub_cp_provider.content_connection.get_versions = self._get_release_versions
inj.provide(inj.CP_PROVIDER, self.stub_cp_provider)
inj.provide(inj.CERT_SORTER, stubs.StubCertSorter())
# setup and mock the plugin_manager
plugin_manager_mock = Mock(name='FixturePluginManagerMock')
inj.provide(inj.PLUGIN_MANAGER, plugin_manager_mock)
inj.provide(inj.DBUS_IFACE, Mock(name='FixtureDbusIfaceMock'))
pooltype_cache = Mock()
inj.provide(inj.POOLTYPE_CACHE, pooltype_cache)
# don't use file based locks for tests
inj.provide(inj.ACTION_LOCK, RLock)
self.stub_facts = stubs.StubFacts()
inj.provide(inj.FACTS, self.stub_facts)
self.dbus_patcher = patch('subscription_manager.managercli.CliCommand._request_validity_check')
self.dbus_patcher.start()
示例8: test_clean_up_remove_180_pem
def test_clean_up_remove_180_pem(self, mock_remove, mock_isfile):
mock_product_directory = NonCallableMock(spec=ProductDirectory)
mock_product_directory.path = "/some/path"
inj.provide(inj.PROD_DIR, mock_product_directory)
self.engine.db = MagicMock()
mock_isfile.side_effect = iter([False, False])
self.engine.clean_up([
"rhel-i386-client-dts-5-beta",
"rhel-i386-client-dts-5",
])
mock_remove.assert_called_with("/some/path/180.pem")
self.engine.db.delete.assert_called_with("180")
self.engine.db.write.assert_called_with()
示例9: test_update_button_disabled
def test_update_button_disabled(self):
# Need an unregistered consumer object:
id_mock = NonCallableMock()
id_mock.name = None
id_mock.uuid = None
def new_identity():
return id_mock
provide(IDENTITY, new_identity)
dialog = factsgui.SystemFactsDialog()
dialog.show()
enabled = dialog.update_button.get_property('sensitive')
self.assertFalse(enabled)
示例10: setUp
def setUp(self):
self.mock_notifier = NonCallableMock(MeetmeServiceNotifier)
self.ami_class = Mock(xivo_ami.AMIClass)
self.manager = service_manager.MeetmeServiceManager(
self.mock_notifier,
self.ami_class,
)
self.mock_manager = NonCallableMock(MeetmeServiceManager)
context.register('meetme_service_notifier', self.mock_notifier)
context.register('meetme_service_manager', self.mock_manager)
示例11: _mock_response
def _mock_response(self):
response = NonCallableMock()
response._headers = {}
response.status_code = 200
response.queries = []
response.get = response._headers.get
response.content = ""
return response
示例12: test_pushapps_noatomic
def test_pushapps_noatomic(discover_apps_, hook, document_):
'''
Test case for pushapps with ``--no-atomic``
Algo:
1. discover apps
#. for each app
1. pre-push
2. push
3. post-push
'''
conf = NonCallableMock(name='conf')
dest = 'http://localhost:5984'
doc = document_()
dbs = conf.get_dbs()
ret_code = commands.pushapps(conf, '/mock_dir', dest, no_atomic=True)
assert ret_code == 0
conf.get_dbs.assert_called_with(dest)
hook.assert_any_call(conf, 'foo', 'pre-push', dbs=dbs, pushapps=True)
hook.assert_any_call(conf, 'foo', 'post-push', dbs=dbs, pushapps=True)
doc.push.assert_called_with(dbs, True, False)
示例13: test_pushapps_export
def test_pushapps_export(discover_apps_, hook, document_, dumps):
'''
Test case for pushapps with ``--export``,
Algo:
1. discover apps
#. pre-push
#. add app to a list ``apps``
#. post-push
#. json.dumps from apps
'''
conf = NonCallableMock(name='conf')
dest = None
ret_code = commands.pushapps(conf, '/mock_dir', dest, export=True)
assert ret_code == 0
discover_apps_.assert_called_with('/mock_dir')
hook.assert_any_call(conf, 'foo', 'pre-push',
dbs=conf.get_dbs(), pushapps=True)
hook.assert_any_call(conf, 'foo', 'post-push',
dbs=conf.get_dbs(), pushapps=True)
assert dumps.called
示例14: test_pushapps_output
def test_pushapps_output(discover_apps_, hook, document_, write_json):
'''
Test case for pushapps with ``--export --output file``
Algo:
1. discover apps
#. pre-push
#. add app to a list ``apps``
#. post-push
#. write_json(apps)
'''
conf = NonCallableMock(name='conf')
dest = None
ret_code = commands.pushapps(conf, '/mock_dir', dest, export=True, output='file')
assert ret_code == 0
discover_apps_.assert_called_with('/mock_dir')
hook.assert_any_call(conf, 'foo', 'pre-push',
dbs=conf.get_dbs(), pushapps=True)
hook.assert_any_call(conf, 'foo', 'post-push',
dbs=conf.get_dbs(), pushapps=True)
'file' in write_json.call_args[0]
示例15: test_volume_pages
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])