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


Python Mock.user方法代码示例

本文整理汇总了Python中mock.Mock.user方法的典型用法代码示例。如果您正苦于以下问题:Python Mock.user方法的具体用法?Python Mock.user怎么用?Python Mock.user使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在mock.Mock的用法示例。


在下文中一共展示了Mock.user方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: prepare_request_mock

# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import user [as 别名]
    def prepare_request_mock(self, data, referer='http://localhost/user_with_workspaces/Public Workspace', user=None, extra_headers={}, GET=''):
        request = Mock()
        request.method = 'POST'
        request.get_host.return_value = 'localhost'
        GET_PARAMETERS = parse_qsl(GET)
        request.GET = MagicMock()
        request.GET.__len__.side_effect = lambda: len(GET_PARAMETERS)
        request.GET.__getitem__.side_effect = lambda key: GET_PARAMETERS[key]
        request.GET.urlencode.side_effect = lambda: GET
        request.COOKIES = {
            settings.SESSION_COOKIE_NAME: 'test',
        }
        request.META = {
            'HTTP_ACCEPT': 'application/json',
            'SERVER_PROTOCOL': 'http',
            'REMOTE_ADDR': '127.0.0.1',
            'content_type': 'application/json',
            'content_length': len(data),
            'HTTP_HOST': 'localhost',
            'HTTP_REFERER': referer,
            'HTTP_X_FI_WARE_OAUTH_TOKEN': 'true',
        }
        request.META.update(extra_headers)
        request.read.return_value = data
        if user is None:
            request.user = self.admin_mock
        else:
            request.user = user

        return request
开发者ID:GreenIDer-Donati,项目名称:wirecloud,代码行数:32,代码来源:proxy.py

示例2: test_user_logged_in

# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import user [as 别名]
    def test_user_logged_in(self, get, now):

        # user requests email change
        user = Mock()
        token_object = Mock()
        token_object.token = 'sometokencontent'
        token_object.user = user
        get.return_value = token_object

        # user is logged in
        request = Mock()
        request.user = user

        # user clicks link in his email
        result = change_email(request, token_object.token)
        self.assertEquals(result.status_code, 302)
        get.assert_called_once_with(
            token=token_object.token, valid_until__gte=now())
        # user stays logged in
        self.assertTrue(request.user.is_authenticated())
        # token is deleted
        token_object.delete.assert_called_once_with()
        user.save.assert_called_once_with()
        # user email gets changed
        self.assertEqual(user.email, token_object.email)
开发者ID:D0han,项目名称:saleor,代码行数:27,代码来源:tests.py

示例3: test_car_has_object_permission

# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import user [as 别名]
 def test_car_has_object_permission(self):
     car = Mock()
     user = Mock()
     request = Mock()
     request.user = user
     car.user = user
     permission = CarOwnerPermission()
     self.assertTrue(
         permission.has_object_permission(request, Mock(), car)
     )
开发者ID:holandes22,项目名称:mycarhistory,代码行数:12,代码来源:test_permissions.py

示例4: test_treatment_has_object_permission

# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import user [as 别名]
 def test_treatment_has_object_permission(self):
     car = Mock()
     user = Mock()
     request = Mock()
     request.user = user
     car.user = user
     treatment = Mock()
     treatment.car = car
     permission = TreatmentOwnerPermission()
     self.assertTrue(
         permission.has_object_permission(request, Mock(), treatment)
     )
开发者ID:holandes22,项目名称:mycarhistory,代码行数:14,代码来源:test_permissions.py

示例5: login

# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import user [as 别名]
 def login(self, adapter, provider_name):
     del adapter, provider_name
     response = Mock()
     response.error = self.error
     if self.error:
         response.user = False
     else:
         user = Mock()
         user.name = self.name
         user.email = self.email
         response.user = user
     return response
开发者ID:cuducos,项目名称:findaconf,代码行数:14,代码来源:mocks.py

示例6: test_photo_too_big

# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import user [as 别名]
    def test_photo_too_big(self, mock_is_image_check, mock_is_animated_check):
        # Mock the ImageCheck object to pass checks on the uploaded image
        mock_is_image_check.return_value = True
        mock_is_image_check.return_value = False
        mock_is_animated_check.returned_value = False

        request = Mock()
        request.user = self.user
        data = {'username': self.user_profile.username,
                'email': self.user_profile.email}
        files = {'photo': get_uploaded_file('transparent.png')}
        form = UserEditForm(data, files=files, instance=self.user_profile,
                            request=request)

        # Creating the mock object instead of the uploaded file,
        # with a specific size over the limit
        upload_mock = MagicMock(spec=SimpleUploadedFile)
        upload_mock._name = 'transparent.png'
        upload_mock.size = 4 * 1024 * 1024 + 1
        upload_mock.content_type = 'image/png'

        # Injecting the mock object
        form.files['photo'] = upload_mock

        assert not form.is_valid()
        mock_is_image_check.assert_called()
        mock_is_animated_check.assert_called()
        assert form.errors == {
            'photo': [u'Please use images smaller than 4MB.']
        }
开发者ID:piyushmittal25,项目名称:addons-server,代码行数:32,代码来源:test_forms.py

示例7: test_contact_create

# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import user [as 别名]
 def test_contact_create(self):
     # POST with no existing contact creates a new one
     name = u'A BRAND NEW CONTACT'
     data = {
         u'name': name,
         u'language': u'wxyz',
         u'submit': u'Save Contact',
         u'connection_set-0-id': u'',
         u'connection_set-0-DELETE': u'',
         u'connection_set-0-backend': u'1',
         u'connection_set-0-contact': u'',
         u'connection_set-0-identity': u'4567',
         u'connection_set-1-id': u'',
         u'connection_set-1-contact': u'',
         u'connection_set-1-identity': u'',
         u'connection_set-1-backend': u'',
         u'connection_set-INITIAL_FORMS': u'0',
         u'connection_set-TOTAL_FORMS': u'2',
         u'connection_set-MAX_NUM_FORMS': u'10',
     }
     with patch('rapidsms.contrib.registration.views.render'):
         request = Mock(method="POST", POST=data)
         request.__class__ = HttpRequest
         self.login()
         request.user = self.user
         retval = views.contact(request)
     self.assertTrue(isinstance(retval, HttpResponseRedirect))
     self.assertEqual(302, retval.status_code)
     Contact.objects.get(name=name)
开发者ID:0xD3ADB33F,项目名称:rapidsms,代码行数:31,代码来源:tests.py

示例8: test_contact_delete

# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import user [as 别名]
    def test_contact_delete(self):
        # Submitting with Delete button deletes the contact
        contact = self.contacts[0]
        data = {
            u'name': u'The Contact',
            u'language': u'wxyz',
            u'delete_contact': u"dontcare",
            u'connection_set-0-id': u'2',
            u'connection_set-0-DELETE': u'',
            u'connection_set-0-backend': u'1',
            u'connection_set-0-contact': u'1',
            u'connection_set-0-identity': u'4567',
            u'connection_set-1-id': u'',
            u'connection_set-1-contact': u'1',
            u'connection_set-1-identity': u'987654',
            u'connection_set-1-backend': u'1',
            u'connection_set-INITIAL_FORMS': u'1',
            u'connection_set-TOTAL_FORMS': u'2',
            u'connection_set-MAX_NUM_FORMS': u'10',
        }

        with patch('rapidsms.contrib.registration.views.render'):
            request = Mock(method="POST", POST=data)
            request.__class__ = HttpRequest
            self.login()
            request.user = self.user
            retval = views.contact(request, pk=contact.pk)
        self.assertTrue(isinstance(retval, HttpResponseRedirect))
        self.assertEqual(302, retval.status_code)
        self.assertFalse(Contact.objects.filter(pk=contact.pk).exists())
开发者ID:0xD3ADB33F,项目名称:rapidsms,代码行数:32,代码来源:tests.py

示例9: test_contact_update

# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import user [as 别名]
 def test_contact_update(self):
     # POST to contact view updates the contact and connections
     contact = self.contacts[0]
     data = {
         u'name': u'The Contact',
         u'language': u'wxyz',
         u'submit': u'Save Contact',
         u'connection_set-0-id': u'2',
         u'connection_set-0-DELETE': u'',
         u'connection_set-0-backend': u'1',
         u'connection_set-0-contact': u'1',
         u'connection_set-0-identity': u'4567',
         u'connection_set-1-id': u'',
         u'connection_set-1-contact': u'1',
         u'connection_set-1-identity': u'',
         u'connection_set-1-backend': u'',
         u'connection_set-INITIAL_FORMS': u'1',
         u'connection_set-TOTAL_FORMS': u'2',
         u'connection_set-MAX_NUM_FORMS': u'10',
     }
     with patch('rapidsms.contrib.registration.views.render'):
         request = Mock(method="POST", POST=data)
         request.__class__ = HttpRequest
         self.login()
         request.user = self.user
         retval = views.contact(request, pk=contact.pk)
     self.assertTrue(isinstance(retval, HttpResponseRedirect))
     self.assertEqual(302, retval.status_code)
     new_contact = Contact.objects.get(pk=contact.pk)
     self.assertEqual(data['name'], new_contact.name)
     self.assertEqual(data['language'], new_contact.language)
     identities = [c.identity for c in contact.connection_set.all()]
     self.assertIn(data['connection_set-0-identity'], identities)
开发者ID:0xD3ADB33F,项目名称:rapidsms,代码行数:35,代码来源:tests.py

示例10: test_addon_sharing

# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import user [as 别名]
    def test_addon_sharing(self):
        addon = Addon.objects.get(id=7172)

        jingo.load_helpers()

        request = Mock()
        request.user = DjangoUser()
        request.APP = amo.FIREFOX
        ctx = {'request': request,
               'APP': request.APP,
               'LANG': translation.get_language()}

        # disable cake csrf token
        cake_csrf_token = lambda: ''
        cake_csrf_token.__name__ = 'cake_csrf_token'
        jingo.register.function(cake_csrf_token)

        doc = pq(addon_sharing(ctx, addon))
        self.assert_(doc.html())
        self.assertEquals(doc('li').length, len(sharing.SERVICES_LIST))

        # Make sure services are in the right order.
        for i in range(len(sharing.SERVICES_LIST)):
            self.assertEquals(doc('li').eq(i).attr('class'),
                              sharing.SERVICES_LIST[i].shortname)
            assert doc('li a').eq(i).attr('target') in ('_blank', '_self'), (
                'Sharing link target must either be blank or self.')
开发者ID:chowse,项目名称:zamboni,代码行数:29,代码来源:tests.py

示例11: test_identity_already_exists

# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import user [as 别名]
    def test_identity_already_exists(self, mocked_message):
        """Test to add an email that already exists."""

        user = UserFactory.create(email='[email protected]')
        IdpProfile.objects.create(
            profile=user.userprofile,
            auth0_user_id='email|',
            email=user.email,
            primary=True
        )
        claims = {
            'email': '[email protected]',
            'user_id': 'email|'
        }

        request_mock = Mock(spec=HttpRequest)
        request_mock.user = user
        self.backend.claims = claims
        self.backend.request = request_mock
        self.backend.check_authentication_method(user)
        idp_q = IdpProfile.objects.filter(auth0_user_id='email|',
                                          email=user.email,
                                          profile=user.userprofile)
        eq_(idp_q.count(), 1)
        ok_(not mocked_message.called)
开发者ID:yahkrivetko,项目名称:mozillians,代码行数:27,代码来源:test_authbackend.py

示例12: test_filter_users_with_a_non_existing_identity

# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import user [as 别名]
    def test_filter_users_with_a_non_existing_identity(self):
        """Test filter users with a non primary identity."""

        user = UserFactory.create(email='[email protected]')
        IdpProfile.objects.create(
            profile=user.userprofile,
            auth0_user_id='email|1',
            email='[email protected]',
            primary=True
        )
        claims = {
            'email': '[email protected]',
            'user_id': 'email|2'
        }

        request_mock = Mock(spec=HttpRequest)
        request_mock.user = user
        self.backend.claims = claims
        self.backend.request = request_mock
        users = self.backend.filter_users_by_claims(claims)
        idp_q = IdpProfile.objects.filter(auth0_user_id='email|1',
                                          email='[email protected]',
                                          profile=user.userprofile)
        eq_(idp_q.count(), 1)
        eq_(list(users), [])
开发者ID:yahkrivetko,项目名称:mozillians,代码行数:27,代码来源:test_authbackend.py

示例13: has_perm

# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import user [as 别名]
 def has_perm(self, method, obj, auth=None, user=None):
     perm = TeamPermission()
     request = Mock()
     request.auth = auth
     request.user = user
     request.method = method
     return perm.has_object_permission(request, None, obj)
开发者ID:nakamura41,项目名称:sentry,代码行数:9,代码来源:test_team.py

示例14: test_add_idp_wrong_flow

# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import user [as 别名]
    def test_add_idp_wrong_flow(self, mocked_message):
        """Test logging in with a weaker provider compared to the current one"""

        user = UserFactory.create(email='[email protected]')
        IdpProfile.objects.create(
            profile=user.userprofile,
            auth0_user_id='ad|foobar',
            primary=True,
            email='[email protected]'
        )

        claims = {
            'email': '[email protected]',
            'user_id': 'foobar'
        }

        request_mock = Mock(spec=HttpRequest)
        request_mock.user = user
        self.backend.claims = claims
        self.backend.request = request_mock

        returned_user = self.backend.check_authentication_method(user)
        msg = 'Please use LDAP Provider as the login method to authenticate'
        mocked_message.error.assert_called_once_with(request_mock, msg)

        eq_(returned_user, None)
开发者ID:johngian,项目名称:mozillians,代码行数:28,代码来源:test_authbackend.py

示例15: test_vote_captcha_first_vote_loggedin

# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import user [as 别名]
 def test_vote_captcha_first_vote_loggedin(self):
     # first vote does not require captcha if user is logged in
     # even if no prior votes have been cast by the logged in user
     mock_request_loggedin = Mock(spec=object)
     mock_request_loggedin.user = Mock()
     mock_request_loggedin.user.is_authenticated = lambda: True
     self.assertFalse(vote_needs_captcha(mock_request_loggedin))
开发者ID:caktus,项目名称:django-opendebates,代码行数:9,代码来源:test_utils.py


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