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


Python support.assert_response_code函数代码示例

本文整理汇总了Python中tests.support.assert_response_code函数的典型用法代码示例。如果您正苦于以下问题:Python assert_response_code函数的具体用法?Python assert_response_code怎么用?Python assert_response_code使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了assert_response_code函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_jsonp_response_when_accept_textjavascript

 def test_jsonp_response_when_accept_textjavascript(self):
     response = self._fetch(
         self.get_url('/api/?callback=my_callback'), 'GET', headers={
             'Accept': 'text/javascript'
         })
     assert_response_code(response, 200)
     assert response.body.decode('utf-8').startswith('my_callback(')
开发者ID:Hazer,项目名称:tapioca,代码行数:7,代码来源:test_rest_api.py

示例2: test_post_to_create_a_new_resource

 def test_post_to_create_a_new_resource(self):
     a_new_item = {
         'text': 'this is my new item'
     }
     response = self.post(self.get_url('/api'), dumps(a_new_item))
     assert_response_code(response, 201)
     assert 'Location' in response.headers
开发者ID:costalince,项目名称:tapioca,代码行数:7,代码来源:test_rest_api.py

示例3: test_post_to_create_a_new_resource

 def test_post_to_create_a_new_resource(self):
     a_new_item = {
         'text': 'this is my new item'
     }
     response = self.post(self.get_url('/api'), dumps(a_new_item))
     assert_response_code(response, 201)
     self.assertRegexpMatches(response.headers['Location'], r'http://localhost:\d+/api/\d+')
     assert loads(response.body)['text'] == 'this is my new item'
开发者ID:Hazer,项目名称:tapioca,代码行数:8,代码来源:test_rest_api.py

示例4: test_show_content_as_html_when_requested_by_browser

 def test_show_content_as_html_when_requested_by_browser(self):
     CHROME_ACCEPT_HEADER = 'text/html,application/xhtml+xml,application/xm'\
                            'l;q=0.9,*/*;q=0.8'
     response = self._fetch(
         self.get_url('/api/'), 'GET', headers={
             'Accept': CHROME_ACCEPT_HEADER
         })
     assert_response_code(response, 200)
     assert '<body>' in response.body.decode('utf-8')
开发者ID:Hazer,项目名称:tapioca,代码行数:9,代码来源:test_rest_api.py

示例5: test_get_request_to_list_all_resource_instances

 def test_get_request_to_list_all_resource_instances(self):
     response = self.get('/api')
     assert_response_code(response, 200)
     resources = loads(response.body.decode('utf-8'))
     number_of_items = len(resources)
     assert number_of_items == 10, 'should return 10 resources but returned {0:d}'.format(number_of_items)
     for item in resources:
         assert 'id' in item, 'should have the key \'id\' in the resource instance'
         assert 'text' in item, 'should have the \'text\' in the resource instance'
开发者ID:Hazer,项目名称:tapioca,代码行数:9,代码来源:test_rest_api.py

示例6: test_update_new_instance_of_the_resource_with_content_type_text_xml

 def test_update_new_instance_of_the_resource_with_content_type_text_xml(self):
     an_updated_item ='<comment id="2">meu comentario</comment>'
     response = self._fetch(self.get_url('/api/2'), 'PUT', headers={'Content-Type': 'text/xml'}, body=an_updated_item)
     assert_response_code(response, 204)
     # get the resource to verify if it was updated
     response = self._fetch(response.headers['Location'], 'GET', headers={'Accept': 'text/xml'})
     assert 'text/xml' in response.headers['Content-Type'], 'the content-type should be text/xml but it was {0}'.format(response.headers['Content-Type'])
     doc = ElementTree.fromstring(response.body)
     assert doc.tag == 'comment', 'the tag should be "comment" but it was {0}'.format(doc.tag)
     assert doc.text == 'meu comentario', 'the comment text should be "meu comentario" but it was {0}'.format(doc.text)
开发者ID:Hazer,项目名称:tapioca,代码行数:10,代码来源:test_rest_api.py

示例7: test_put_to_update_an_existing_resource

 def test_put_to_update_an_existing_resource(self):
     response = self.get('/api/1')
     assert_response_code(response, 200)
     resource = loads(response.body.decode('utf-8'))
     resource['comment'] = 'wow!'
     response = self.put(self.get_url('/api/1'), dumps(resource))
     assert_response_code(response, 204)
     response = self.get('/api/1')
     resource = loads(response.body.decode('utf-8'))
     assert 'comment' in resource
     assert resource['comment'] == 'wow!'
开发者ID:Hazer,项目名称:tapioca,代码行数:11,代码来源:test_rest_api.py

示例8: test_create_new_instance_of_the_resource_with_content_type_text_xml

 def test_create_new_instance_of_the_resource_with_content_type_text_xml(self):
     a_new_item ='<comment>meu comentario</comment>'
     response = self._fetch(self.get_url('/api'), 'POST', headers={'Content-Type': 'text/xml'}, body=a_new_item)
     assert_response_code(response, 201)
     # gets the new instance
     response = self._fetch(response.headers['Location'], 'GET', headers={'Accept': 'text/xml'})
     assert 'text/xml' in response.headers['Content-Type'], 'the content-type should be text/xml but it was {0}'.format(response.headers['Content-Type'])
     doc = ElementTree.fromstring(response.body)
     assert doc.tag == 'comment', 'the tag should be "comment" but it was {0}'.format(doc.tag)
     assert doc.text == 'meu comentario', 'the comment text should be "meu comentario" but it was {0}'.format(doc.text)
     assert doc.get('id') == '10', 'the id should be 11 but it was {0}'.format(doc.get('id'))
开发者ID:Hazer,项目名称:tapioca,代码行数:11,代码来源:test_rest_api.py

示例9: test_should_raise_404_when_extension_is_not_found

 def test_should_raise_404_when_extension_is_not_found(self):
     response = self.get('/api/1.rb')
     assert_response_code(response, 404)
开发者ID:Hazer,项目名称:tapioca,代码行数:3,代码来源:test_rest_api.py

示例10: test_should_return_type_xml_as_specified_in_url

 def test_should_return_type_xml_as_specified_in_url(self):
     response = self.get('/api/1.xml')
     assert_response_code(response, 200)
     assert '</comment>' in response.body.decode('utf-8')
开发者ID:Hazer,项目名称:tapioca,代码行数:4,代码来源:test_rest_api.py

示例11: test_should_return_type_json_as_specified_in_url

 def test_should_return_type_json_as_specified_in_url(self):
     response = self.get('/api/1.json')
     assert_response_code(response, 200)
     data = loads(response.body.decode('utf-8'))
     assert 'id' in data.decode('utf-8')
开发者ID:Hazer,项目名称:tapioca,代码行数:5,代码来源:test_rest_api.py

示例12: test_get_a_resource_that_does_not_exist

 def test_get_a_resource_that_does_not_exist(self):
     response = self.get('/api/30')
     assert_response_code(response, 404)
开发者ID:Hazer,项目名称:tapioca,代码行数:3,代码来源:test_rest_api.py

示例13: test_try_to_update_a_resource

 def test_try_to_update_a_resource(self):
     response = self.put(self.get_url('/api/1'), dumps(dict(text='nice')))
     assert_response_code(response, 404)
开发者ID:Hazer,项目名称:tapioca,代码行数:3,代码来源:test_rest_api.py

示例14: test_try_to_list_resources

 def test_try_to_list_resources(self):
     response = self.get('/api')
     assert_response_code(response, 404)
开发者ID:Hazer,项目名称:tapioca,代码行数:3,代码来源:test_rest_api.py

示例15: test_should_return_with_the_callback_name_i_choose

 def test_should_return_with_the_callback_name_i_choose(self):
     response = self.get('/api/1.js?callback=fooBar')
     assert_response_code(response, 200)
     assert response.body.decode('utf-8').startswith('fooBar(')
开发者ID:Hazer,项目名称:tapioca,代码行数:4,代码来源:test_rest_api.py


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