From f17dcd02e56291066c255417a2d72faeae1b02b3 Mon Sep 17 00:00:00 2001 From: Anton Prokhorov Date: Fri, 29 Dec 2017 17:52:21 +0700 Subject: [PATCH 1/2] Add data passing through `CBVTestCase.get` --- test_plus/test.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/test_plus/test.py b/test_plus/test.py index d658d2e..28ae7cf 100644 --- a/test_plus/test.py +++ b/test_plus/test.py @@ -417,10 +417,11 @@ def get(self, cls, *args, **kwargs): Calls cls.get() method after instantiating view class. Renders view templates and sets context if appropriate. """ + data = kwargs.pop('data', None) instance = self.get_instance(cls, *args, **kwargs) if not instance.request: # Use a basic request - instance.request = RequestFactory().get('/') + instance.request = RequestFactory().get('/', data) self.last_response = self.get_response(instance.request, instance.get) self.context = self.last_response.context return self.last_response From 8c91106594917749acea645445fcd4472ffdac90 Mon Sep 17 00:00:00 2001 From: Anton Prokhorov Date: Fri, 29 Dec 2017 18:05:29 +0700 Subject: [PATCH 2/2] Add `data` in `test_get_request_attributes` --- test_project/test_app/tests.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/test_project/test_app/tests.py b/test_project/test_app/tests.py index 75b01ea..810a7f2 100644 --- a/test_project/test_app/tests.py +++ b/test_project/test_app/tests.py @@ -433,10 +433,13 @@ def test_get_request_attributes(self): # add custom attribute request.some_data = 5 + data = {'some_data_key': 'some_data_value'} + self.get( CBDataView, request=request, pk=self.data.pk, + data=data, ) # view copies `request.some_data` into context if present self.assertContext('some_data', 5)