Skip to content

Commit

Permalink
add recipe for using cURL to test post requests
Browse files Browse the repository at this point in the history
  • Loading branch information
mcdonc committed Jul 1, 2011
1 parent b8c6521 commit 2d39851
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 0 deletions.
1 change: 1 addition & 0 deletions index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ The Pyramid Cookbook presents topical, practical usages of :mod:`Pyramid`.
events
deployment/index.rst
porting
testing
cmf/index.rst
mac_install
glossary
Expand Down
44 changes: 44 additions & 0 deletions testing.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
Testing a POST Request Using cURL
---------------------------------

Using the following Pyramid application:

.. code-block:: python
from pyramid.view import view_config
@view_config(route_name='theroute', renderer='string',
request_method='POST')
def myview(request):
print request.GET.items()
print request.POST.items()
print request.params.items()
return 'OK'
if __name__ == '__main__':
from pyramid.config import Configurator
from paste.httpserver import serve
config = Configurator()
config.add_route('theroute', '/')
config.scan('__main__')
serve(config.make_wsgi_app())
Once your run the above application, you can test a POST request to the
application via ``curl`` (available on most UNIX systems):

.. code-block: text
$ curl -d "param1=value1&param2=value2" http://localhost:8080/?param3=value3
You'll see the following output on the application terminal:

.. code-block:: text
[('param3', u'value3')]
[('param1', u'value1'), ('param2', u'value2')]
[('param3', u'value3'), ('param1', u'value1'), ('param2', u'value2')]
Note the relationship between the query string and ``request.GET``. Note the
relationship between the POST body values (provided as the argument to the
``-d`` flag of ``curl``) and ``request.POST``. Note that ``request.params``
is an amalgamation of ``request.GET`` and ``request.POST`` values.

0 comments on commit 2d39851

Please sign in to comment.