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


Python Client.post方法代码示例

本文整理汇总了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)
开发者ID:IanLewis,项目名称:kay,代码行数:61,代码来源:rest_test.py

示例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)
#.........这里部分代码省略.........
开发者ID:dbordak,项目名称:pyblog,代码行数:103,代码来源:rest_test.py


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