Example #1
0
    def test_update(self):
        p1 = self.create_person_one()
        objectstore.flush()
        objectstore.clear()

        person = Person.select()[0]
        person.gender = 'F'
        objectstore.flush()
        objectstore.clear()
        self.assertEquals(person.row_version, 2)

        person = Person.select()[0]
        person.gender = 'M'
        objectstore.flush()
        objectstore.clear()
        self.assertEquals(person.row_version, 3)

        #TODO: check that a concurrent modification raises exception
        p1 = Person.select()[0]
        s1 = objectstore.session
        s2 = create_session()
        objectstore.context.current = s2
        p2 = Person.select()[0]
        p1.first_name = "jack"
        p2.first_name = "ed"
        objectstore.flush()
        try:
            objectstore.context.current = s1
            objectstore.flush()
            # Only dialects with a sane rowcount can detect the ConcurrentModificationError
            if testbase.db.dialect.supports_sane_rowcount():
                assert False
        except exceptions.ConcurrentModificationError:
            pass
Example #2
0
    def testbasic(self):
        # Set up activemapper objects
        foo1, baz1 = self.create_objects()

        objectstore.flush()
        objectstore.clear()

        foo1 = foo.get_by(name='foo1')
        baz1 = baz.get_by(name='baz1')

        # Just checking ...
        assert (foo1.name == 'foo1')
        assert (baz1.name == 'baz1')

        # Diagnostics ...
        # import sys
        # sys.stderr.write("\nbazrel missing from dir(foo1):\n%s\n"  % dir(foo1))
        # sys.stderr.write("\nbazrel in foo1 relations:\n%s\n" %  foo1.relations)

        # Optimistically based on activemapper one_to_many test, try  to append
        # baz1 to foo1.bazrel - (AttributeError: 'foo' object has no attribute 'bazrel')
        print sqlalchemy.class_mapper(foo).props
        print sqlalchemy.class_mapper(baz).props
        foo1.bazrel.append(baz1)
        assert (foo1.bazrel == [baz1])
    def test_multiple(self):
        p1 = self.create_person_one()
        p2 = self.create_person_two()

        objectstore.flush()
        objectstore.clear()

        # select and make sure we get back two results
        people = Person.query.all()
        self.assertEquals(len(people), 2)

        # make sure that our backwards relationships work
        self.assertEquals(people[0].addresses[0].person.id, p1.id)
        self.assertEquals(people[1].addresses[0].person.id, p2.id)

        # try a more complex select
        results = Person.query.filter(
            or_(
                and_(
                    Address.c.person_id == Person.c.id,
                    Address.c.postal_code.like('30075')
                ),
                and_(
                    Person.c.prefs_id == Preferences.c.id,
                    Preferences.c.favorite_color == 'Green'
                )
            )
        ).all()
        self.assertEquals(len(results), 2)
    def test_update(self):
        p1 = self.create_person_one()
        objectstore.flush()
        objectstore.clear()

        person = Person.query.first()
        person.gender = 'F'
        objectstore.flush()
        objectstore.clear()
        self.assertEquals(person.row_version, 2)

        person = Person.query.first()
        person.gender = 'M'
        objectstore.flush()
        objectstore.clear()
        self.assertEquals(person.row_version, 3)

        #TODO: check that a concurrent modification raises exception
        p1 = Person.query.first()
        s1 = objectstore()
        s2 = create_session()
        objectstore.registry.set(s2)
        p2 = Person.query.first()
        p1.first_name = "jack"
        p2.first_name = "ed"
        objectstore.flush()
        try:
            objectstore.registry.set(s1)
            objectstore.flush()
            # Only dialects with a sane rowcount can detect the ConcurrentModificationError
            if testing.db.dialect.supports_sane_rowcount:
                assert False
        except exceptions.ConcurrentModificationError:
            pass
Example #5
0
     def testbasic(self):
         # Set up activemapper objects
         foo1, baz1 = self.create_objects()

         objectstore.flush()
         objectstore.clear()

         foo1 = foo.get_by(name='foo1')
         baz1 = baz.get_by(name='baz1')
         
         # Just checking ...
         assert (foo1.name == 'foo1')
         assert (baz1.name == 'baz1')

         # Diagnostics ...
         # import sys
         # sys.stderr.write("\nbazrel missing from dir(foo1):\n%s\n"  % dir(foo1))
         # sys.stderr.write("\nbazrel in foo1 relations:\n%s\n" %  foo1.relations)

         # Optimistically based on activemapper one_to_many test, try  to append
         # baz1 to foo1.bazrel - (AttributeError: 'foo' object has no attribute 'bazrel')
         print sqlalchemy.class_mapper(foo).props
         print sqlalchemy.class_mapper(baz).props
         foo1.bazrel.append(baz1)
         assert (foo1.bazrel == [baz1])
Example #6
0
    def test_oneway_backref(self):
        # FIXME: I don't know why, but it seems that my backwards relationship
        #        on preferences still ends up being a list even though I pass
        #        in uselist=False...
        # FIXED: the backref is a new PropertyLoader which needs its own "uselist".
        # uses a function which I dont think existed when you first wrote ActiveMapper.
        p1 = self.create_person_one()
        self.assertEquals(p1.preferences.person, p1)
        p1.delete()

        objectstore.flush()
        objectstore.clear()
Example #7
0
 def test_oneway_backref(self):
     # FIXME: I don't know why, but it seems that my backwards relationship
     #        on preferences still ends up being a list even though I pass
     #        in uselist=False...
     # FIXED: the backref is a new PropertyLoader which needs its own "uselist".
     # uses a function which I dont think existed when you first wrote ActiveMapper.
     p1 = self.create_person_one()
     self.assertEquals(p1.preferences.person, p1)
     p1.delete()
     
     objectstore.flush()
     objectstore.clear()
Example #8
0
    def test_create(self):
        p1 = self.create_person_one()
        objectstore.flush()
        objectstore.clear()

        results = Person.select()

        self.assertEquals(len(results), 1)

        person = results[0]
        self.assertEquals(person.id, p1.id)
        self.assertEquals(len(person.addresses), 2)
        self.assertEquals(person.addresses[0].postal_code, '30338')
    def test_create(self):
        p1 = self.create_person_one()
        objectstore.flush()
        objectstore.clear()

        results = Person.query.all()

        self.assertEquals(len(results), 1)

        person = results[0]
        self.assertEquals(person.id, p1.id)
        self.assertEquals(len(person.addresses), 2)
        self.assertEquals(person.addresses[0].postal_code, '30338')
Example #10
0
    def test_delete(self):
        p1 = self.create_person_one()

        objectstore.flush()
        objectstore.clear()

        results = Person.select()
        self.assertEquals(len(results), 1)

        results[0].delete()
        objectstore.flush()
        objectstore.clear()

        results = Person.select()
        self.assertEquals(len(results), 0)
Example #11
0
    def test_delete(self):
        p1 = self.create_person_one()

        objectstore.flush()
        objectstore.clear()

        results = Person.query.all()
        self.assertEquals(len(results), 1)

        objectstore.delete(results[0])
        objectstore.flush()
        objectstore.clear()

        results = Person.query.all()
        self.assertEquals(len(results), 0)
Example #12
0
    def testbasic(self):
        t = TreeNode(name='node1')
        t.children.append(TreeNode(name='node2'))
        t.children.append(TreeNode(name='node3'))
        objectstore.flush()
        objectstore.clear()

        t = TreeNode.get_by(name='node1')
        assert (t.name == 'node1')
        assert (t.children[0].name == 'node2')
        assert (t.children[1].name == 'node3')
        assert (t.children[1].parent is t)

        objectstore.clear()
        t = TreeNode.get_by(name='node3')
        assert (t.parent is TreeNode.get_by(name='node1'))
Example #13
0
    def testbasic(self):
        t = TreeNode(name='node1')
        t.children.append(TreeNode(name='node2'))
        t.children.append(TreeNode(name='node3'))
        objectstore.flush()
        objectstore.clear()

        t = TreeNode.query.filter_by(name='node1').one()
        assert (t.name == 'node1')
        assert (t.children[0].name == 'node2')
        assert (t.children[1].name == 'node3')
        assert (t.children[1].parent is t)

        objectstore.clear()
        t = TreeNode.query.filter_by(name='node3').one()
        assert (t.parent is TreeNode.query.filter_by(name='node1').one())
Example #14
0
    def test_select_by(self):
        # FIXME: either I don't understand select_by, or it doesn't work.
        # FIXED (as good as we can for now): yup....everyone thinks it works that way....it only
        # generates joins for keyword arguments, not ColumnClause args.  would need a new layer of
        # "MapperClause" objects to use properties in expressions. (MB)

        p1 = self.create_person_one()
        p2 = self.create_person_two()

        objectstore.flush()
        objectstore.clear()

        results = Person.select(
            Address.c.postal_code.like('30075') & Person.join_to('addresses'))
        self.assertEquals(len(results), 1)

        self.assertEquals(Person.count(), 2)
Example #15
0
    def test_select_by(self):
        # FIXME: either I don't understand select_by, or it doesn't work.
        # FIXED (as good as we can for now): yup....everyone thinks it works that way....it only
        # generates joins for keyword arguments, not ColumnClause args.  would need a new layer of
        # "MapperClause" objects to use properties in expressions. (MB)

        p1 = self.create_person_one()
        p2 = self.create_person_two()

        objectstore.flush()
        objectstore.clear()

        results = Person.query.join('addresses').filter(
            Address.c.postal_code.like('30075')
        ).all()
        self.assertEquals(len(results), 1)

        self.assertEquals(Person.query.count(), 2)
Example #16
0
    def test_multiple(self):
        p1 = self.create_person_one()
        p2 = self.create_person_two()

        objectstore.flush()
        objectstore.clear()

        # select and make sure we get back two results
        people = Person.select()
        self.assertEquals(len(people), 2)

        # make sure that our backwards relationships work
        self.assertEquals(people[0].addresses[0].person.id, p1.id)
        self.assertEquals(people[1].addresses[0].person.id, p2.id)

        # try a more complex select
        results = Person.select(
            or_(
                and_(Address.c.person_id == Person.c.id,
                     Address.c.postal_code.like('30075')),
                and_(Person.c.prefs_id == Preferences.c.id,
                     Preferences.c.favorite_color == 'Green')))
        self.assertEquals(len(results), 2)