本文整理汇总了Python中unittest.mock.Mock.user方法的典型用法代码示例。如果您正苦于以下问题:Python Mock.user方法的具体用法?Python Mock.user怎么用?Python Mock.user使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类unittest.mock.Mock
的用法示例。
在下文中一共展示了Mock.user方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: Mock
# 需要导入模块: from unittest.mock import Mock [as 别名]
# 或者: from unittest.mock.Mock import user [as 别名]
def test_補使用者資料無name(self):
登入資料 = Mock()
登入資料.user = 使用者表()
self.使用者 = self.社群接口.populate_user(HttpRequest(), 登入資料, {
'email': '[email protected]',
})
self.assertEqual(self.使用者.來源.名, '[email protected]')
示例2: test_has_permission_fails_with_no_user
# 需要导入模块: from unittest.mock import Mock [as 别名]
# 或者: from unittest.mock.Mock import user [as 别名]
def test_has_permission_fails_with_no_user(self):
permission = permissions.IsContinuousIntegrationToEdit()
request = Mock()
request.method = 'POST'
request.user = None
view = None
self.assertFalse(permission.has_permission(request, view))
示例3: test_has_permission_with_get
# 需要导入模块: from unittest.mock import Mock [as 别名]
# 或者: from unittest.mock.Mock import user [as 别名]
def test_has_permission_with_get(self):
permission = permissions.IsContinuousIntegrationToEdit()
user = User.objects.create(username="user")
request = Mock()
request.user = user
request.method = 'GET'
view = None
self.assertTrue(permission.has_permission(request, view))
示例4: test_authenicated_call
# 需要导入模块: from unittest.mock import Mock [as 别名]
# 或者: from unittest.mock.Mock import user [as 别名]
def test_authenicated_call(self):
"Authenicated call should yield a successful response."
request = Mock()
user = Mock()
user.is_authenticated = True
request.user = user
response = self.lookup.results(request)
self.assertTrue(response.status_code, 200)
示例5: test_non_authenicated_call
# 需要导入模块: from unittest.mock import Mock [as 别名]
# 或者: from unittest.mock.Mock import user [as 别名]
def test_non_authenicated_call(self):
"Non-Authenicated call should yield an unauthorized response."
request = Mock()
user = Mock()
user.is_authenticated = False
request.user = user
response = self.lookup.results(request)
self.assertEqual(response.status_code, 401)
示例6: test_product_quantity_defaults_to_zero
# 需要导入模块: from unittest.mock import Mock [as 别名]
# 或者: from unittest.mock.Mock import user [as 别名]
def test_product_quantity_defaults_to_zero(self):
cat = self.create_category()
prod = Product(pk=10, category=cat, name="Prod 1", price=10)
prod.save()
user = self.create_user()
request_mock = Mock()
request_mock.user = user
self.assertEqual(prod.get_cart_quantity(request_mock), 0)
示例7: test_can_set_cart_quantity
# 需要导入模块: from unittest.mock import Mock [as 别名]
# 或者: from unittest.mock.Mock import user [as 别名]
def test_can_set_cart_quantity(self):
cat = self.create_category()
prod = self.create_product(cat, stock=10)
user = self.create_user()
prod.set_cart_quantity(user, 5) # should not raise
request_mock = Mock()
request_mock.user = user
self.assertEqual(prod.get_cart_quantity(request_mock), 5)
示例8: test_set_cart_quantity_updates_session
# 需要导入模块: from unittest.mock import Mock [as 别名]
# 或者: from unittest.mock.Mock import user [as 别名]
def test_set_cart_quantity_updates_session(self):
cat = self.create_category()
prod = self.create_product(cat, stock=10)
user = self.create_user()
prod.set_cart_quantity(user, 5) # should not raise
prod = Product.objects.get(name="Product") # reloads the object from the db
request_mock = Mock()
request_mock.user = user
self.assertEqual(prod.get_cart_quantity(request_mock), 5)
示例9: test_staff_member_call
# 需要导入模块: from unittest.mock import Mock [as 别名]
# 或者: from unittest.mock.Mock import user [as 别名]
def test_staff_member_call(self):
"Staff member call should yield a successful response."
request = Mock()
user = Mock()
user.is_authenticated = lambda: True
user.is_staff = True
request.user = user
response = self.lookup.results(request)
self.assertTrue(response.status_code, 200)
示例10: test_authenicated_but_not_staff
# 需要导入模块: from unittest.mock import Mock [as 别名]
# 或者: from unittest.mock.Mock import user [as 别名]
def test_authenicated_but_not_staff(self):
"Authenicated but non staff call should yield a forbidden response."
request = Mock()
user = Mock()
user.is_authenticated = True
user.is_staff = False
request.user = user
response = self.lookup.results(request)
self.assertTrue(response.status_code, 403)
示例11: test_get_current_employee_none
# 需要导入模块: from unittest.mock import Mock [as 别名]
# 或者: from unittest.mock.Mock import user [as 别名]
def test_get_current_employee_none(self):
user = UserFactory.create(username='batman')
request = Mock()
request.session = dict()
request.user = user
with mock.patch('pmp_shield.employees.ldap_tools.LDAPTool.search_by_username',
TestEmployeeSelectionUtil.mock_ldap_tool.search_by_username):
employee = employee_selection_util.get_current_employee(request)
self.assertIsNone(employee)
示例12: test_has_permission
# 需要导入模块: from unittest.mock import Mock [as 别名]
# 或者: from unittest.mock.Mock import user [as 别名]
def test_has_permission(self):
permission = permissions.IsUser()
user = User.objects.create(username="user")
request = Mock()
request.user = user
view = None
self.assertTrue(permission.has_object_permission(
request, view, user.userpreferences))
示例13: test_validate_recipient_if_same_as_sender
# 需要导入模块: from unittest.mock import Mock [as 别名]
# 或者: from unittest.mock.Mock import user [as 别名]
def test_validate_recipient_if_same_as_sender(self):
apt = ApartmentFactory.create()
req = Mock()
req.building = apt.building
req.user = ResidentFactory.create(apartment=apt,
email="[email protected]")
serializer = MessageSerializer(context={'request': req})
attrs = {'recipient': req.user}
self.assertRaises(serializers.ValidationError,
serializer.validate_recipient, attrs, 'recipient')
示例14: test_validate_recipient_if_all_ok
# 需要导入模块: from unittest.mock import Mock [as 别名]
# 或者: from unittest.mock.Mock import user [as 别名]
def test_validate_recipient_if_all_ok(self):
apt = ApartmentFactory.create()
req = Mock()
req.building = apt.building
req.user = ResidentFactory.create(apartment=apt)
recipient = ResidentFactory.create(apartment=apt,
email='[email protected]')
serializer = MessageSerializer(context={'request': req})
attrs = {'recipient': recipient}
serializer.validate_recipient(attrs, 'recipient')
示例15: test_does_not_have_permission
# 需要导入模块: from unittest.mock import Mock [as 别名]
# 或者: from unittest.mock.Mock import user [as 别名]
def test_does_not_have_permission(self):
permission = permissions.IsUser()
user = User.objects.create(username="user")
other_user = User.objects.create(username="bar")
request = Mock()
request.user = other_user
view = None
self.assertFalse(permission.has_object_permission(
request, view, user.userpreferences))