Authorization through POST forms

31 views
Skip to first unread message

Diego

unread,
Apr 19, 2011, 11:38:45 PM4/19/11
to django-piston
I'm currently using Piston to create my Restful API and recently came
up with a few questions.

When I tried unit testing my create using a form with the POST method,
I came across the CSRF error. That's when I figured out I need to
actually authenticate myself before I try to perform these unit
tests.

1. For unit testing is html forms a good way to go?

2. Can someone point me to a good resource to get authentication
working and how to actually get authenticated? Most of the resources I
found online were mostly of code and not too much of how to actually
authenticate my session to make a request.

I recently started working with Django.

Best Regards,

Chris Wesseling

unread,
Apr 20, 2011, 6:01:08 AM4/20/11
to django...@googlegroups.com
On 2011-04-19T20:38:45-0700, Diego wrote:
> When I tried unit testing my create using a form with the POST method,
> I came across the CSRF error. That's when I figured out I need to
> actually authenticate myself before I try to perform these unit
> tests.
>
> 1. For unit testing is html forms a good way to go?

For testing the serveral verbs on your api, the
utils.unittest.TestCase.client[1]_ should be enough.

For integrationtesting with your front-end stuff, I'd take a look at
windmill[2]_ . It provides a way to put the windmilltests in a test in
the default Django testrunner.

> 2. Can someone point me to a good resource to get authentication
> working and how to actually get authenticated? Most of the resources I
> found online were mostly of code and not too much of how to actually
> authenticate my session to make a request.

Do you mean while testing or just getting any authentication in your api
app?

> I recently started working with Django.

Have fun,

.. [1] http://docs.djangoproject.com/en/1.3/topics/testing/#django.test.TestCase.client
-- [2] http://www.getwindmill.com

--
Chris
--
A: No.
Q: Should I include quotations after my reply?

Diego

unread,
Apr 24, 2011, 5:50:05 PM4/24/11
to django-piston
I was able to figure out how to remove the CSRF error by using a CSRF
exempt hanlder.

I mainly am looking for a resource to figure out how to get an API
user to authenticate his calls. So far I only see how curl is used in
the documentation. What if the user has to do this using PHP/
Javascript? In POST are they sent as additional arguments?
> .. [1]http://docs.djangoproject.com/en/1.3/topics/testing/#django.test.Test...
Reply all
Reply to author
Forward
0 new messages