How do I validate django UpdateView correctly?

I have the following unit test

def test_category_update_view(self):
    """
    Make sure that a category can be updated
    :return: 
    """
    self.log_user_1_in()

    self.assertEqual('Bacon', self.category.name)

    res = self.client.put(
        reverse(
            'calendars:categories:edit_category',
            kwargs={'calendar_pk': self.calendar.id, 'pk': self.category.id}
        ),
        urlencode({'name': 'bacon is yummy'})
    )

    self.assertEqual('bacon is yummy', self.category.name)

    self.assertEqual(302, res.status_code)
    self.assertEqual(
        reverse('calendars:categories:category_list', kwargs={'calendar_pk': self.calendar.id}),
        res.url
    )

      

enter image description here

As you can see the form is invalid, so my question is why is it invalid? Should the test client use the data I gave him? My POST request done in the same way works fine and passes the correct data.

I haven't been writing lately, so forgive me if this is a little vague. If you need more information to help me please let me know.

+3


source to share


1 answer


Shouldn't you use self.client.post and not self.client.put?



0


source







All Articles