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
Esempio n. 2
0
 def test_change(self):
     k = self.Knight.get(2)
     k.name = 'John'
     commit()
     start_session()
     k_got = self.Knight.get(2)
     self.assertEqual(k_got.name, 'John')
Esempio n. 3
0
 def setUp(self):
     
     class Knight(Object):
         title = f.CharacterVarying(
             length = 5, null = False, default = 'Sir'
         )
         name = f.CharacterVarying(length = 20, null = False)
         nickname = f.CharacterVarying(length = 20, null = True)
         score = f.Integer()
         
     self.Knight = Knight
     set_context(get_test_conn())
     start_session()
     # Knight.create_table()
     
     for ktup in [
         ('Sir', 'Galahad', 'The Pure', 10),
         ('King', 'Arthur', None, 20),
         ('Sir', 'Robin', 'The Brave', 30),
         ('Sir', 'Lancelot', None, 40),
     ]:
         title, name, nickname, score = ktup
         k = Knight(
             title = title,
             name = name,
             nickname = nickname,
             score = score
         )
         add(k)
         
     commit()
     start_session()
 def setUp(self):
     
     class Knight(Object):
         set_context(get_test_conn())
         start_session()
         title = f.CharacterVarying(
             length = 5, null = False, default = 'Sir'
         )
         name = f.CharacterVarying(length = 20, null = False)
         nickname = f.CharacterVarying(length = 20, null = True)
         score = f.Integer()
         
     self.Knight = Knight
     self.root = Root()
     Traverser(class_=self.Knight, field='name', session=get_session()).mount(self.root, 'knights')
     
     for ktup in [
         ('Sir', 'Galahad', 'The Pure', 10),
         ('King', 'Arthur', None, 20),
         ('Sir', 'Robin', 'The Brave', 30),
         ('Sir', 'Lancelot', None, 40),
     ]:
         title, name, nickname, score = ktup
         k = Knight(
             title = title,
             name = name,
             nickname = nickname,
             score = score
         )
         add(k)
         
     commit()
     start_session()
Esempio n. 5
0
 def test_deft(self):
     """Test of default value"""
     k = self.Knight(name = 'Doris', nickname = 'The Hamster', score = 999)
     add(k)
     commit()
     start_session()
     k_got = self.Knight.get(self.Knight.name == 'Doris')
     self.assertEqual(k_got.title, 'Sir')
Esempio n. 6
0
 def test_deletion(self):
     """Test a correct deletion behaviour"""
     k = self.Knight.get(2)
     k.delete()
     self.assertRaises(LifecycleError, lambda: k.name)
     commit()
     ks = list(self.Knight.find())
     self.assertEqual(len(ks), 3)
Esempio n. 7
0
 def test_change_id(self):
     """Changing id should be impossible"""
     k = self.Knight.get(2)
     k.name = 'John'
     commit()
     start_session()
     def broken():
         k =  self.Knight.get(2)
         k.id = 1
         
     self.assertRaises(TypeError, broken)
Esempio n. 8
0
 def test_custom_name(self):
     """Creating a table with custom table_name"""
     class Spam(Object):
         __table_name__ = 'eggs'
         meal = f.CharacterVarying(length = 10)
         
     add(Spam(meal = 'bacon'))
     commit()
     c = get_connection()
     cur = c.cursor()
     cur.execute('SELECT id, meal FROM eggs WHERE 1 = 1;')
     self.assertEqual(cur.fetchone(), (1, 'bacon'))
Esempio n. 9
0
 def test_no_connection(self):
     """Test trying to use nonexistent ctx raises exc"""
     self.assertRaises(CtxError, lambda: get_connection())
     self.assertRaises(CtxError, lambda: get_cursor())
     self.assertRaises(CtxError, lambda: get_session())
     self.assertRaises(CtxError, lambda: commit())
     self.assertRaises(CtxError, lambda: add())
Esempio n. 10
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)
Esempio n. 11
0
    def setUp(self):
        
        class Knight(Object):
            name = f.CharacterVarying(length = 20, null = False)

        self.Knight = Knight
        set_context(get_test_conn())
        start_session()

        for knight_name in [
            'Agravain', 'Bagdemagus', 'Bedivere', 'Bors', 'Breunor',
            'Calogrenant', 'Caradoc', 'Dagonet', 'Dinadan', 'Gaheris',
            'Galahad', 'Gareth', 'Gawain', 'Geraint', 'Griflet',
            'Hector de Maris', 'Kay', 'Lamorak', 'Lancelot', 'Leodegrance',
            'Lionel', 'Lucan', 'Maleagant', 'Marhaus', 'Palamedes', 'Pelleas',
            'Pellinore', 'Percival', 'Safir', 'Sagramore', 'Segwarides', 'Tor',
        ]: # There are 32 knights
            knight = Knight(name=knight_name)
            add(knight)
        commit()