'Django valid_form() in UpdateView() not passing coverage report Unittest
So i been trying to write a test for the form_valid() method of this view as you can see below But despited all the necessary assertions i've put in the test,it still fails to pass the coverage report and i can't see what exactly i might be missing in my test.
class CrView(UpdateView):
model = Model
form_class = Form_
def get_context_data(self, **kwargs):
data = super().get_context_data(**kwargs)
........
@transaction.atomic()
def form_valid(self, form):
context = self.get_context_data()
items = context["items"]
if items.is_valid():
items.instance = self.object
items.save()
return super().form_valid(form)
else:
return self.form_invalid(form)
Unittest : Which all passes just fine
class TestsView(TestCase):
def test_post(self):
response_post = self.client.post(self.url, data={
'string_set-TOTAL_FORMS': 1,
'string_set-INITIAL_FORMS': 0,
'string_set-MIN_NUM_FORMS': 0,
'string_set-MAX_NUM_FORMS': 1000,
'string_set-0-string': 'test',
'string_set-0-page': self.page.uuid,
})
response_post_context= response_post.context['items']
response_post_context.save(
commit=True
)
# response_post_context = self.object
self.assertEqual(response_post.status_code, 200)
import pdb; pdb.set_trace()
self.assertTrue(response_post_context.is_valid())
self.assertEqual(response_post_context.instance, self.page)
self.assertEqual(response_post_context.instance.number, 1)
self.assertEqual(response_post_context.instance.pdf, self.pdf)
self.assertEqual(response_post_context.instance.uuid, self.page.uuid)
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
