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
Source:stackexchange.com