コード例 #1
0
    def setUp(self):

        class Movie(Object):
            title = CharacterVarying(30)

        class Character(Object):
            name = CharacterVarying(30)
            movie = ManyToOne(Movie)

        self.connection = get_test_conn()
        set_context(self.connection)
        start_session()
        life = Movie(title = 'Life of Brian')
        grail = Movie(title = 'MP & the Holy Grail')
        add(life)
        add(grail)
        for c in [
            ('Brian', life),
            ('Patsy', grail),
            ('Arthur', grail),
        ]:
            name, movie = c
            char = Character(name = name, movie = movie)
            add(char)
            
        commit()

        self.Character = Character
        self.Movie = Movie
コード例 #2
0
 def tearDown(self):
     try:
         conn = get_test_conn()
         conn.cursor().execute('DROP TABLE spams;')
         conn.commit()
         
     except ProgrammingError:
         pass
コード例 #3
0
 def test_unhandled_exception(self):
     """Testing the exception from engine that can't be handled"""
     conn = get_test_conn()
     set_context(conn)
     class Spam(Object):
         eggs = BrokenField()
     try:
         Spam.create_table()
     except ProgrammingError as err:
         conn.rollback()
         self.assertEqual(err.pgcode, UNDEFINED_OBJECT)
コード例 #4
0
 def test_unhandled_exception_getting(self):
     """Testing the exception from engine that can't be handled
     (while get()ting)"""
     conn = get_test_conn()
     set_context(conn)
     start_session()
     class Spam(Object):
         eggs = CharacterVarying(20)
     add(Spam(eggs='abc'))
     commit()
     start_session()
     class Spam(Object):
         bacon = CharacterVarying(20)
     try:
         spam = Spam.get(1)
     except ProgrammingError as err:
         self.assertEqual(err.pgcode, UNDEFINED_COLUMN)
コード例 #5
0
 def test_table_mismatch(self):
     """Testing unhandled errors when flushing"""
     conn = get_test_conn()
     cur = conn.cursor()
     cur.execute(
         """CREATE TABLE spams (
             id integer,
             eggs character varying(10),
             PRIMARY KEY (id)
         );""")
     conn.commit()
     set_context(conn)
     start_session()
     class Spam(Object):
         bacon = CharacterVarying(length = 10)
     
     add(Spam(bacon = 'sausage'))
     self.assertRaises(ProgrammingError, commit)
コード例 #6
0
    def setUp(self):
        self.connection = get_test_conn()
        ep.set_context(self.connection)
        ep.start_session()
        class Food(ep.Object):
            name = ep.f.CharacterVarying(20)
            ingredients = ep.rel.ManyToMany()

        spam = Food(name='spam')
        eggs = Food(name='eggs')
        bacon = Food(name='bacon')
        sausage = Food(name='sausage')

        meal1 = Food(name='meal1', ingredients=[spam, bacon])
        meal2 = Food(name='meal2', ingredients=[spam, eggs, bacon])
        meal3 = Food(name='meal3', ingredients=[spam, bacon, sausage])
        ep.add(spam, eggs, bacon, sausage, meal1, meal2, meal3)
        self.Food = Food
        ep.commit()
コード例 #7
0
    def test_eaft_relation(self):
        """
        This is a special test to create a related table when object depending
        on it (but with foreign key = NULL) is flushed
        """

        class Movie(ep.Object):
            title = ep.f.CharacterVarying(30)

        class Character(ep.Object):
            name = ep.f.CharacterVarying(30)
            movie = ep.rel.ManyToOne(Movie)

        c = Character(name="Nobody important", movie = None)

        self.connection = get_test_conn()
        ep.set_context(self.connection)
        ep.start_session()

        ep.add(c)
        ep.commit()
コード例 #8
0
    def setUp(self):
        class Ingredient(ep.Object):
            name = ep.f.CharacterVarying(20)

        class Meal(ep.Object):
            name = ep.f.CharacterVarying(20)
            ingredients = ep.rel.ManyToMany(Ingredient)

        self.connection = get_test_conn()
        ep.set_context(self.connection)

        spam = Ingredient(name='spam')
        eggs = Ingredient(name='eggs')
        bacon = Ingredient(name='bacon')
        sausage = Ingredient(name='sausage')
        ep.start_session()
        ep.add(spam, eggs, bacon, sausage)
        meal1 = Meal(name='meal1', ingredients=[spam, bacon])
        meal2 = Meal(name='meal2', ingredients=[spam, eggs, bacon])
        meal3 = Meal(name='meal3', ingredients=[spam, bacon, sausage])
        ep.add(meal1, meal2, meal3)
        self.Meal = Meal
        self.Ingredient = Ingredient
        ep.commit()