django unittest with post not working

22 views
Skip to first unread message

JAMES DAMILD ETIENNE

unread,
Feb 4, 2016, 5:32:12 PM2/4/16
to Django users
Hi ,  will some help with this please ,
I am writting a django unittest for  a web app. when i do a post  like that :   




r = self.client.post(reverse('login'), {'username': 'te...@hotmail.com', 'password': '12345'})
print 'logins page load>>', r.status_code

the status code returns 302. it's that normal ?

after i try to add some data to the create view like this :


def test_brand_create(self):
r = self.client.get(reverse('brand_new'), follow=True)
self.assertEqual(r.status_code, 200, msg="brand_new Page loads")
print 'brand_new loads >>>',r.status_code

r = self.client.post(brand/new/', {'name': 'poko'})
print 'brand new post>>>' ,r.status_code


brand = Brand.objects.get(name='poko') ( this doesn't return anything error:>>> (DoesNotExist: Brand matching query does not exist.) it seems that the values didn't get posted via the url )

self.assertIsNotNone(brand, msg="brand object created")
print "brand object created>>>",brand


any idea what am doing wrong ?

Dheerendra Rathor

unread,
Feb 4, 2016, 6:46:34 PM2/4/16
to Django users
302 looks Okay as you're being redirect to LOGIN_REDIRECT_URL. 

During posting new branch, start your URL with `/` like
 r = self.client.post('/brand/new/', {'name': 'poko'})

--
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...@googlegroups.com.
To post to this group, send email to django...@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/90d21384-c1f4-4622-be1e-738682cc529e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

JAMES DAMILD ETIENNE

unread,
Feb 5, 2016, 11:19:39 AM2/5/16
to Django users

Yes but it stillnot saving the data after posting :/
Reply all
Reply to author
Forward
0 new messages