Thursday, July 27, 2017

Getting response code 302 instead of 200 while testing a url

I have a django named blog and trying to test the url. The code for testing is :-

class PostTests(TestCase):

    def setUp(self):
        self.user = get_user_model().objects.create(username='some_user')
        self.title = "test-title"
        Post.objects.create(
            title=self.title, user=self.user,
            publish=datetime.date.today()
        )

    def test_post_list(self):
        response = self.client.get('/posts/search/')
        self.assertEqual(response.status_code, 200)

    def test_post_create(self):
        response = self.client.get('/posts/create/')
        self.assertEqual(response.status_code, 200)

    def test_post_update(self):
        response = self.client.get('/posts/test-title/update/')
        self.assertEqual(response.status_code, 200)

    def test_post_delete(self):
        response = self.client.get('/posts/test-title/delete/')
        self.assertEqual(response.status_code, 200)





The problem here is that my test cased passed for the first 2 functions i.e. "test_post_list" and "test_post_create" but now working for other two test functions i.e "test_post_update" and "test_post_delete". What might be the problem ?

The setup function that i made is supposed to create a object of model named "Post", then what might be the problem ?

--
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+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@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/cc9da776-d6bd-408d-bab9-e6b0d8ba0cd2%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment