Call to method that takes in a request

17 views
Skip to first unread message

Yufenyuy Veyeh Didier

unread,
Jun 1, 2018, 7:02:54 AM6/1/18
to Django users
Hello,
I wish to know  how I can call a method that takes in a request as one of its parameters such as 

def get(self, request, pk):

#I am writing a test method to test the above method too.

Julio Biason

unread,
Jun 1, 2018, 7:48:20 AM6/1/18
to django...@googlegroups.com
Hi Yufenyuy,

You just instantiate the object and call the function. Something like

created_object = MyModel(field='some_value')
view = MyView()
view.get(request, created_object.pk)

If you want to create a request object, you can use RequestFactory: https://docs.djangoproject.com/en/2.0/topics/testing/advanced/#the-request-factory


--
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...@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/8740fe0d-e6b3-4caf-b35e-a442ee05e209%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
Julio Biason, Sofware Engineer
AZION  |  Deliver. Accelerate. Protect.
Office: +55 51 3083 8101  |  Mobile: +55 51 99907 0554

Melvyn Sopacua

unread,
Jun 1, 2018, 8:13:44 AM6/1/18
to django...@googlegroups.com

If you want to test a view, use the TestClient.

 

--

Melvyn Sopacua

Reply all
Reply to author
Forward
0 new messages