예제 #1
0
 def test_del(self):
     # del should cause rollback
     foo = Foo.new(foo_id=1, i1=10, s1="xyz")
     conn1 = connect()
     conn1.insert(Foo, foo)
     conn1 = None
     self.assertEquals([], connect().select(Foo))
예제 #2
0
 def test_close(self):
     # close should cause rollback
     foo = Foo.new(foo_id=1, i1=10, s1="xyz")
     conn1 = connect()
     conn1.insert(Foo, foo)
     conn1.close()
     self.assertEquals([], connect().select(Foo))
예제 #3
0
 def test_rollback(self):
     foo = Foo.new(foo_id=1, i1=10, s1="xyz")
     conn1 = connect()
     conn1.insert(Foo, foo)
     self.assertEquals([foo], conn1.select(Foo))
     conn1.rollback()
     self.assertEquals([], conn1.select(Foo))
     conn2 = connect()
     self.assertEquals([], conn2.select(Foo))
예제 #4
0
 def test_create_transactional(self):
     conn = connect()
     conn.create_table(Foo)
     conn = connect()
     if connect == connect_postgres:
         try:
             conn.drop_table(Foo)
         except conn.DbError, e:
             self.assertIn(e.args, _NO_TABLE_FOO)
예제 #5
0
 def setUp(self):
     conn = connect()
     conn.drop_table_if_exists(Foo)
     conn.create_table(Foo)
     conn.commit()
     conn = connect()
     conn.insert(Foo, foo1)
     conn.insert(Foo, foo2)
     conn.commit()
예제 #6
0
 def test_commit_read_committed(self):
     foo = Foo.new(foo_id=1, i1=10, s1="xyz")
     conn1 = connect()
     if connect is connect_sqlite:
         conn2 = connect()
     else:
         conn2 = connect(isolation_level=READ_COMMITTED)
     conn1.insert(Foo, foo)
     self.assertEquals([], conn2.select(Foo))
     conn1.commit()
     self.assertEquals([foo], conn2.select(Foo))
예제 #7
0
 def test_insert_ascii(self):
     foo1 = Foo.new(foo_id=1, s1=S_ENGLISH_ASCII)
     foo2 = Foo.new(foo_id=2, s1=S_ENGLISH_U)
     conn = connect()
     conn.insert(Foo, foo1)
     conn.insert(Foo, foo2)
     conn.commit()
     conn.close()
     conn = connect()
     foo_list = conn.select(Foo, order_by=Foo.q.foo_id.ASC)
     self.assertEquals([foo1, foo2], foo_list)
     conn.close()
예제 #8
0
 def test_insert_unicode(self):
     foo1 = Foo.new(foo_id=1, s1=S_SPANISH_U)
     foo2 = Foo.new(foo_id=2, s1=S_FRENCH_U)
     conn = connect()
     conn.insert(Foo, foo1)
     conn.insert(Foo, foo2)
     conn.commit()
     conn.close()
     conn = connect()
     foo_list = conn.select(Foo, order_by=Foo.q.foo_id.ASC)
     self.assertEquals([foo1, foo2], foo_list)
     conn.close()
예제 #9
0
 def test_commit_repeatable_read(self):
     if connect is connect_sqlite:
         return
     foo = Foo.new(foo_id=1, i1=10, s1="xyz")
     conn1 = connect()
     conn2e = connect(isolation_level=REPEATABLE_READ)
     conn2i = connect() # test default is REPEATABLE_READ
     conn3 = connect(isolation_level=REPEATABLE_READ)
     conn1.insert(Foo, foo)
     self.assertEquals([], conn2e.select(Foo))
     self.assertEquals([], conn2i.select(Foo))
     conn1.commit()
     self.assertEquals([], conn2e.select(Foo))
     self.assertEquals([], conn2i.select(Foo))
     self.assertEquals([foo], conn3.select(Foo))
예제 #10
0
 def test_order_by(self):
     conn = connect()
     foo1 = Foo.new(foo_id=1, i1=101, s1="a")
     foo2 = Foo.new(foo_id=2, i1=23, s1="B")
     foo3 = Foo.new(foo_id=3, i1=42, s1="c")
     conn.insert(Foo, foo1)
     conn.insert(Foo, foo2)
     conn.insert(Foo, foo3)
     # order by AutoIdCol
     foo_list = list(conn.select(Foo, order_by=Foo.q.foo_id.ASC))
     self.assertEquals([foo1, foo2, foo3], foo_list)
     foo_list = list(conn.select(Foo, order_by=Foo.q.foo_id.DESC))
     self.assertEquals([foo3, foo2, foo1], foo_list)
     # order by IntCol
     foo_list = list(conn.select(Foo, order_by=Foo.q.i1.ASC))
     self.assertEquals([foo2, foo3, foo1], foo_list)
     foo_list = list(conn.select(Foo, order_by=Foo.q.i1.DESC))
     self.assertEquals([foo1, foo3, foo2], foo_list)
     # UnicodeCol - ignore case
     foo_list = list(conn.select(Foo, order_by=Foo.q.s1.ASC))
     if connect == connect_postgres:
         self.assertEquals([foo2, foo1, foo3], foo_list)
     else:
         self.assertEquals([foo1, foo2, foo3], foo_list)
     foo_list = list(conn.select(Foo, order_by=Foo.q.s1.DESC))
     if connect == connect_postgres:
         self.assertEquals([foo3, foo1, foo2], foo_list)
     else:
         self.assertEquals([foo3, foo2, foo1], foo_list)
예제 #11
0
 def test_where_LIKE_ILIKE(self):
     conn = connect()
     foo1 = Foo.new(foo_id=1, i1=101, s1="ab pq")
     foo2 = Foo.new(foo_id=2, i1=23, s1="AB PQ XY")
     foo3 = Foo.new(foo_id=3, i1=42, s1="pq xy")
     conn.insert(Foo, foo1)
     conn.insert(Foo, foo2)
     conn.insert(Foo, foo3)
     # where trailing %
     if connect != connect_sqlite:
         foo_list = conn.select(Foo, Foo.q.s1.LIKE('ab%'))
         self.assertEquals([foo1], foo_list)
     foo_list = conn.select(Foo, Foo.q.s1.ILIKE('ab%'))
     self.assertEquals([foo1, foo2], foo_list)
     # where trailing % - no matches
     if connect != connect_sqlite:
         foo_list = conn.select(Foo, Foo.q.s1.LIKE('%z%'))
         self.assertEquals([], foo_list)
     foo_list = conn.select(Foo, Foo.q.s1.ILIKE('%z%'))
     self.assertEquals([], foo_list)
     # where leading %
     if connect != connect_sqlite:
         foo_list = conn.select(Foo, Foo.q.s1.LIKE('%xy'))
         self.assertEquals([foo3], foo_list)
     foo_list = conn.select(Foo, Foo.q.s1.ILIKE('%xy'))
     self.assertEquals([foo2, foo3], foo_list)
     # where both sides %
     if connect != connect_sqlite:
         foo_list = conn.select(Foo, Foo.q.s1.LIKE('%x%'))
         self.assertEquals([foo3], foo_list)
     foo_list = conn.select(Foo, Foo.q.s1.ILIKE('%x%'))
     self.assertEquals([foo2, foo3], foo_list)
예제 #12
0
 def test_update_by_id_RO(self):
     conn = connect("test123")
     try:
         foo1 = Foo.new(i1=101, s1="xyz")
         conn.update_by_id(Foo, foo1)
     except Exception, e:
         self.assertEquals("Connection is read only: test123", str(e))
예제 #13
0
 def test_update_RO(self):
     conn = connect("test123")
     try:
         bar1 = Bar.new(bi=2001, bs="abc")
         conn.update(Bar, bar1, Bar.q.bi == 2002)
     except Exception, e:
         self.assertEquals("Connection is read only: test123", str(e))
예제 #14
0
 def test_RO(self):
     conn = connect("test123")
     try:
         foo = Foo.new(foo_id=1, i1=101, s1="alpha")
         conn.insert(Foo, foo)
     except Exception, e:
         self.assertEquals("Connection is read only: test123", str(e))
예제 #15
0
 def test_xselect_distinct(self):
     conn = connect()
     foo_list = \
         conn.xselect_distinct(Foo, Foo.q.i1)
     # FIXME: depending on db order
     self.assertEquals(101, foo_list.next())
     self.assertEquals(102, foo_list.next())
예제 #16
0
 def setUp(self):
     conn = connect()
     conn.drop_table_if_exists(Foo)
     conn.drop_table_if_exists(Baz)
     conn.create_table(Foo)
     conn.create_table(Baz)
     conn.commit()
예제 #17
0
    def test_intcol_roundtrip(self):
        import sys

        conn = connect()
        foo = Foo.new(foo_id=1, i1=sys.maxint)
        conn.insert(Foo, foo)
        foo_list = conn.select(Foo)
        self.assertEquals([foo], foo_list)
예제 #18
0
 def test_roundtrip_check_values(self):
     conn = connect()
     foo1 = Foo.new(foo_id=1, i1=101, s1="alpha", d1=datetime.date(2006, 6, 12))
     conn.insert(Foo, foo1)
     foo_list = conn.select(Foo)
     self.assertEquals([foo1], foo_list)
     foo2 = foo_list[0]
     Foo.check_values(foo2)
예제 #19
0
 def test_update_by_id(self):
     foo1 = Foo.new(foo_id=1, s1=S_SPANISH_U)
     foo2 = Foo.new(foo_id=2, s1=S_FRENCH_U)
     conn = connect()
     conn.insert(Foo, foo1)
     conn.insert(Foo, foo2)
     conn.commit()
     conn.close()
     conn = connect()
     foo2["s1"] = S_GERMAN_U
     conn.update_by_id(Foo, foo2)
     conn.commit()
     conn.close()
     conn = connect()
     foo2b = conn.get(Foo, 2)
     self.assertEquals(foo2, foo2b)
     conn.close()
예제 #20
0
 def test_bad_values(self):
     conn = connect()
     try:
         conn.get(Foo, '4')
     except TypeError, e:
         self.assertEquals(
             "AutoIdCol 'foo_id': int expected, got str", str(e)
             )
예제 #21
0
 def test_auto_id(self):
     conn = connect()
     try:
         conn.get(Foo, None)
     except AssertionError, e:
         self.assertEquals(
             "select_by_id(): cannot use None for AutoIdCol", str(e)
             )
예제 #22
0
 def test_no_auto_id_col(self):
     conn = connect()
     try:
         conn.get(Bar, 12)
     except AssertionError, e:
         self.assertEquals(
             "select_by_id(): table 'bar' does not have AutoIdCol", str(e)
             )
예제 #23
0
 def setUp(self):
     conn = connect()
     conn.drop_table(Foo, True)
     conn.drop_table(Bar, True)
     conn.drop_table(Baz, True)
     conn.create_table(Foo)
     conn.create_table(Bar)
     conn.create_table(Baz)
     conn.commit()
예제 #24
0
 def test_update_where(self):
     foo1 = Foo.new(foo_id=1, s1=S_SPANISH_U)
     foo2 = Foo.new(foo_id=2, s1=S_FRENCH_U)
     conn = connect()
     conn.insert(Foo, foo1)
     conn.insert(Foo, foo2)
     conn.commit()
     conn.close()
     conn = connect()
     foo3 = Foo.new(foo_id=3, s1=S_ENGLISH_ASCII)
     rc = conn.update(Foo, foo3, Foo.q.s1 == S_FRENCH_U)
     self.assertEquals(1, rc)
     conn.commit()
     conn.close()
     conn = connect()
     foo_list = conn.select(Foo, order_by=Foo.q.foo_id.ASC)
     self.assertEquals([foo1, foo3], foo_list)
     conn.close()
예제 #25
0
 def test_order_by(self):
     conn = connect()
     foo_list = \
         conn.select_distinct(
                 Foo,
                 Foo.q.s1,
                 order_by=Foo.q.s1.DESC
             )
     self.assertEquals(["beta", "alpha"], foo_list)
예제 #26
0
 def test_delete_0_rows(self):
     conn = connect()
     foo1 = Foo.new(foo_id=1, i1=101, s1="alpha")
     foo2 = Foo.new(foo_id=2, i1=23, s1="beta")
     conn.insert(Foo, foo1)
     conn.insert(Foo, foo2)
     rowcount = conn.delete(Foo, Foo.q.foo_id == 3)
     self.assertEquals(0, rowcount)
     foo_list = conn.select(Foo, order_by=Foo.q.foo_id.ASC)
     self.assertEquals([foo1, foo2], foo_list)
예제 #27
0
 def test_where_order_by(self):
     conn = connect()
     foo_list = \
         conn.select_distinct(
                 Foo,
                 Foo.q.foo_id,
                 Foo.q.s1 == "beta",
                 Foo.q.foo_id.ASC
             )
     self.assertEquals([2, 3], foo_list)
예제 #28
0
 def test_update_all_rows(self):
     conn = connect()
     bar1 = Bar.new(bi=2001, bs="abc")
     bar2 = Bar.new(bi=2002, bs="abc")
     conn.insert(Bar, bar1)
     conn.insert(Bar, bar2)
     bar4a = Bar.new(bi=2004, bs="ghi")
     rowcount = conn.update(Bar, bar4a, None)
     self.assertEquals(2, rowcount)
     bar_list = conn.select(Bar, order_by=Bar.q.bi.ASC)
     self.assertEquals([bar4a, bar4a], bar_list)
예제 #29
0
파일: test_close.py 프로젝트: divtxt/binder
 def test_close_insert(self):
     "Closing the connection prevents further operations on the connection."
     conn = connect()
     foo1 = Foo.new(foo_id=1, i1=101, s1="alpha")
     conn.insert(Foo, foo1)
     conn.close()
     foo2 = Foo.new(foo_id=2, s1="beta")
     try:
         conn.insert(Foo, foo2)
     except AssertionError, e:
         self.assertEquals("Connection is closed", str(e))
예제 #30
0
 def test_select(self):
     conn = connect()
     foo1 = Foo.new(foo_id=1, i1=101, s1="alpha")
     foo2 = Foo.new(foo_id=2, s1="beta")
     conn.insert(Foo, foo1)
     foo_list = conn.select(Foo)
     self.assertEquals([foo1], foo_list)
     conn.insert(Foo, foo2)
     foo_list = conn.select(Foo)
     # FIXME: depending on db order
     self.assertEquals([foo1, foo2], foo_list)