当前位置: 首页>>代码示例>>Python>>正文


Python Mock.user方法代码示例

本文整理汇总了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]')
开发者ID:shihyu,项目名称:tai5-uan5_gian5-gi2_phing5-tai5,代码行数:9,代码来源:test使用者社群接口試驗.py

示例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))
开发者ID:willjschmitt,项目名称:joulia-webserver,代码行数:9,代码来源:permissions_test.py

示例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))
开发者ID:willjschmitt,项目名称:joulia-webserver,代码行数:10,代码来源:permissions_test.py

示例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)
开发者ID:mlavin,项目名称:django-selectable,代码行数:10,代码来源:test_decorators.py

示例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)
开发者ID:mlavin,项目名称:django-selectable,代码行数:10,代码来源:test_decorators.py

示例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)
开发者ID:agripo,项目名称:website,代码行数:10,代码来源:test_shop.py

示例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)
开发者ID:agripo,项目名称:website,代码行数:10,代码来源:test_shop.py

示例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)
开发者ID:agripo,项目名称:website,代码行数:11,代码来源:test_shop.py

示例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)
开发者ID:bogdal,项目名称:django-selectable,代码行数:11,代码来源:test_decorators.py

示例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)
开发者ID:mlavin,项目名称:django-selectable,代码行数:11,代码来源:test_decorators.py

示例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)
开发者ID:luiscberrocal,项目名称:pmp_shield,代码行数:11,代码来源:test_utils.py

示例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))
开发者ID:willjschmitt,项目名称:joulia-webserver,代码行数:11,代码来源:permissions_test.py

示例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')
开发者ID:danjac,项目名称:ownblock,代码行数:12,代码来源:tests.py

示例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')
开发者ID:danjac,项目名称:ownblock,代码行数:12,代码来源:tests.py

示例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))
开发者ID:willjschmitt,项目名称:joulia-webserver,代码行数:12,代码来源:permissions_test.py


注:本文中的unittest.mock.Mock.user方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。