class HasOneTestCase(BaseAssociationTestCase): def setUp(self): self.klass = fixtures.association_models.Test self.id = 'has_one' self.foreign_key = 'some_id' self.has_one = HasOne(target_klass=self.klass, id=self.id) def test_type(self): """should set type to has_one""" self.assertEqual('has_one', self.has_one.type()) def test_collection(self): """should set collection to false""" self.assertFalse(self.has_one.collection()) def test_get_descriptor(self): """should return first object in scope""" TestAdapter.data = { 'id': 1 } class Test(fixtures.association_models.AssocTest): id = Field() foo_id = Field() assoc = HasOne(target_klass=Test, id='foo', klass=Test) Test.foo = assoc instance = Test(id=1, foo_id=1) self.assertEqual(Test.foo, assoc) self.assertEqual(type(instance.foo), Test)
def test_has_one(self): """ should use the target class's primary key in a has one association """ association = HasOne(target_klass=TargetModel, id='whatever', class_name='SourceModel') self.assertEqual(association.primary_key(), TargetModel.primary_key())
class Site(AssocTest): id = Field() name = Field() maintainer_id = Field() maintainer = BelongsTo(klass=lambda: Person) headline = HasOne(klass=lambda: Article) master_comment = HasOne(as_='parent', class_name='Comment') fun_articles = HasOne(class_name='Article', conditions='1', sql=lambda s: """ SELECT articles.* FROM articles WHERE articles.text LIKE %%monkeyonabobsled%% AND articles.site_id = %s """ % s.id) articles = HasMany(class_name='Article', namespace='tests.fixtures.association_models') comments = HasMany(as_='parent', class_name='Comment') awesome_comments = HasMany(class_name='Comment', conditions='1', sql=lambda s: """ SELECT comments.* FROM comments WHERE comments.text LIKE '%%awesome%%' AND parent_type = "Site" AND parent_id = %s """ % s.id) article_comments = HasMany(through='articles', source='comments')
class HasOneTestCase(BaseAssociationTestCase): def setUp(self): self.klass = fixtures.association_models.Test self.id = "has_one" self.foreign_key = "some_id" self.has_one = HasOne(self.klass, self.id) def test_type(self): """should set type to has_one""" self.assertEqual("has_one", self.has_one.type()) def test_collection(self): """should set collection to false""" self.assertFalse(self.has_one.collection())
def test_get_descriptor(self): """should return first object in scope""" TestAdapter.data = { 'id': 1 } class Test(fixtures.association_models.AssocTest): id = Field() foo_id = Field() assoc = HasOne(target_klass=Test, id='foo', klass=Test) Test.foo = assoc instance = Test(id=1, foo_id=1) self.assertEqual(Test.foo, assoc) self.assertEqual(type(instance.foo), Test)
def setUp(self): self.klass = fixtures.association_models.Test self.id = 'has_one' self.foreign_key = 'some_id' self.has_one = HasOne(target_klass=self.klass, id=self.id)
def test_has_one(self): """ should use the target class's primary key in a has one association """ association = HasOne(TargetModel, "whatever", class_name="SourceModel") self.assertEqual(association.primary_key(), TargetModel.primary_key())
def setUp(self): self.klass = fixtures.association_models.Test self.id = "has_one" self.foreign_key = "some_id" self.has_one = HasOne(self.klass, self.id)
class AssociationModel(pyperry.Base): you = BelongsTo() foo = BelongsTo(polymorphic=True) bar = HasOne() bizs = HasMany() bazs = HasMany(through='bizs')