Hi Guys,

Any leads would be appreciated


On Wed, Feb 12, 2020 at 6:22 PM onlinejudge95 <onlinejudg...@gmail.com>
wrote:

> Hi Devs,
>
> I was implementing unit-tests in my Django project and stumbled upon the
> following issue.
>
> I want to unit-test my POST route. I do not want to use the test client
> already shipped with Django (using it in my e2e tests). I want to know how
> do I prepare my request object to pass to my view. Here is what I have done
> currently.
>
> test_views.py
>
>> class CreateBlogTest(BaseViewTest):
>
>     @classmethod
>>     def setUpClass(cls):
>>         cls.request.method = "POST"
>
>     def test_create_valid_blog(self):
>>         self.request.content_type = "application/json"
>>         self.request._body = json.dumps({"title": "new title", "body":
>> "new body"})
>>
>>         response = views.blog_collection(self.request)
>>         self.assertEqual(response.status_code, 201)
>>
>
> In my view, I am accessing the data through *request.data* and passing it
> to a serializer.
>
> In my current setting, I am getting a 400 error message when I have
> checked that the user does not exist.
>
> Any suggestions regarding the same?
>
> Thanks,
> onlinejudge95
>

-- 
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 view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAD%3DM5eS3nFRxHm_aSqSt8YxFhaZGahF%3DP6Uj0Zco7wafM1%2BHOQ%40mail.gmail.com.

Reply via email to