def post(self, url, query_string=None, post={}, headers={}, files={}, status=None): kw = dict(query_string=query_string, headers=headers, post=post, files=files) kw["assert_"] = get_assert(status) return Client.post(self, url, **kw)
def test_view_any(): config = morepath.setup() app = morepath.App(testing_config=config) @app.path(path='') class Model(object): def __init__(self): pass @app.view(model=Model, request_method=morepath.ANY) def default(self, request): return "View" config.commit() c = Client(app) response = c.get('/') assert response.body == 'View' response = c.post('/') assert response.body == 'View'
def test_view_predicates(): config = setup() app = App(testing_config=config) @app.path(path="") class Root(object): pass @app.view(model=Root, name="foo", request_method="GET") def get(self, request): return "GET" @app.view(model=Root, name="foo", request_method="POST") def post(self, request): return "POST" config.commit() c = Client(app) response = c.get("/foo") assert response.body == "GET" response = c.post("/foo") assert response.body == "POST"
""" uploading files example """ from webobtoolkit.client import Client, client_pipeline from webob import Request, Response def application(environ, start_response): """this application merely spits out the keys of the form that was posted. we are using webob Request and Response for brevity """ request = Request(environ) return Response(str(request.POST.keys()))(environ, start_response) client = Client(pipeline=client_pipeline(application)) print client.post("/", files=dict(file1=("myfile.txt", "this is a file containing this text")))
""" passing parameters as a form post """ from webobtoolkit.client import Client client = Client() def assert_success(request, response): """ if response status != 200 then raise an error """ if response.status_int != 200: raise Exception("Did not get a valid response from %s" % request.url) print client.post("http://ajax.googleapis.com/ajax/services/search/web", post=dict(v="1.0", q="define: HTTP"), assert_=assert_success)
def post(self, url, query_string=None, post={}, headers={}, files={}, status=None): kw = dict(query_string=query_string, headers=headers, post=post, files=files) kw["assert_"] = get_assert(status) return Client.post(self, url, **kw)
""" uploading files example """ from webobtoolkit.client import Client, client_pipeline from webob import Request, Response def application(environ, start_response): """this application merely spits out the keys of the form that was posted. we are using webob Request and Response for brevity """ request = Request(environ) return Response(str(request.POST.keys()))(environ, start_response) client = Client(pipeline=client_pipeline(application)) print client.post("/", files=dict(file1=("myfile.txt", "this is a file containing this text")))