Beispiel #1
0
 def test_set_sets(self):
     """__set__ should push to __setitem__ on owner"""
     attr = Field()
     attr.name = 'bar'
     self.owner.__class__.bar = attr
     self.owner.bar = "Setting this thing!"
     self.assertEqual(self.owner['bar'], 'Setting this thing!')
Beispiel #2
0
 def test_get_gets(self):
     """__get__ should pull from __getitem__ on owner"""
     self.owner['foo'] = "FunTimes!"
     attr = Field()
     attr.name = 'foo'
     self.owner.__class__.foo = attr
     self.assertEqual(self.owner.foo, 'FunTimes!')
Beispiel #3
0
 def test_get_gets_with_type(self):
     """__get__ should cast value retreived to `type` if set"""
     attr = Field(type=int)
     attr.name = 'id'
     self.owner.__class__.id = attr
     self.owner['id'] = '123'
     self.assertEqual(self.owner.id, 123)
Beispiel #4
0
 def test_del_dels(self):
     """__delete__ should call __delitem__ on owner"""
     attr = Field()
     self.owner['baz'] = 42
     attr.name = 'baz'
     self.owner.__class__.baz = attr
     del self.owner.baz
     assert not self.owner.dict.has_key('baz')
Beispiel #5
0
 def test_del_dels(self):
     """__delete__ should call __delitem__ on owner"""
     attr = Field()
     self.owner['baz'] = 42
     attr.name = 'baz'
     self.owner.__class__.baz = attr
     del self.owner.baz
     assert not self.owner.dict.has_key('baz')
Beispiel #6
0
 def test_leaves_none_alone(self):
     """should not cast None"""
     attr = Field(type=int)
     attr.name = 'foo'
     self.owner.__class__.foo = attr
     try:
         self.owner.foo = None
     except TypeError:
         assert False, "should not cast None, but did"
Beispiel #7
0
class ReloadTestModel(pyperry.Base):
    id = Field()
    a = Field()
    b = Field()

    @classmethod
    def fetch_records(cls, relation):
        cls.last_relation = relation
        return [cls({'id': 2, 'a': 3, 'b': 4})]
Beispiel #8
0
class HelpModel(pyperry.Base):
    """a model with a docstring"""
    attr1 = Field()
    attr2 = Field()

    foo = BelongsTo(polymorphic=True)
    ape = BelongsTo()
    bars = HasMany(through='bananas')
    bananas = HasMany()
Beispiel #9
0
 def test_leaves_none_alone(self):
     """should not cast None"""
     attr = Field(type=int)
     attr.name = 'foo'
     self.owner.__class__.foo = attr
     try:
         self.owner.foo = None
     except TypeError:
         assert False, "should not cast None, but did"
 def test_primary_key(self):
     """should use configured primary_key in url"""
     TestModel.id = Field()
     TestModel.foo = Field()
     model = TestModel({'id': 7, 'foo': 12345})
     self.config['primary_key'] = 'foo'
     adapter = RestfulHttpAdapter(self.config)
     url = adapter.url_for('GET', model)
     self.assertEqual(url, '/widgets/12345.xml')
Beispiel #11
0
class Comment(AssocTest):
    id = Field()
    person_id = Field()
    parent_id = Field()
    parent_type = Field()
    text = Field()

    parent = BelongsTo(polymorphic=True)
    author = BelongsTo(class_name='Person',
                       foreign_key='person_id',
                       namespace='tests.fixtures.association_models')
Beispiel #12
0
class Article(AssocTest):
    id = Field()
    site_id = Field()
    author_id = Field()
    title = Field()
    text = Field()

    site = BelongsTo(class_name='Site')
    author = BelongsTo(class_name='Person')
    comments = HasMany(as_='parent', class_name='Comment')
    awesome_comments = HasMany(as_='parent',
                               class_name='Comment',
                               conditions="text LIKE '%awesome%'")
    comment_authors = HasMany(through='comments', source='author')
Beispiel #13
0
class Person(AssocTest):
    id = Field()
    name = Field()
    manager_id = Field()
    company_id = Field()

    manager = BelongsTo(class_name='Person', foreign_key='manager_id')
    authored_comments = HasMany(class_name='Comment', foreign_key='person_id')
    articles = HasMany(class_name='Article', foreign_key='author_id')
    comments = HasMany(as_='parent', class_name='Comment')
    employees = HasMany(class_name='Person', foreign_key='manager_id')
    sites = HasMany(class_name='Site', foreign_key='maintainer_id')
    commented_articles = HasMany(through='comments',
                                 source='parent',
                                 source_type='Article')
    maintained_articles = HasMany(through='sites', source='articles')
Beispiel #14
0
 class CallbackTest(pyperry.Base):
     id = Field()
     reader = TestAdapter()
     writer = TestAdapter()
     log = []
     bld = c_bld(lambda (self): self.log.append('before_load'))
     ald = c_ald(lambda (self): self.log.append('after_load'))
     bsv = c_bsv(lambda (self): self.log.append('before_save'))
     asv = c_asv(lambda (self): self.log.append('after_save'))
     bct = c_bct(lambda (self): self.log.append('before_create'))
     act = c_act(lambda (self): self.log.append('after_create'))
     bup = c_bup(lambda (self): self.log.append('before_update'))
     aup = c_aup(lambda (self): self.log.append('after_update'))
     bde = c_bde(lambda (self): self.log.append('before_delete'))
     ade = c_ade(lambda (self): self.log.append('after_delete'))
Beispiel #15
0
 class Model(pyperry.Base):
     id = Field()
     foo = Field()
Beispiel #16
0
 class Foo(pyperry.Base):
     id = Field()
     foo = Field()
     writer = TestAdapter()
     writer.features['batch_write'] = True
Beispiel #17
0
 class Test(pyperry.Base):
     id = Field()
     foo = Scope(where='bar')
     reader = TestAdapter()
Beispiel #18
0
 class Model(pyperry.Base):
     id = Field()
     reader = PreloadTestAdapter(processors=[(PreloadAssociations, {})])
Beispiel #19
0
 class Test(fixtures.association_models.AssocTest):
     id = Field()
     foo_id = Field()
Beispiel #20
0
 class Test(pyperry.Base):
     id = Field()
     name = Field()
     poop = Field()
     foo = Field(name='bar')
Beispiel #21
0
 class Test2(pyperry.Base):
     id = Field()
     name = Field()
Beispiel #22
0
class SourceModel(pyperry.Base):
    id = Field()
    bar = Field()
    _primary_key = 'bar'
Beispiel #23
0
 class Test(pyperry.Base):
     id = Field()
     name = Field()
     foo = Field(type=int)
     bar = Field(default=3)
Beispiel #24
0
class Source(pyperry.Base):
    id = Field()
Beispiel #25
0
 def test_set_sets_with_type(self):
     attr = Field(type=int)
     attr.name = 'id'
     self.owner.__class__.id = attr
     self.owner.id = '123'
     self.assertEqual(self.owner.dict['id'], 123)
Beispiel #26
0
 class Test(pyperry.Base):
     foo_id = Field()
     foo = associations.HasMany()
Beispiel #27
0
 def test_keywords(self):
     """should accept keywords type and default"""
     attr = Field(type=str, default=6, name='foo')
     self.assertEqual(attr.type, str)
     self.assertEqual(attr.default, 6)
     self.assertEqual(attr.name, 'foo')
Beispiel #28
0
class Company(AssocTest):
    id = Field()
    name = Field()

    employees = HasMany(class_name='Person',
                        namespace='tests.fixtures.extended_association_models')
Beispiel #29
0
 def test_sets_name_to_none(self):
     """should set name attribute to None"""
     attr = Field()
     self.assertEqual(attr.name, None)
Beispiel #30
0
 class Test(pyperry.Base):
     id = Field()
     baz_id = Field()
     baz = associations.BelongsTo(
         class_name='pyperry_foobar.foo.baz.Bazaroo5234')
Beispiel #31
0
 def test_set_sets_with_type(self):
     attr = Field(type=int)
     attr.name = 'id'
     self.owner.__class__.id = attr
     self.owner.id = '123'
     self.assertEqual(self.owner.dict['id'], 123)
 class Test(pyperry.Base):
     id = Field()
     reader = TestAdapter(middlewares=[(LocalCache, {})])
Beispiel #33
0
class TargetModel(pyperry.Base):
    id = Field()
    foo = Field()
    whatever_type = Field()
    _primary_key = 'foo'
Beispiel #34
0
 class Test(pyperry.Base):
     id = Field()
     writer = TestAdapter()
Beispiel #35
0
class Test(pyperry.Base):
    id = Field()
Beispiel #36
0
 class Parent2(pyperry.Base):
     name2 = Field()