Re: Best approach to write unit tests involving rest apis.

2015-12-03 Thread Xavier Ordoquy

> Le 3 déc. 2015 à 08:08, learn django  > a écrit :
> 
>  On Wednesday, December 2, 2015 at 10:48:52 PM UTC-8, Xavier Ordoquy wrote:
> Hi, 
> 
> > Le 3 déc. 2015 à 00:12, learn django  
> > a écrit : 
> > 
> > My app uses rest framework. 
> > I am writing test cases which involve standard requests like 
> > GET/POST/DELETE/PUT. 
> > What is the best approach to write the test cases ? 
> 
> Django REST framework comes with a test client named APIClient. 
> It will go through the middleware and urls before calling your API entry 
> points which seems to be what you’re looking for. 
> The documentation about it is available at 
> http://www.django-rest-framework.org/api-guide/testing/#apiclient 
>  
> 
> 
> Hi Linovia,
> 
> Yes, I started with that.
> Initially I was getting 403 (auth failure) since my backend handlers have 
> @login_required decorator.

This may be an issue since a Django REST framework view shouldn’t use this 
decorator.
If it is a regular Django view that returns a JSON response, then you should 
consider using the Django client directly.

> To overcome that i created a super user (python manage.py superuser) &
> used those credentials as below.
> 
> # url = '/orca/api/v2/customer/'
> # data = {'c_name':'Pnc', 'c_role':'API-Admin'}
> # client = APIClient()
> # client.login(username='admin', password='admin')
> # response = client.post(url, data, format='json') 
> 
> After this I started was getting 302 (redirects).
> Have you encountered similar issue before ?

Where does it redirects you to ? If it’s the login page, it means that somehow 
the login call didn’t work.

Regards,
Xavier,
Linovia.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/1E2EC51D-42E8-4654-8ABE-57D5F5479128%40linovia.com.
For more options, visit https://groups.google.com/d/optout.


Re: Best approach to write unit tests involving rest apis.

2015-12-02 Thread learn django
 On Wednesday, December 2, 2015 at 10:48:52 PM UTC-8, Xavier Ordoquy wrote:
>
> Hi, 
>
> > Le 3 déc. 2015 à 00:12, learn django  > a écrit : 
> > 
> > My app uses rest framework. 
> > I am writing test cases which involve standard requests like 
> GET/POST/DELETE/PUT. 
> > What is the best approach to write the test cases ? 
>
> Django REST framework comes with a test client named APIClient. 
> It will go through the middleware and urls before calling your API entry 
> points which seems to be what you’re looking for. 
> The documentation about it is available at 
> http://www.django-rest-framework.org/api-guide/testing/#apiclient 
>
> Regards, 
> Xavier, 
> Linovia. 
>
>
Hi Linovia,

Yes, I started with that.
Initially I was getting 403 (auth failure) since my backend handlers have 
@login_required decorator.

To overcome that i created a super user (python manage.py superuser) &
used those credentials as below.

# url = '/orca/api/v2/customer/'
# data = {'c_name':'Pnc', 'c_role':'API-Admin'}
# client = APIClient()
# client.login(username='admin', password='admin')
# response = client.post(url, data, format='json') 

After this I started was getting 302 (redirects).
Have you encountered similar issue before ?

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/d0dab1a9-6b99-462b-911e-f098a4aea79e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Best approach to write unit tests involving rest apis.

2015-12-02 Thread Xavier Ordoquy
Hi,

> Le 3 déc. 2015 à 00:12, learn django  a écrit :
> 
> My app uses rest framework.
> I am writing test cases which involve standard requests like 
> GET/POST/DELETE/PUT.
> What is the best approach to write the test cases ?

Django REST framework comes with a test client named APIClient.
It will go through the middleware and urls before calling your API entry points 
which seems to be what you’re looking for.
The documentation about it is available at 
http://www.django-rest-framework.org/api-guide/testing/#apiclient

Regards,
Xavier,
Linovia.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/C9F5286E-8261-47C3-8F0C-959EBF267E49%40linovia.com.
For more options, visit https://groups.google.com/d/optout.


signature.asc
Description: Message signed with OpenPGP using GPGMail