本文整理汇总了Python中test_utils.RequestFactory.API方法的典型用法代码示例。如果您正苦于以下问题:Python RequestFactory.API方法的具体用法?Python RequestFactory.API怎么用?Python RequestFactory.API使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类test_utils.RequestFactory
的用法示例。
在下文中一共展示了RequestFactory.API方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get_request
# 需要导入模块: from test_utils import RequestFactory [as 别名]
# 或者: from test_utils.RequestFactory import API [as 别名]
def get_request(self, data=None):
if data is None:
data = {}
request = RequestFactory().get("/", data)
request.REGION = mkt.regions.RESTOFWORLD
request.API = True
return request
示例2: test_fail
# 需要导入模块: from test_utils import RequestFactory [as 别名]
# 或者: from test_utils.RequestFactory import API [as 别名]
def test_fail(self):
url = absolutify(reverse('app-list'))
url, auth_header = self._oauth_request_info(
url, client_key=self.access.key,
client_secret="none")
auth = authentication.RestOAuthAuthentication()
req = RequestFactory().get(
url, HTTP_HOST='testserver',
HTTP_AUTHORIZATION=auth_header)
req.API = True
RestOAuthMiddleware().process_request(req)
assert not auth.authenticate(Request(req))
assert not hasattr(req, 'user')
示例3: test_bad_access_token
# 需要导入模块: from test_utils import RequestFactory [as 别名]
# 或者: from test_utils.RequestFactory import API [as 别名]
def test_bad_access_token(self):
url = absolutify(reverse('app-list'))
Token.generate_new(ACCESS_TOKEN, creds=self.access, user=self.user2)
url, auth_header = self._oauth_request_info(
url, client_key=self.access.key,
client_secret=self.access.secret, resource_owner_key=generate(),
resource_owner_secret=generate())
auth = authentication.RestOAuthAuthentication()
req = RequestFactory().get(
url, HTTP_HOST='testserver',
HTTP_AUTHORIZATION=auth_header)
req.API = True
RestOAuthMiddleware().process_request(req)
assert not auth.authenticate(Request(req))
示例4: test_success
# 需要导入模块: from test_utils import RequestFactory [as 别名]
# 或者: from test_utils.RequestFactory import API [as 别名]
def test_success(self):
url = absolutify(reverse('app-list'))
url, auth_header = self._oauth_request_info(
url, client_key=self.access.key,
client_secret=self.access.secret)
auth = authentication.RestOAuthAuthentication()
req = RequestFactory().get(
url, HTTP_HOST='testserver',
HTTP_AUTHORIZATION=auth_header)
req.API = True
req.user = AnonymousUser()
RestOAuthMiddleware().process_request(req)
ok_(auth.authenticate(Request(req)))
ok_(req.user.is_authenticated())
eq_(req.user, self.user)
示例5: test_use_access_token
# 需要导入模块: from test_utils import RequestFactory [as 别名]
# 或者: from test_utils.RequestFactory import API [as 别名]
def test_use_access_token(self):
url = absolutify(reverse('app-list'))
t = Token.generate_new(ACCESS_TOKEN, creds=self.access,
user=self.user2)
url, auth_header = self._oauth_request_info(
url, client_key=self.access.key, client_secret=self.access.secret,
resource_owner_key=t.key, resource_owner_secret=t.secret)
auth = authentication.RestOAuthAuthentication()
req = RequestFactory().get(
url, HTTP_HOST='testserver',
HTTP_AUTHORIZATION=auth_header)
req.API = True
req.user = AnonymousUser()
RestOAuthMiddleware().process_request(req)
ok_(auth.authenticate(Request(req)))
ok_(req.user.is_authenticated())
eq_(req.user, self.user2)
示例6: get_request
# 需要导入模块: from test_utils import RequestFactory [as 别名]
# 或者: from test_utils.RequestFactory import API [as 别名]
def get_request(self, query_string):
request = RequestFactory().get('/', query_string)
request.REGION = mkt.regions.WORLDWIDE
request.API = True
return request
示例7: test_no_api_version
# 需要导入模块: from test_utils import RequestFactory [as 别名]
# 或者: from test_utils.RequestFactory import API [as 别名]
def test_no_api_version(self):
req = RequestFactory().get('/api/v2/')
req.API = True
res = self.api_version_middleware.process_response(req, HttpResponse())
eq_(self.header(res, 'API-Version'), '2')
eq_(self.header(res, 'API-Status'), None)
示例8: test_session_not_used_api
# 需要导入模块: from test_utils import RequestFactory [as 别名]
# 或者: from test_utils.RequestFactory import API [as 别名]
def test_session_not_used_api(self, process_request):
req = RequestFactory().get('/')
req.API = True
NoVarySessionMiddleware().process_request(req)
assert not process_request.called