Hello,

I'm trying to test a function that imports and acts upon a django model, named 
House.

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 like to mock out the House model.
This is what I've tried so far, this is a method of a TestCase class:

@patch('apps.market.models.House')
   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()


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,

Jonas.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.

Reply via email to