[TIP] Issue setting up the correct mocking behavior
jonas at geiregat.org
Sat Apr 14 04:41:19 PDT 2012
I'm trying to test a function that imports and acts upon a django model.
from apps.market.models import Gig
def create_house(location, date, price):
house = House(id=None, date, price)
# calculate some stuff and further expand the house instance
# for example house.tag.add("some-tag")
# save after calculations
I like to mock out the House module.
This is what I've tried so far, this is a method of a TestCase class:
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()
MockedHouse.assert_called_with(None, DATE, PRICE)
I keep getting an assertionError, the Class is never called.
I'm also wondering if it's possible to inspect MockedHouse to see if it has for example some tags added to it.
Any help is appreciated,
More information about the testing-in-python