Django save bullying database

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()

    # calculate some stuff and further expand the house instance
    # for example house.tag.add("some-tag")

    # save after calculations
    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

    # A location is also a django module , I'm using factory_boy here for building a 'mocked' location
      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.

+3
source share
1

" django "... , Django , , python manage.py test. , .

mock ( ), Django .

. db , sqlite, settings.py:

if 'test' in sys.argv:
    DATABASES['default']['ENGINE'] = 'sqlite3'

.

+3

All Articles