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


Python test.RequestFactory方法代码示例

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


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

示例1: setup

# 需要导入模块: from django import test [as 别名]
# 或者: from django.test import RequestFactory [as 别名]
def setup(self, db):
        self.factory = RequestFactory()
        self.callers = create_test_users()
        self.callers.append(
            UserFactory(username='inactive_regular_user',
                is_active=False))
        self.callers.append(
            UserFactory(username='inactive_staff_user',
                is_active=False, is_staff=True))
        self.callers.append(
            UserFactory(username='inactive_super_user',
                is_active=False, is_superuser=True))
        self.callers.append(
            UserFactory(username='inactive_superstaff_user',
                is_active=False, is_staff=True, is_superuser=True))
        self.redirect_startswith = '/accounts/login/?next=' 
开发者ID:appsembler,项目名称:figures,代码行数:18,代码来源:test_figures_home_view.py

示例2: setUp

# 需要导入模块: from django import test [as 别名]
# 或者: from django.test import RequestFactory [as 别名]
def setUp(self):
        self.factory = RequestFactory()
        self.test_user = UserModel.objects.create_user(
            "test_user", "test@example.com", "123456")
        self.dev_user = UserModel.objects.create_user(
            "dev_user", "dev@example.com", "123456")

        self.application = Application(
            name="Test Password Application",
            user=self.dev_user,
            client_type=Application.CLIENT_PUBLIC,
            authorization_grant_type=Application.GRANT_PASSWORD,
        )
        self.application.save()

        oauth2_settings._SCOPES = ["read", "write"]
        oauth2_settings._DEFAULT_SCOPES = ["read", "write"] 
开发者ID:Humanitec,项目名称:django-oauth-toolkit-jwt,代码行数:19,代码来源:test_views.py

示例3: setUp

# 需要导入模块: from django import test [as 别名]
# 或者: from django.test import RequestFactory [as 别名]
def setUp(self):
        self.factory = RequestFactory()
        self.sessions = SessionMiddleware()
        self.messages = MessageMiddleware()
        self.event1 = models.Event.objects.create(
            datetime=today_noon,
            targetamount=5,
            timezone=pytz.timezone(getattr(settings, 'TIME_ZONE', 'America/Denver')),
        )
        self.run1 = models.SpeedRun.objects.create(
            name='Test Run 1', run_time='0:45:00', setup_time='0:05:00', order=1
        )
        self.run2 = models.SpeedRun.objects.create(
            name='Test Run 2', run_time='0:15:00', setup_time='0:05:00', order=2
        )
        if not User.objects.filter(username='admin').exists():
            User.objects.create_superuser('admin', 'nobody@example.com', 'password') 
开发者ID:GamesDoneQuick,项目名称:donation-tracker,代码行数:19,代码来源:test_speedrun.py

示例4: setUpClass

# 需要导入模块: from django import test [as 别名]
# 或者: from django.test import RequestFactory [as 别名]
def setUpClass(cls):
        cls.factory = RequestFactory()
        cls.client = Client()
        cls.user = User.objects.create_user("test", "test@archesproject.org", "password")

        rdm_admin_group = Group.objects.get(name="RDM Administrator")
        cls.user.groups.add(rdm_admin_group)
        cls.anonymous_user = User.objects.get(username="anonymous")

        cls.token = "abc"
        cls.oauth_client_id = OAUTH_CLIENT_ID
        cls.oauth_client_secret = OAUTH_CLIENT_SECRET

        sql_str = CREATE_TOKEN_SQL.format(token=cls.token, user_id=cls.user.pk)
        cursor = connection.cursor()
        cursor.execute(sql_str) 
开发者ID:archesproject,项目名称:arches,代码行数:18,代码来源:auth_tests.py

示例5: test_add_participants

# 需要导入模块: from django import test [as 别名]
# 或者: from django.test import RequestFactory [as 别名]
def test_add_participants(self):
        # by default, a user will be authorized to add a participant if they are not yet in the thread
        # we add new and existing participants
        request = RequestFactory()
        request.user = self.user
        request.rest_messaging_participant = Participant.objects.get(id=self.user.id)
        self.assertTrue(all(participant in [self.participant1, self.participant2, self.participant3] for participant in self.thread1.participants.all()))
        self.assertEqual(3, len(self.thread1.participants.all()))
        with self.assertNumQueries(2):
            self.thread1.add_participants(request, self.participant4.id, self.participant5.id)
        self.assertTrue(all(participant in [self.participant1, self.participant2, self.participant3, self.participant4, self.participant5] for participant in self.thread1.participants.all()))
        self.assertEqual(5, len(self.thread1.participants.all()))
        # by default, the number of participants is limited to 10
        l = []
        for i in range(7, 16):  # setUp ends at 6
            l.append(Participant(id=i))
        Participant.objects.bulk_create(l)
        self.thread1.add_participants(request, *[p.id for p in l])
        self.assertEqual(10, len(self.thread1.participants.all())) 
开发者ID:raphaelgyory,项目名称:django-rest-messaging,代码行数:21,代码来源:test_models.py

示例6: test_can_authenticate

# 需要导入模块: from django import test [as 别名]
# 或者: from django.test import RequestFactory [as 别名]
def test_can_authenticate(self):
        headers = ['(request-target)', 'accept', 'date', 'host']
        expected_signature = 'SelruOP39OWoJrSopfYJ99zOLoswmpyGXyDPdebeELc='
        expected_signature_string = build_signature(
            headers,
            key_id=KEYID,
            signature=expected_signature)
        request = RequestFactory().get(
            '/packages/measures/', {},
            HTTP_ACCEPT='application/json',
            HTTP_DATE='Mon, 17 Feb 2014 06:11:05 GMT',
            HTTP_HOST='localhost:8000',
            HTTP_AUTHORIZATION=expected_signature_string,
            HTTP_X_API_KEY=KEYID)

        result = self.auth.authenticate(request)
        self.assertIsNotNone(result)
        self.assertEqual(result[0], self.test_user)
        self.assertEqual(result[1], KEYID) 
开发者ID:etoccalino,项目名称:django-rest-framework-httpsignature,代码行数:21,代码来源:tests.py

示例7: test_public_with_link_to_share_toggle_on

# 需要导入模块: from django import test [as 别名]
# 或者: from django.test import RequestFactory [as 别名]
def test_public_with_link_to_share_toggle_on(self):
        # sharing behavior as of 09/13/2012:
        # it requires both data_share and form_share both turned on
        # in order to grant anon access to form uploading
        # TODO: findout 'for_user': 'all' and what it means
        response = self.client.post(self.perm_url, {'for_user': 'all',
                                    'perm_type': 'link'})
        self.assertEqual(response.status_code, 302)
        self.assertEqual(MetaData.public_link(self.xform), True)
        # toggle shared on
        self.xform.shared = True
        self.xform.shared_data = True
        self.xform.save()
        response = self.anon.get(self.show_url)
        self.assertEqual(response.status_code, 302)
        if not self._running_enketo():
            raise SkipTest
        with HTTMock(enketo_mock):
            factory = RequestFactory()
            request = factory.get('/')
            request.user = AnonymousUser()
            response = enter_data(
                request, self.user.username, self.xform.id_string)
            self.assertEqual(response.status_code, 302) 
开发者ID:awemulya,项目名称:kobo-predict,代码行数:26,代码来源:test_form_enter_data.py

示例8: form_list_xml

# 需要导入模块: from django import test [as 别名]
# 或者: from django.test import RequestFactory [as 别名]
def form_list_xml(url, request, **kwargs):
    response = requests.Response()
    factory = RequestFactory()
    req = factory.get(url.path)
    req.user = authenticate(username='bob', password='bob')
    req.user.profile.require_auth = False
    req.user.profile.save()
    id_string = 'transportation_2011_07_25'
    if url.path.endswith('formList'):
        res = formList(req, username='bob')
    elif url.path.endswith('form.xml'):
        res = download_xform(req, username='bob', id_string=id_string)
    elif url.path.find('xformsManifest') > -1:
        res = xformsManifest(req, username='bob', id_string=id_string)
    elif url.path.find('formid-media') > -1:
        data_id = url.path[url.path.rfind('/') + 1:]
        res = download_media_data(
            req, username='bob', id_string=id_string, data_id=data_id)
        response._content = get_streaming_content(res)
    else:
        res = formList(req, username='bob')
    response.status_code = 200
    if not response._content:
        response._content = res.content
    return response 
开发者ID:awemulya,项目名称:kobo-predict,代码行数:27,代码来源:test_briefcase_client.py

示例9: setUp

# 需要导入模块: from django import test [as 别名]
# 或者: from django.test import RequestFactory [as 别名]
def setUp(self):
        cache.clear()
        self.factory = RequestFactory()
        self.operator = self._create_operator() 
开发者ID:openwisp,项目名称:openwisp-users,代码行数:6,代码来源:test_authentication.py

示例10: test_customer

# 需要导入模块: from django import test [as 别名]
# 或者: from django.test import RequestFactory [as 别名]
def test_customer(self):
        factory = RequestFactory()
        request = factory.get('/checkin/')
        request.user = AnonymousUser
        request = add_middleware_to_request(request, SessionMiddleware)
        #form = CustomerForm(request) 
开发者ID:fpsw,项目名称:Servo,代码行数:8,代码来源:test_forms.py

示例11: setUp

# 需要导入模块: from django import test [as 别名]
# 或者: from django.test import RequestFactory [as 别名]
def setUp(self):
        # Every test needs access to the request factory.
        self.factory = RequestFactory()
        self.user = User.objects.create_user(
            username='John Doe',
            email='',
            password='test')
        self.c = Client() 
开发者ID:OpenMDM,项目名称:OpenMDM,代码行数:10,代码来源:tests.py

示例12: setUp

# 需要导入模块: from django import test [as 别名]
# 或者: from django.test import RequestFactory [as 别名]
def setUp(self):
        self.factory = RequestFactory()
        self.user = User.objects.create_user(
            username='pusher', email='pusher@example.com', password='hunter2'
        )
        self.object = PusherableExample.objects.create(
            text = "This is a test PusherableExample object"
        ) 
开发者ID:pusher,项目名称:django-pusherable,代码行数:10,代码来源:test_example.py

示例13: test_log_failure_username

# 需要导入模块: from django import test [as 别名]
# 或者: from django.test import RequestFactory [as 别名]
def test_log_failure_username(self, mock_logger, mock_authenticate):
        mock_authenticate.return_value = None
        request = RequestFactory().get("/")
        user = LoggingModelBackend().authenticate(
            request, username="fakeuser", password="does.not.exist"
        )
        assert user is None
        mock_logger.warning.assert_called_with(
            Whatever.contains("fakeuser"), extra={"code": WARNING_LOGIN_FAILURE}
        ) 
开发者ID:mozilla,项目名称:normandy,代码行数:12,代码来源:test_auth_backends.py

示例14: test_log_failure_no_username

# 需要导入模块: from django import test [as 别名]
# 或者: from django.test import RequestFactory [as 别名]
def test_log_failure_no_username(self, mock_logger, mock_authenticate):
        mock_authenticate.return_value = None
        request = RequestFactory().get("/")
        user = LoggingModelBackend().authenticate(request, password="does.not.exist")
        assert user is None
        mock_logger.warning.assert_called_with(
            Whatever.contains("no username provided"), extra={"code": WARNING_LOGIN_FAILURE}
        ) 
开发者ID:mozilla,项目名称:normandy,代码行数:10,代码来源:test_auth_backends.py

示例15: test_log_success

# 需要导入模块: from django import test [as 别名]
# 或者: from django.test import RequestFactory [as 别名]
def test_log_success(self, mock_logger, mock_authenticate):
        mock_authenticate.return_value = True
        request = RequestFactory().get("/")
        user = LoggingModelBackend().authenticate(
            request, username="fakeuser", password="does.not.exist"
        )
        assert user
        mock_logger.info.assert_called_with(
            Whatever.contains("fakeuser"), extra={"code": INFO_LOGIN_SUCCESS}
        ) 
开发者ID:mozilla,项目名称:normandy,代码行数:12,代码来源:test_auth_backends.py


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