當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。