本文整理汇总了Python中django.http.HttpRequest._raw_post_data方法的典型用法代码示例。如果您正苦于以下问题:Python HttpRequest._raw_post_data方法的具体用法?Python HttpRequest._raw_post_data怎么用?Python HttpRequest._raw_post_data使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类django.http.HttpRequest
的用法示例。
在下文中一共展示了HttpRequest._raw_post_data方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_posts
# 需要导入模块: from django.http import HttpRequest [as 别名]
# 或者: from django.http.HttpRequest import _raw_post_data [as 别名]
def test_posts(self):
request = HttpRequest()
post_data = '{"name": "Ball", "artnr": 12345}'
request._raw_post_data = post_data
resp = self.client.post('/api/v1/products/', data=post_data, content_type='application/json')
self.assertEqual(resp.status_code, 201)
self.assertEqual(resp['location'], 'http://testserver/api/v1/products/12345/')
# make sure posted object exists
resp = self.client.get('/api/v1/products/12345/', data={'format': 'json'})
self.assertEqual(resp.status_code, 200)
obj = json.loads(resp.content)
self.assertEqual(obj['name'], 'Ball')
self.assertEqual(obj['artnr'], 12345)
# With appended characters
request = HttpRequest()
post_data = '{"name": "Ball 2", "artnr": 56789}'
request._raw_post_data = post_data
resp = self.client.post('/api/v1/products/', data=post_data, content_type='application/json')
self.assertEqual(resp.status_code, 201)
self.assertEqual(resp['location'], 'http://testserver/api/v1/products/56789/')
# make sure posted object exists
resp = self.client.get('/api/v1/products/56789/', data={'format': 'json'})
self.assertEqual(resp.status_code, 200)
obj = json.loads(resp.content)
self.assertEqual(obj['name'], 'Ball 2')
self.assertEqual(obj['artnr'], 56789)
示例2: test_form
# 需要导入模块: from django.http import HttpRequest [as 别名]
# 或者: from django.http.HttpRequest import _raw_post_data [as 别名]
def test_form(request):
data = {
'protocols': PROTOCOLS,
}
if request.method == 'POST':
tail = request.POST['tail']
protocol = request.POST['protocol']
query_string = request.POST['query_string']
request_text = request.POST['request']
fake_request = HttpRequest()
fake_request.GET = urlparse.parse_qs(query_string)
if not query_string:
fake_request._raw_post_data = request_text
response = serve(fake_request, protocol + '/' + tail, server)
data.update({
'tail': tail,
'protocol': protocol,
'query_string': query_string,
'request': request_text,
'response': response,
})
return render_to_response('test_form.html', data)
示例3: test_api_field_error
# 需要导入模块: from django.http import HttpRequest [as 别名]
# 或者: from django.http.HttpRequest import _raw_post_data [as 别名]
def test_api_field_error(self):
# When a field error is encountered, we should be presenting the message
# back to the user.
request = HttpRequest()
post_data = '{"content": "More internet memes.", "is_active": true, "title": "IT\'S OVER 9000!", "slug": "its-over", "user": "/api/v1/users/9001/"}'
request._raw_post_data = post_data
resp = self.client.post('/api/v1/notes/', data=post_data, content_type='application/json')
self.assertEqual(resp.status_code, 400)
self.assertEqual(resp.content, "Could not find the provided object via resource URI '/api/v1/users/9001/'.")
示例4: test_ajax_required
# 需要导入模块: from django.http import HttpRequest [as 别名]
# 或者: from django.http.HttpRequest import _raw_post_data [as 别名]
def test_ajax_required(self):
request = HttpRequest()
request.method = 'POST'
response = self.c(request)
self.assertEqual(response.status_code, http.NOT_FOUND.status_code)
request.META['HTTP_X_REQUESTED_WITH'] = u'XMLHttpRequest'
request.META['CONTENT_TYPE'] = 'application/json'
request._raw_post_data = '{"name": "John Doe", "age": 37}'
response = self.c(request)
self.assertEqual(request.data, {'name': 'John Doe', 'age': 37})
self.assertEqual(response.status_code, http.CREATED)
示例5: test_puts
# 需要导入模块: from django.http import HttpRequest [as 别名]
# 或者: from django.http.HttpRequest import _raw_post_data [as 别名]
def test_puts(self):
request = HttpRequest()
post_data = '{"content": "Another new post.", "is_active": true, "title": "Another New Title", "slug": "new-title", "user": "/api/v1/users/1/"}'
request._raw_post_data = post_data
resp = self.client.put('/api/v1/notes/1/', data=post_data, content_type='application/json')
self.assertEqual(resp.status_code, 204)
# make sure posted object exists
resp = self.client.get('/api/v1/notes/1/', data={'format': 'json'})
self.assertEqual(resp.status_code, 200)
obj = json.loads(resp.content)
self.assertEqual(obj['content'], 'Another new post.')
self.assertEqual(obj['is_active'], True)
self.assertEqual(obj['user'], '/api/v1/users/1/')
示例6: test_puts
# 需要导入模块: from django.http import HttpRequest [as 别名]
# 或者: from django.http.HttpRequest import _raw_post_data [as 别名]
def test_puts(self):
request = HttpRequest()
post_data = '{"content": "Another new post.", "is_active": true, "title": "Another New Title", "slug": "new-title", "user": "/api/v1/users/1/"}'
request._raw_post_data = post_data
resp = self.client.put("/api/v1/notes/1/", data=post_data, content_type="application/json")
self.assertEqual(resp.status_code, 204)
# make sure posted object exists
resp = self.client.get("/api/v1/notes/1/", data={"format": "json"})
self.assertEqual(resp.status_code, 200)
obj = json.loads(resp.content)
self.assertEqual(obj["content"], "Another new post.")
self.assertEqual(obj["is_active"], True)
self.assertEqual(obj["user"], "/api/v1/users/1/")
示例7: test_post_user
# 需要导入模块: from django.http import HttpRequest [as 别名]
# 或者: from django.http.HttpRequest import _raw_post_data [as 别名]
def test_post_user(self):
request = HttpRequest()
post_data = '''{
"username": "[email protected]"
}'''
request._raw_post_data = post_data
resp = self.client.post('/api/v1/user/', data=post_data, content_type='application/json')
self.assertEqual(resp.status_code, 201)
self.assertEqual(resp['location'], 'http://testserver/api/v1/user/8/')
new_user = User.objects.get(username='[email protected]')
# test dupe user posts
resp = self.client.post('/api/v1/user/', data=post_data, content_type='application/json')
self.assertEqual(resp.status_code, 400)
self.assertEqual(json.loads(resp.content)['username'][0], 'This email is already registered.')
示例8: test_post
# 需要导入模块: from django.http import HttpRequest [as 别名]
# 或者: from django.http.HttpRequest import _raw_post_data [as 别名]
def test_post(self):
print "Running POST test"
request = HttpRequest()
post_data = '{"code": "Some cool code", "description": "test snippet", "python_version": 2.7, "language": "/api/v1/language/1/", "title": "Unit Test Snippet 1", "user": "/api/v1/user/1/"}'
request._raw_post_data = post_data
resp = self.client.post('/api/v1/snippet/', data=post_data, content_type='application/json')
#print resp.content
self.assertEqual(resp.status_code, 201)
# make sure posted object exists
resp = self.client.get('/api/v1/snippet/2/', data={'format': 'json'})
self.assertEqual(resp.status_code, 200)
obj = json.loads(resp.content)
#print resp.content
self.assertEqual(obj['code'], 'Some cool code')
示例9: test_mimetype
# 需要导入模块: from django.http import HttpRequest [as 别名]
# 或者: from django.http.HttpRequest import _raw_post_data [as 别名]
def test_mimetype(self):
request = HttpRequest()
request.method = 'GET'
request.META['HTTP_ACCEPT'] = '*/*'
self.b(request)
self.assertEqual(request.accepttype, 'application/json')
request = HttpRequest()
request.method = 'PUT'
request.META['CONTENT_TYPE'] = 'application/json; charset=utf-8'
request._raw_post_data = '{"name": "Sally Doe", "age": null}'
self.b(request)
self.assertEqual(request.contenttype, 'application/json')
self.assertTrue(hasattr(request, 'PUT'))
示例10: test_listing_post
# 需要导入模块: from django.http import HttpRequest [as 别名]
# 或者: from django.http.HttpRequest import _raw_post_data [as 别名]
def test_listing_post(self):
token = user.profile.token
request = HttpRequest()
post_data = '''{
"description": "Cheap poop",
"price": "2",
"latitude": "43.2",
"longitude": "-79.4",
"photo": "/9j/4AAQSkZJRgABAQEAYABgAAD/2wBDAAgGBgcGBQgHBwcJCQgKDBQNDAsLDBkSEw8UHRofHh0aHBwgJC4nICIsIxwcKDcpLDAxNDQ0Hyc5PTgyPC4zNDL/2wBDAQkJCQwLDBgNDRgyIRwhMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjL/wAARCAATABMDASIAAhEBAxEB/8QAHwAAAQUBAQEBAQEAAAAAAAAAAAECAwQFBgcICQoL/8QAtRAAAgEDAwIEAwUFBAQAAAF9AQIDAAQRBRIhMUEGE1FhByJxFDKBkaEII0KxwRVS0fAkM2JyggkKFhcYGRolJicoKSo0NTY3ODk6Q0RFRkdISUpTVFVWV1hZWmNkZWZnaGlqc3R1dnd4eXqDhIWGh4iJipKTlJWWl5iZmqKjpKWmp6ipqrKztLW2t7i5usLDxMXGx8jJytLT1NXW19jZ2uHi4+Tl5ufo6erx8vP09fb3+Pn6/8QAHwEAAwEBAQEBAQEBAQAAAAAAAAECAwQFBgcICQoL/8QAtREAAgECBAQDBAcFBAQAAQJ3AAECAxEEBSExBhJBUQdhcRMiMoEIFEKRobHBCSMzUvAVYnLRChYkNOEl8RcYGRomJygpKjU2Nzg5OkNERUZHSElKU1RVVldYWVpjZGVmZ2hpanN0dXZ3eHl6goOEhYaHiImKkpOUlZaXmJmaoqOkpaanqKmqsrO0tba3uLm6wsPExcbHyMnK0tPU1dbX2Nna4uPk5ebn6Onq8vP09fb3+Pn6/9oADAMBAAIRAxEAPwDpT4yj0rwPDY+KTLeqdZm0LXJhL9o8wyRyOzRNHtITLINuAyLuTbuUVNoWt20ml+DFHjXRtZ1qF1ilNxcJh0lxubYXWTz1QeUjFSxLsGUb2K8L49+IzeI4Tpeh2ktl4eeWVmlSFWN3JvWRJTHs3IPMDtwctkFgM4rktK1m4kkjtlntbiOViTbxySkTr1KmJEc8qOcgjg5rlqYlxdoK51UsOp/E7H13RXknhH4weHdN8MWll4r11o9agaSOdXtLhiAJGCclCT8mzljuP8XOaK6U7q5zNWdjwLxNe3GieLNa0rT5TFZWd/PBBGQH2RrIwVctknAAHJrL/wCEg1T/AJ+v/Ia/4UUVDo03q4r7i1VqL7T+8+mfhT4b0HX/AIb6Zqur6DpV7qF09xJPcT2MTvI3nycklaKKK0SsZt31Z//Z"
}'''
request._raw_post_data = post_data
resp = self.client.post('/api/v1/listing/', data=post_data, content_type='application/json', HTTP_AUTHORIZATION='Token ' + token)
self.assertEqual(resp.status_code, 201)
self.assertEqual(resp['location'], 'http://testserver/api/v1/listing/4/')
#make sure posted object exists
resp = self.client.get('/api/v1/listing/4/', data={'format': 'json'}, HTTP_AUTHORIZATION='Token ' + token)
self.assertEqual(resp.status_code, 200)
obj = json.loads(resp.content)
self.assertEqual(obj['description'], 'Cheap poop')
示例11: test_posts
# 需要导入模块: from django.http import HttpRequest [as 别名]
# 或者: from django.http.HttpRequest import _raw_post_data [as 别名]
def test_posts(self):
request = HttpRequest()
post_data = '{"name": "Ball", "artnr": "12345"}'
request._raw_post_data = post_data
resp = self.client.post('/api/v1/products/', data=post_data, content_type='application/json')
self.assertEqual(resp.status_code, 201)
self.assertEqual(resp['location'], 'http://testserver/api/v1/products/12345/')
# make sure posted object exists
resp = self.client.get('/api/v1/products/12345/', data={'format': 'json'})
self.assertEqual(resp.status_code, 200)
obj = json.loads(resp.content)
self.assertEqual(obj['name'], 'Ball')
self.assertEqual(obj['artnr'], '12345')
# With appended characters
request = HttpRequest()
post_data = '{"name": "Ball 2", "artnr": "12345ABC"}'
request._raw_post_data = post_data
resp = self.client.post('/api/v1/products/', data=post_data, content_type='application/json')
self.assertEqual(resp.status_code, 201)
self.assertEqual(resp['location'], 'http://testserver/api/v1/products/12345ABC/')
# make sure posted object exists
resp = self.client.get('/api/v1/products/12345ABC/', data={'format': 'json'})
self.assertEqual(resp.status_code, 200)
obj = json.loads(resp.content)
self.assertEqual(obj['name'], 'Ball 2')
self.assertEqual(obj['artnr'], '12345ABC')
# With prepended characters
request = HttpRequest()
post_data = '{"name": "Ball 3", "artnr": "WK12345"}'
request._raw_post_data = post_data
resp = self.client.post('/api/v1/products/', data=post_data, content_type='application/json')
self.assertEqual(resp.status_code, 201)
self.assertEqual(resp['location'], 'http://testserver/api/v1/products/WK12345/')
# make sure posted object exists
resp = self.client.get('/api/v1/products/WK12345/', data={'format': 'json'})
self.assertEqual(resp.status_code, 200)
obj = json.loads(resp.content)
self.assertEqual(obj['name'], 'Ball 3')
self.assertEqual(obj['artnr'], 'WK12345')
# Now Primary Keys with Slashes
request = HttpRequest()
post_data = '{"name": "Bigwheel", "artnr": "76123/03"}'
request._raw_post_data = post_data
resp = self.client.post('/api/v1/products/', data=post_data, content_type='application/json')
self.assertEqual(resp.status_code, 201)
self.assertEqual(resp['location'], 'http://testserver/api/v1/products/76123/03/')
# make sure posted object exists
resp = self.client.get('/api/v1/products/76123/03/', data={'format': 'json'})
self.assertEqual(resp.status_code, 200)
obj = json.loads(resp.content)
self.assertEqual(obj['name'], 'Bigwheel')
self.assertEqual(obj['artnr'], '76123/03')
request = HttpRequest()
post_data = '{"name": "Trampolin", "artnr": "WS65150/02"}'
request._raw_post_data = post_data
resp = self.client.post('/api/v1/products/', data=post_data, content_type='application/json')
self.assertEqual(resp.status_code, 201)
self.assertEqual(resp['location'], 'http://testserver/api/v1/products/WS65150/02/')
# make sure posted object exists
resp = self.client.get('/api/v1/products/WS65150/02/', data={'format': 'json'})
self.assertEqual(resp.status_code, 200)
obj = json.loads(resp.content)
self.assertEqual(obj['name'], 'Trampolin')
self.assertEqual(obj['artnr'], 'WS65150/02')