def setUp(self): self.site = fixtures.association_models.Site self.klass = fixtures.association_models.Test self.id = 'has' self.foreign_key = 'some_id' self.has = Has(target_klass=self.klass, id=self.id) self.article = fixtures.association_models.Article
def test_kwarg(self): """should use the primary key given in the kwargs""" association = BelongsTo(target_klass=TargetModel, id='whatever', primary_key='asdf') self.assertEqual(association.primary_key(), 'asdf') association = Has(target_klass=TargetModel, id='whatever', primary_key='asdf') self.assertEqual(association.primary_key(), 'asdf')
def test_foreign_key_option(self): """should use 'foreign_key' option if specified""" a = Has(target_klass=self.klass, id='bar', foreign_key='purple_monkey') self.assertEqual('purple_monkey', a.foreign_key)
def test_polymorphic(self): """should return set polymorphic true if 'as' option passed and false otherwise""" self.assertEqual(False, self.has.polymorphic()) self.assertTrue(Has(target_klass=self.klass, id='bar', as_='parent').polymorphic())