本文整理汇总了Python中kay.utils.test.Client.post方法的典型用法代码示例。如果您正苦于以下问题:Python Client.post方法的具体用法?Python Client.post怎么用?Python Client.post使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类kay.utils.test.Client
的用法示例。
在下文中一共展示了Client.post方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: RestTestCase
# 需要导入模块: from kay.utils.test import Client [as 别名]
# 或者: from kay.utils.test.Client import post [as 别名]
class RestTestCase(GAETestBase):
KIND_NAME_UNSWAPPED = False
USE_PRODUCTION_STUBS = True
CLEANUP_USED_KIND = True
KIND_PREFIX_IN_TEST = "t2"
def setUp(self):
s = LazySettings(settings_module='kay.tests.rest_settings')
app = get_application(settings=s)
self.client = Client(app, BaseResponse)
self.client.test_logout()
def tearDown(self):
self.client.test_logout()
def test_rest_operations(self):
self.client.test_login(email="[email protected]", is_admin="1")
response = self.client.get('/rest/metadata')
self.assertEqual(response.status_code, 200)
response = self.client.get('/rest/metadata/RestModel')
self.assertEqual(response.status_code, 200)
response = self.client.post('/rest/RestModel', data='<?xml version="1.0" encoding="utf-8"?><RestModel><i_prop>12</i_prop><s_prop>string</s_prop></RestModel>')
self.assertEqual(response.status_code, 200)
key = response.data
elm = RestModel.get(key)
self.assertEqual(elm.s_prop, "string")
self.assertEqual(elm.i_prop, 12)
response = self.client.post(
'/rest/RestModel/%s' % key,
data='<?xml version="1.0" encoding="utf-8"?><RestModel><i_prop>14</i_prop></RestModel>')
self.assertEqual(response.status_code, 200)
key2 = response.data
self.assertEqual(key, key2)
elm = RestModel.get(key)
self.assertEqual(elm.s_prop, "string")
self.assertEqual(elm.i_prop, 14)
response = self.client.get('/rest/RestModel')
self.assertEqual(response.status_code, 200)
response = self.client.get('/rest/RestModel/%s' % key)
self.assertEqual(response.status_code, 200)
response = self.client.get('/rest/RestModel/%s/s_prop' % key)
self.assertEqual(response.status_code, 200)
self.assertEqual(response.data, "string")
response = self.client.get('/rest/RestModel/%s/i_prop' % key)
self.assertEqual(response.status_code, 200)
self.assertEqual(response.data, "14")
response = self.client.delete('/rest/RestModel/%s' % key)
self.assertEqual(response.status_code, 200)
response = self.client.get('/rest/RestModel/%s' % key)
self.assertEqual(response.status_code, 404)
示例2: RestJSONTestCase
# 需要导入模块: from kay.utils.test import Client [as 别名]
# 或者: from kay.utils.test.Client import post [as 别名]
class RestJSONTestCase(GAETestBase):
KIND_NAME_UNSWAPPED = False
USE_PRODUCTION_STUBS = True
CLEANUP_USED_KIND = True
def setUp(self):
s = LazySettings(settings_module='kay.tests.rest_settings')
app = get_application(settings=s)
self.client = Client(app, BaseResponse)
self.client.test_logout()
def tearDown(self):
self.client.test_logout()
def test_rest_json(self):
headers = Headers({"Accept": "application/json"})
response = self.client.get('/rest/metadata', headers=headers)
self.assertEqual(response.status_code, 403)
self.client.test_login(email="[email protected]")
response = self.client.get('/rest/metadata', headers=headers)
self.assertEqual(response.status_code, 403)
self.client.test_login(email="[email protected]", is_admin="1")
response = self.client.get('/rest/metadata', headers=headers)
self.assertEqual(response.status_code, 200)
self.client.test_logout()
response = self.client.get('/rest/metadata/RestModel', headers=headers)
self.assertEqual(response.status_code, 403)
self.client.test_login(email="[email protected]")
response = self.client.get('/rest/metadata/RestModel', headers=headers)
self.assertEqual(response.status_code, 403)
self.client.test_login(email="[email protected]", is_admin="1")
response = self.client.get('/rest/metadata/RestModel', headers=headers)
self.assertEqual(response.status_code, 200)
self.client.test_logout()
response = self.client.post(
'/rest/RestModel',
data='{"RestModel": {"i_prop": 12, "s_prop": "string"}}',
content_type="application/json; charset=utf-8")
self.assertEqual(response.status_code, 403)
self.client.test_login(email="[email protected]")
response = self.client.post(
'/rest/RestModel',
data='{"RestModel": {"i_prop": 12, "s_prop": "string"}}',
content_type="application/json; charset=utf-8")
self.assertEqual(response.status_code, 403)
self.client.test_login(email="[email protected]", is_admin="1")
response = self.client.post(
'/rest/RestModel',
data='{"RestModel": {"i_prop": 12, "s_prop": "string"}}',
content_type="application/json; charset=utf-8")
self.assertEqual(response.status_code, 200)
key = response.data
elm = RestModel.get(key)
self.assertEqual(elm.s_prop, "string")
self.assertEqual(elm.i_prop, 12)
self.client.test_logout()
response = self.client.post(
'/rest/RestModel/%s' % key,
data='{"RestModel": {"i_prop": 14}}',
content_type="application/json; charset=utf-8")
self.assertEqual(response.status_code, 403)
self.client.test_login(email="[email protected]")
response = self.client.post(
'/rest/RestModel/%s' % key,
data='{"RestModel": {"i_prop": 14}}',
content_type="application/json; charset=utf-8")
self.assertEqual(response.status_code, 403)
self.client.test_login(email="[email protected]", is_admin="1")
response = self.client.post(
'/rest/RestModel/%s' % key,
data='{"RestModel": {"i_prop": 14}}',
content_type="application/json; charset=utf-8")
self.assertEqual(response.status_code, 200)
key2 = response.data
self.assertEqual(key, key2)
elm = RestModel.get(key)
self.assertEqual(elm.s_prop, "string")
self.assertEqual(elm.i_prop, 14)
response = self.client.post(
'/rest/RestModel',
data='[{"RestModel": {"i_prop": 1, "s_prop": "foobar1"}},{"RestModel": {"i_prop": 2, "s_prop": "foobar2"}}]',
content_type="application/json; charset=utf-8")
self.assertEqual(response.status_code, 200)
#.........这里部分代码省略.........