[Django]-Mock keeps calling real function

4๐Ÿ‘

โœ…

So, searching around and looking some codes on github, I found out that I need to mock from the view even if the function belongs to the use_cases module.

So my code now is:

tests.py

from unittest.mock import patch, Mock

@patch('core.views.add_owner_to_place')
@patch('core.forms.PlaceForm.is_valid')
@patch('core.forms.PlaceForm.save')
def test_save_should_be_called(self, mocked_save, mocked_is_valid, mocked_add_owner_to_place):
    self.client.post(reverse('place_create'), data={})
    self.assertTrue(mocked_save.called)

I know that this works, but now I need to search why it works. Iโ€™ll explain it when I figure it out.

๐Ÿ‘คRubico

Leave a comment