Reputation: 84
I have the following mixin:
class MixinToAddOnMyClass:
def get_data(self, request):
try:
data = super().get_processed_data(request)
except Exception:
data = {'error': 'Invalid data request'}
I'd like to test this mixin class - but I find it not so clean when I have to create a mock class to inherit from it so that I can test the super()
call.
What would be the best way to unit test it?
Upvotes: 0
Views: 116
Reputation: 84
Ended up finding a way to do it. It seems like you can mock built in methods:
@patch('<path_to_mixin_file>.super')
def test_get_data_when_no_exception(self, super):
super.get_processed_data.return_value = True
self.assertTrue(MixinToAddOnMyClass.run_validation())
Upvotes: 2