def test_user_with_profile_works(self, import_mock): """ A user that already has a profile will do nothing """ backend = MagicMock() import_mock.side_effect = backend ensure_user_has_profile(self.backend_mock, {}, user=self.user_mock) backend().get_user_profile().assert_not_called()
def test_user_without_profile_works(self, import_mock): """ A user that has no profile will create one """ backend = MagicMock() import_mock.side_effect = backend backend().get_user_profile().DoesNotExist = ValueError type(self.user_mock).profile = PropertyMock(side_effect=ValueError) ensure_user_has_profile(self.backend_mock, {}, user=self.user_mock) backend().get_user_profile().objects.create.assert_called()