I am trying to patch a function of a view within a TestCase in django. I have a class:
class BaseView(View):
def _get_data(self):
self.attribute = self.fancy_stuff()
self.thing = self.do_other_stuff()
I need to mock out self.attribute to an empty list like:
_get_data_fake_function():
self.attribute = []
self.thing = True
An issue is that I'm within a test case like:
class MyTests(TestCase):
def setUp(self):
self.view = BaseView
self.view_instance = self.view()
def test_stuff(self):
with patch(self.view) as mock_view:
?
I fear the self
is going to refer to the TestCase instance, and I'm confused on how to patch in the with patch(thing) as name
part.
I could patch the view's or the view instance's method, but either way I don't know how the fake function will correctly set the view's attribute
and thing
, not the test cases.