my view's code looks like that:
if self.request.POST.get('is_useful'):
help_obj = get_object_or_404(Help, pk=self.kwargs['pk'], answer_to__author__username=self.request.POST.get('sender'))
help_obj.useful = True
print(help_obj)
help_obj.save()
print(help_obj)
response = json.dumps({'message': 'marked as useful help!'})
I'm testing it using this:
def test_logged_user_can_mark_help_as_useful(self):
self.client.login(username='bunny', password='pass')
response = self.client.post(reverse('questions:edit-help', kwargs={'pk': 1}), {'is_useful': True, 'sender': 'bunny'})
content = json.loads(response.content)
print(self.help1)
self.assertTrue('useful' in content['message'])
self.assertTrue(self.help1.useful)
The problem is that self.assertTrue(self.help1.useful) does not pass, regardless of help_obj.useful = True in the view. Each of the print operations show that the help object has ID 1 and it's the only object made for testing.
That first assertion passes.
Any help would be appreciated. Thanks!