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


Python TestApp.put方法代码示例

本文整理汇总了Python中webtest.TestApp.put方法的典型用法代码示例。如果您正苦于以下问题:Python TestApp.put方法的具体用法?Python TestApp.put怎么用?Python TestApp.put使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在webtest.TestApp的用法示例。


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

示例1: AuthenticationTests

# 需要导入模块: from webtest import TestApp [as 别名]
# 或者: from webtest.TestApp import put [as 别名]
class AuthenticationTests(unittest.TestCase):

    def setUp(self):
        app = wp_frontend.main({}, 
                               sql_init_function=tests.init_db, 
                               **tests.settings)
        self.testapp = TestApp(app)

    def tearDown(self):
        del self.testapp
        tests.getSession().remove()

    def test_login_and_logout(self):
        self.testapp.put('/login', valid_credentials, status=302)
        res = self.testapp.get('/home')
        self.assertNotIn('input type="password"', res.body)
        self.testapp.get('/logout')
        res = self.testapp.get('/home')
        self.assertIn('input type="password"', res.body)
        
    def test_failed_log_in(self):
        invalid_credentials = { 'user': 'invalid_user',
                                'password': 'invalid_password',
                                'came_from': '/',
                                'submit': '', }
        res = self.testapp.put('/login', invalid_credentials, status=200)
        res = self.testapp.get('/home')
        self.assertIn('input type="password"', res.body)

    def test_garbage_log_in(self):
        garbage_credentials = {'foo': 'baz', 'submit': ''}
        res = self.testapp.put('/login', garbage_credentials, status=200)
        self.assertIn('input type="password"', res.body)
        self.assertIn('There was a problem with your submission', res.body)
开发者ID:fuzzy-id,项目名称:wp_frontend,代码行数:36,代码来源:__init__.py

示例2: test_users_put_same_twice

# 需要导入模块: from webtest import TestApp [as 别名]
# 或者: from webtest.TestApp import put [as 别名]
    def test_users_put_same_twice(self):
        """
        try to register the same user twice; must fail!
        """
        app = TestApp(main({}))
        _name = 'john'
        _namejson = json.dumps({'name': _name})
        res = app.put('/users', _namejson)
        # check response
        self.assertTrue("token" in str(res.body))  # did get a token
        self.assertTrue(_name in str(res.body))  # name found
        # do it again, try to register user of same name
        # expect "Bad Request (400)"
        res2 = app.put('/users', _namejson, status=400)
        #print(res2)
# {"status": "error",
#  "errors": [{
#      "location": "url",
#      "name": "name",
#      "description": "This user exists!"}]}
        _json2 = json.loads(res2.body)
        #print(_json2['status'])
        self.assertTrue(
            'error' in _json2['status'])
        self.assertTrue(
            'This user exists!' in _json2['errors'][0]['description'])
开发者ID:C3S,项目名称:c3s.app.restapi,代码行数:28,代码来源:test_views.py

示例3: test_custom_with_trailing_slash

# 需要导入模块: from webtest import TestApp [as 别名]
# 或者: from webtest.TestApp import put [as 别名]
    def test_custom_with_trailing_slash(self):

        class CustomController(RestController):

            _custom_actions = {
                'detail': ['GET'],
                'create': ['POST'],
                'update': ['PUT'],
                'remove': ['DELETE'],
            }

            @expose()
            def detail(self):
                return 'DETAIL'

            @expose()
            def create(self):
                return 'CREATE'

            @expose()
            def update(self, id):
                return id

            @expose()
            def remove(self, id):
                return id

        app = TestApp(make_app(CustomController()))

        r = app.get('/detail')
        assert r.status_int == 200
        assert r.body == b_('DETAIL')

        r = app.get('/detail/')
        assert r.status_int == 200
        assert r.body == b_('DETAIL')

        r = app.post('/create')
        assert r.status_int == 200
        assert r.body == b_('CREATE')

        r = app.post('/create/')
        assert r.status_int == 200
        assert r.body == b_('CREATE')

        r = app.put('/update/123')
        assert r.status_int == 200
        assert r.body == b_('123')

        r = app.put('/update/123/')
        assert r.status_int == 200
        assert r.body == b_('123')

        r = app.delete('/remove/456')
        assert r.status_int == 200
        assert r.body == b_('456')

        r = app.delete('/remove/456/')
        assert r.status_int == 200
        assert r.body == b_('456')
开发者ID:alex-devops,项目名称:pecan,代码行数:62,代码来源:test_rest.py

示例4: FunctionalTest

# 需要导入模块: from webtest import TestApp [as 别名]
# 或者: from webtest.TestApp import put [as 别名]
class FunctionalTest(unittest.TestCase):
    def setUp(self):
        self.app = TestApp(application) 

    def test_index_returns_200(self):  
        response = self.app.get('/', expect_errors=True)        
        self.assertEquals("200 OK", response.status)
            
    def test_index_return_correct_mime_type(self):
        response = self.app.get('/', expect_errors=True)
        self.assertEquals(response.content_type, "text/html")
        
    def test_multiple_args_in_url(self):
        response = self.app.get('/foo/1/2', expect_errors=True)        
        response.mustcontain("Hello World of 1 and 2")

    def test_put(self):
        response = self.app.put('/', expect_errors=True)        
        self.assertEquals("200 OK", response.status)
        response.mustcontain("Hello World of Put")
        
    def test_404_handler(self):  
        response = self.app.get('/does-not-exist', expect_errors=True)        
        self.assertEquals("404 Not Found", response.status)

    def test_404_handler(self):  
        response = self.app.get('/does-not-exist', expect_errors=True)        
        self.assertEquals("404 Not Found", response.status)

    def test_HTTPResponseRedirect_handler(self):
        response = self.app.get('/bar', expect_errors=True)        
        self.assertEquals("/", response.headers['Location'])
        self.assertEquals("301 Moved Permanently", response.status)

    def test_temporaty_HTTPResponseRedirect_handler(self):
        response = self.app.delete('/bar', expect_errors=True)        
        self.assertEquals("/", response.headers['Location'])
        self.assertEquals("302 Found", response.status)

    def test_unregistered_post_request(self):
        response = self.app.post('/', expect_errors=True)        
        self.assertEquals("405 Method Not Allowed", response.status)

    def test_unregistered_delete_request(self):
        response = self.app.delete('/', expect_errors=True)        
        self.assertEquals("405 Method Not Allowed", response.status)

    def test_unregistered_put_request(self):
        response = self.app.put('/bar', expect_errors=True)        
        self.assertEquals("405 Method Not Allowed", response.status)

    def test_query_string(self):  
        response = self.app.get('/?test=test', expect_errors=True)        
        self.assertEqual("test", response.request.GET['test'])
        self.assertEquals("200 OK", response.status)

    def test_addition_of_method_to_request(self):  
        response = self.app.get('/', expect_errors=True)        
        self.assertEqual("GET", response.request.method)
开发者ID:GaretJax,项目名称:mnml,代码行数:61,代码来源:functional.py

示例5: test_accept

# 需要导入模块: from webtest import TestApp [as 别名]
# 或者: from webtest.TestApp import put [as 别名]
    def test_accept(self):
        # tests that the accept headers are handled the proper way
        app = TestApp(main({}))

        # requesting the wrong accept header should return a 406 ...
        response = app.get("/service2", headers={"Accept": "audio/*"}, status=406)

        # ... with the list of accepted content-types
        error_location = response.json["errors"][0]["location"]
        error_name = response.json["errors"][0]["name"]
        error_description = response.json["errors"][0]["description"]
        self.assertEquals("header", error_location)
        self.assertEquals("Accept", error_name)
        self.assertIn("application/json", error_description)
        self.assertIn("text/json", error_description)
        self.assertIn("text/plain", error_description)

        # requesting a supported type should give an appropriate response type
        response = app.get("/service2", headers={"Accept": "application/*"})
        self.assertEqual(response.content_type, "application/json")

        response = app.get("/service2", headers={"Accept": "text/plain"})
        self.assertEqual(response.content_type, "text/plain")

        # it should also work with multiple Accept headers
        response = app.get("/service2", headers={"Accept": "audio/*, application/*"})
        self.assertEqual(response.content_type, "application/json")

        # and requested preference order should be respected
        headers = {"Accept": "application/json; q=1.0, text/plain; q=0.9"}
        response = app.get("/service2", headers=headers)
        self.assertEqual(response.content_type, "application/json")

        headers = {"Accept": "application/json; q=0.9, text/plain; q=1.0"}
        response = app.get("/service2", headers=headers)
        self.assertEqual(response.content_type, "text/plain")

        # test that using a callable to define what's accepted works as well
        response = app.get("/service3", headers={"Accept": "audio/*"}, status=406)
        error_description = response.json["errors"][0]["description"]
        self.assertIn("text/json", error_description)

        response = app.get("/service3", headers={"Accept": "text/*"})
        self.assertEqual(response.content_type, "text/json")

        # Test that using a callable to define what's accepted works as well.
        # Now, the callable returns a scalar instead of a list.
        response = app.put("/service3", headers={"Accept": "audio/*"}, status=406)
        error_description = response.json["errors"][0]["description"]
        self.assertIn("text/json", error_description)

        response = app.put("/service3", headers={"Accept": "text/*"})
        self.assertEqual(response.content_type, "text/json")

        # If we are not asking for a particular content-type,
        # we should get one of the two types that the service supports.
        response = app.get("/service2")
        self.assertIn(response.content_type, ("application/json", "text/plain"))
开发者ID:mozilla-services,项目名称:cornice,代码行数:60,代码来源:test_validation.py

示例6: test_singular_resource

# 需要导入模块: from webtest import TestApp [as 别名]
# 或者: from webtest.TestApp import put [as 别名]
    def test_singular_resource(self, *a):
        View = get_test_view_class()
        config = _create_config()
        root = config.get_root_resource()
        root.add('thing', view=View)
        grandpa = root.add('grandpa', 'grandpas', view=View)
        wife = grandpa.add('wife', view=View, renderer='string')
        wife.add('child', 'children', view=View)

        config.begin()
        app = TestApp(config.make_wsgi_app())

        self.assertEqual(
            '/grandpas/1/wife',
            route_path('grandpa:wife', testing.DummyRequest(), grandpa_id=1)
        )

        self.assertEqual(
            '/grandpas/1',
            route_path('grandpa', testing.DummyRequest(), id=1)
        )

        self.assertEqual(
            '/grandpas/1/wife/children/2',
            route_path('grandpa_wife:child', testing.DummyRequest(),
                       grandpa_id=1, id=2)
        )

        self.assertEqual(app.put('/grandpas').body, six.b('update_many'))
        self.assertEqual(app.head('/grandpas').body, six.b(''))
        self.assertEqual(app.options('/grandpas').body, six.b(''))

        self.assertEqual(app.delete('/grandpas/1').body, six.b('delete'))
        self.assertEqual(app.head('/grandpas/1').body, six.b(''))
        self.assertEqual(app.options('/grandpas/1').body, six.b(''))

        self.assertEqual(app.put('/thing').body, six.b('replace'))
        self.assertEqual(app.patch('/thing').body, six.b('update'))
        self.assertEqual(app.delete('/thing').body, six.b('delete'))
        self.assertEqual(app.head('/thing').body, six.b(''))
        self.assertEqual(app.options('/thing').body, six.b(''))

        self.assertEqual(app.put('/grandpas/1/wife').body, six.b('replace'))
        self.assertEqual(app.patch('/grandpas/1/wife').body, six.b('update'))
        self.assertEqual(app.delete('/grandpas/1/wife').body, six.b('delete'))
        self.assertEqual(app.head('/grandpas/1/wife').body, six.b(''))
        self.assertEqual(app.options('/grandpas/1/wife').body, six.b(''))

        self.assertEqual(six.b('show'), app.get('/grandpas/1').body)
        self.assertEqual(six.b('show'), app.get('/grandpas/1/wife').body)
        self.assertEqual(
            six.b('show'), app.get('/grandpas/1/wife/children/1').body)
开发者ID:mbijon,项目名称:nefertari,代码行数:54,代码来源:test_resource.py

示例7: test_accept_and_content_type

# 需要导入模块: from webtest import TestApp [as 别名]
# 或者: from webtest.TestApp import put [as 别名]
    def test_accept_and_content_type(self):
        # Tests that using both the "Accept" and "Content-Type"
        # request headers satisfy the requirement.
        app = TestApp(main({}))

        # POST endpoint just has one accept and content_type definition
        response = app.post('/service7', headers={
            'Accept': 'text/xml, application/json',
            'Content-Type': 'application/json; charset=utf-8'
        })
        self.assertEqual(response.json, "some response")

        response = app.post(
            '/service7',
            headers={
                'Accept': 'text/plain, application/json',
                'Content-Type': 'application/json; charset=utf-8'
            },
            status=406)

        response = app.post(
            '/service7',
            headers={
                'Accept': 'text/xml, application/json',
                'Content-Type': 'application/x-www-form-urlencoded'
            },
            status=415)

        # PUT endpoint has a list of accept and content_type definitions
        response = app.put('/service7', headers={
            'Accept': 'text/xml, application/json',
            'Content-Type': 'application/json; charset=utf-8'
        })
        self.assertEqual(response.json, "some response")

        response = app.put(
            '/service7',
            headers={
                'Accept': 'audio/*',
                'Content-Type': 'application/json; charset=utf-8'
            },
            status=406)

        response = app.put(
            '/service7',
            headers={
                'Accept': 'text/xml, application/json',
                'Content-Type': 'application/x-www-form-urlencoded'
            }, status=415)
开发者ID:openprocurement,项目名称:cornice,代码行数:51,代码来源:test_validation.py

示例8: TestShield

# 需要导入模块: from webtest import TestApp [as 别名]
# 或者: from webtest.TestApp import put [as 别名]
class TestShield(unittest.TestCase):

    def setUp(self):
        self.app = TestApp(application)

    def test_shields(self):
        response = self.app.post_json('/api/_login', {"username": "felipe", "password": '123'})
        self.assertEqual(200, response.status_int)

        response = self.app.get('/api/person/')
        self.assertEqual(200, response.status_int)

        self.app = TestApp(application)
        response = self.app.get('/api/person', expect_errors=True)
        self.assertEquals(401, response.status_int)

        self.app = TestApp(application)
        response = self.app.post('/api/person/', expect_errors=True)
        self.assertIsNot(401, response.status_int)

        self.app = TestApp(application)
        response = self.app.put('/api/person/', expect_errors=True)
        self.assertIsNot(404, response.status_int)

        self.app = TestApp(application)
        response = self.app.delete('/api/person/', expect_errors=True)
        self.assertIsNot(404, response.status_int)
开发者ID:felipevolpone,项目名称:ray,代码行数:29,代码来源:test_shield.py

示例9: test_content_type_with_callable_returning_scalar

# 需要导入模块: from webtest import TestApp [as 别名]
# 或者: from webtest.TestApp import put [as 别名]
 def test_content_type_with_callable_returning_scalar(self):
     # Test that using a callable for content_type works as well.
     # Now, the callable returns a scalar instead of a list.
     app = TestApp(main({}))
     response = app.put("/service6", headers={"Content-Type": "audio/*"}, status=415)
     error_description = response.json["errors"][0]["description"]
     self.assertIn("text/xml", error_description)
开发者ID:mozilla-services,项目名称:cornice,代码行数:9,代码来源:test_validation.py

示例10: test_users_delete

# 需要导入模块: from webtest import TestApp [as 别名]
# 或者: from webtest.TestApp import put [as 别名]
    def test_users_delete(self):
        """
        register a username, get an auth token, delete user again
        idea: register second user to check
        """
        app = TestApp(main({}))
        _name = "mary"
        res = app.put("/users", _name, status=200)
        self.assertTrue("application/json; charset=UTF-8" in res.headers["Content-Type"])
        # store the body as json
        _json = json.loads(res.body)
        # print(_json['token'])
        self.assertTrue("0.1dev" in _json["api-version"])
        self.assertTrue(_name in str(_json["token"]))

        _token = _json["token"]
        # print("the token from res: " + _token)

        # try using an invalid token: get coverage for the valid_token function
        _invalid_token = _token.replace("-", "")  # removing the '-'
        # print("_invalid_token: " + _invalid_token)
        _auth_header = {"X-Messaging-Token": str(_invalid_token)}
        # calling with the invalid_token we expect 401: Unauthorized
        res2 = app.delete_json("/users", params=_name, headers=_auth_header, status=401)

        _auth_header = {"X-Messaging-Token": str(_token)}
        # now we have a token and can authenticate... and delete the user

        # delete the user
        # res2 = app.delete('/users', params=_name,
        res2 = app.delete_json("/users", params=_name, headers=_auth_header, status=200)
        # print(res2)
        self.assertTrue("goodbye" in json.loads(res2.body).keys())
        self.assertTrue(_name in json.loads(res2.body).values())
开发者ID:AnneGilles,项目名称:c3s.app.restapi,代码行数:36,代码来源:test_views.py

示例11: test_users_put

# 需要导入模块: from webtest import TestApp [as 别名]
# 或者: from webtest.TestApp import put [as 别名]
    def test_users_put(self):
        """
        register a username, get an auth token, use it to get list of users
        """
        app = TestApp(main({}))
        _name = "heinzi"
        res = app.put("/users", _name, status=200)
        # print(res)  # uncomment to see the following output:
        # Content-Type: application/json; charset=UTF-8
        # {"api-version": "0.1dev",
        #  "token": "heinz-2354ed39ba5def1aef9f8a11997d8833df691f25"}
        self.assertTrue("application/json; charset=UTF-8" in res.headers["Content-Type"])
        # store the body as json
        _json = json.loads(res.body)
        # print(_json['api-version'])
        self.assertTrue("0.1dev" in _json["api-version"])
        self.assertTrue(_name in str(_json["token"]))

        _token = _json["token"]
        # print("the token from res: " + _token)
        _auth_header = {"X-Messaging-Token": str(_token)}
        # now we have a token and can authenticate...
        res2 = app.get("/users", headers=_auth_header, status=200)

        # print(res2)
        # Response: 200 OK
        # Content-Type: application/json; charset=UTF-8
        # {"users": ["heinz"]}
        self.assertTrue("application/json; charset=UTF-8" in res2.headers["Content-Type"])
        # store the body as json
        _json = json.loads(res2.body)
        # self.assertTrue('0.1dev' in _json['api-version'])
        self.assertTrue(_name in (_json["users"]))
开发者ID:AnneGilles,项目名称:c3s.app.restapi,代码行数:35,代码来源:test_views.py

示例12: test_bad_rest

# 需要导入模块: from webtest import TestApp [as 别名]
# 或者: from webtest.TestApp import put [as 别名]
    def test_bad_rest(self):

        class ThingsController(RestController):
            pass

        class RootController(object):
            things = ThingsController()

        # create the app
        app = TestApp(make_app(RootController()))

        # test get_all
        r = app.get('/things', status=404)
        assert r.status_int == 404

        # test get_one
        r = app.get('/things/1', status=404)
        assert r.status_int == 404

        # test post
        r = app.post('/things', {'value': 'one'}, status=404)
        assert r.status_int == 404

        # test edit
        r = app.get('/things/1/edit', status=404)
        assert r.status_int == 404

        # test put
        r = app.put('/things/1', {'value': 'ONE'}, status=404)

        # test put with _method parameter and GET
        r = app.get('/things/1?_method=put', {'value': 'ONE!'}, status=405)
        assert r.status_int == 405

        # test put with _method parameter and POST
        r = app.post('/things/1?_method=put', {'value': 'ONE!'}, status=404)
        assert r.status_int == 404

        # test get delete
        r = app.get('/things/1/delete', status=404)
        assert r.status_int == 404

        # test delete
        r = app.delete('/things/1', status=404)
        assert r.status_int == 404

        # test delete with _method parameter and GET
        r = app.get('/things/1?_method=DELETE', status=405)
        assert r.status_int == 405

        # test delete with _method parameter and POST
        r = app.post('/things/1?_method=DELETE', status=404)
        assert r.status_int == 404

        # test "RESET" custom action
        with warnings.catch_warnings():
            warnings.simplefilter("ignore")
            r = app.request('/things', method='RESET', status=404)
            assert r.status_int == 404
开发者ID:alex-devops,项目名称:pecan,代码行数:61,代码来源:test_rest.py

示例13: WsgiApiTests

# 需要导入模块: from webtest import TestApp [as 别名]
# 或者: from webtest.TestApp import put [as 别名]
class WsgiApiTests(BaseWsgiApiTests):
    @mock_iam
    def test_should_make_role(self):
        result = self.app.put('/role/testrole')
        self.assertEqual(result.status_int, 201)

    def test_status_good_case(self):
        result = self.app.get('/status')
        expected_json = {"status": "200", "message": "OK"}
        self.assertEqual(result.json, expected_json)

    def test_status_bad_case_with_missing_config(self):
        missing_config = os.path.join(self.config_path, "missing_config.yaml")
        env_with_wrong_config_path = {'CONFIG_PATH': missing_config}
        self.app = TestApp(wsgi_api.get_webapp(), extra_environ=env_with_wrong_config_path)

        result = self.app.get('/status', expect_errors=True)

        self.assertEqual(result.status_int, 500)

    def test_should_give_401_return_code(self):
        self.mock_boto_connection.create_role.side_effect = \
            [boto.exception.BotoServerError('', '', {'Error': {"Code": "InvalidClientTokenId"}})]
        result = self.app.put('/role/testrole', expect_errors=True)
        self.assertEqual(result.status_int, 401)

    def test_should_give_509_return_code(self):
        self.mock_boto_connection.create_role.side_effect = \
            [boto.exception.BotoServerError('', '', {'Error': {"Code": "LimitExceeded"}})]
        result = self.app.put('/role/testrole', expect_errors=True)
        self.assertEqual(result.status_int, 509)

    def test_should_give_502_return_code(self):
        self.mock_boto_connection.create_role.side_effect = \
            [boto.exception.BotoServerError('', '', {'Error': {"Code": "CanNotContinueException"}})]
        result = self.app.put('/role/testrole', expect_errors=True)
        self.assertEqual(result.status_int, 502)

    @patch('afp_resource_maker.wsgi.yaml_load')
    def test_load_config_uses_default_path(self, mock_yaml_load):
        env_without_config_path = {}
        self.app = TestApp(wsgi_api.get_webapp(), extra_environ=env_without_config_path)

        wsgi_api.get_config()

        mock_yaml_load.assert_called_with('/etc/afp-resource-maker')
开发者ID:ImmobilienScout24,项目名称:afp-resource-maker,代码行数:48,代码来源:wsgi_tests.py

示例14: test_content_type_with_callable_returning_scalar

# 需要导入模块: from webtest import TestApp [as 别名]
# 或者: from webtest.TestApp import put [as 别名]
 def test_content_type_with_callable_returning_scalar(self):
     # Test that using a callable for content_type works as well.
     # Now, the callable returns a scalar instead of a list.
     app = TestApp(main({}))
     response = app.put('/service6', headers={'Content-Type': 'audio/*'},
                        status=415)
     error_description = response.json['errors'][0]['description']
     self.assertIn('text/xml', error_description)
开发者ID:openprocurement,项目名称:cornice,代码行数:10,代码来源:test_validation.py

示例15: test_content_type_correct

# 需要导入模块: from webtest import TestApp [as 别名]
# 或者: from webtest.TestApp import put [as 别名]
    def test_content_type_correct(self):
        # Tests that the Content-Type request header satisfies the requirement.
        app = TestApp(main({}))

        # Requesting with one of the allowed Content-Type headers should work,
        # even when having a charset parameter as suffix.
        response = app.put("/service5", headers={"Content-Type": "text/plain; charset=utf-8"})
        self.assertEqual(response.json, "some response")
开发者ID:mozilla-services,项目名称:cornice,代码行数:10,代码来源:test_validation.py


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