I am trying to call out a save method call on django models. Maud. I use Mock as my mocking library.
I am testing the function in the house_factory.py file, which is located in apps.deps.house_factory.
house_factory.py: from apps.market.models import House
def create_house(location, date, price):
house = House(id=None, date, price)
house.save()
house.save()
I would like to mock the House model.
class HouseModelMock(mock.Mock):
def save(self):
pass
Testing method, is part of the unittest.TestCase class
@patch('apps.deps.house_factory.House', new_callable=HouseModelMock)
def create_house_test(self, MockedHouse):
""" Constants """
DAYS_FROM_TODAY = 55
DATE = datetime.date.today() + datetime.timedelta(days=DAYS_FROM_TODAY)
PRICE = 250000
location = LocationFactory.build()
create_house(DATE, PRICE)
MockedHouse.assert_called_with(None, DATE, PRICE)
MockedHouse.save.assert_called_with()
If I run this test, I get:
call__ return self.call (* arg, ** kw) MemoryError
This is one of my first attempts to get serious with django and testing. So maybe I'm misconfiguring to mock a database call.
Any help is appreciated
Jonas.