本文整理汇总了Python中bindertest.tabledefs.Foo.new方法的典型用法代码示例。如果您正苦于以下问题:Python Foo.new方法的具体用法?Python Foo.new怎么用?Python Foo.new使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类bindertest.tabledefs.Foo
的用法示例。
在下文中一共展示了Foo.new方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_order_by
# 需要导入模块: from bindertest.tabledefs import Foo [as 别名]
# 或者: from bindertest.tabledefs.Foo import new [as 别名]
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)
示例2: test_where_LIKE_ILIKE
# 需要导入模块: from bindertest.tabledefs import Foo [as 别名]
# 或者: from bindertest.tabledefs.Foo import new [as 别名]
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)
示例3: test_delete_0_rows
# 需要导入模块: from bindertest.tabledefs import Foo [as 别名]
# 或者: from bindertest.tabledefs.Foo import new [as 别名]
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)
示例4: test_select
# 需要导入模块: from bindertest.tabledefs import Foo [as 别名]
# 或者: from bindertest.tabledefs.Foo import new [as 别名]
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)
示例5: test_close_insert
# 需要导入模块: from bindertest.tabledefs import Foo [as 别名]
# 或者: from bindertest.tabledefs.Foo import new [as 别名]
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))
示例6: test_delete_all
# 需要导入模块: from bindertest.tabledefs import Foo [as 别名]
# 或者: from bindertest.tabledefs.Foo import new [as 别名]
def test_delete_all(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)
conn.insert(Foo, foo2)
found = conn.delete(Foo)
self.assertEquals(2, found)
self.assertEquals([], conn.select(Foo))
found = conn.delete(Foo)
self.assertEquals(0, found)
示例7: test_where_gt_ge_lt_le
# 需要导入模块: from bindertest.tabledefs import Foo [as 别名]
# 或者: from bindertest.tabledefs.Foo import new [as 别名]
def test_where_gt_ge_lt_le(self):
conn = connect()
foo1 = Foo.new(foo_id=1, i1=101, s1="alpha", d1=datetime.date(2005, 11, 24))
foo2 = Foo.new(foo_id=2, i1=23, s1="beta", d1=datetime.date(2006, 2, 16))
foo3 = Foo.new(foo_id=3, i1=42, s1="alpha", d1=datetime.date(2006, 6, 10))
conn.insert(Foo, foo1)
conn.insert(Foo, foo2)
conn.insert(Foo, foo3)
# where __gt__ & AutoIdCol
foo_list = conn.select(Foo, Foo.q.foo_id > 2)
self.assertEquals([foo3], foo_list)
# where __ge__ & UnicodeCol
foo_list = conn.select(Foo, Foo.q.s1 >= 'beta')
self.assertEquals([foo2], foo_list)
# where __lt__ & IntCol
foo_list = conn.select(Foo, Foo.q.i1 < 42)
self.assertEquals([foo2], foo_list)
# where __le__ & IntCol
foo_list = conn.select(Foo, Foo.q.i1 <= 42)
# FIXME: depending on db order
self.assertEquals([foo2, foo3], foo_list)
# where AND, AutoIdCol, gt, IntCol, lt
foo_list = conn.select(Foo, AND(Foo.q.foo_id > 1, Foo.q.i1 < 30))
self.assertEquals([foo2], foo_list)
# where AND, DateCol, gt, lt
foo_list = conn.select(
Foo,
AND(
Foo.q.d1 > datetime.date(2005, 11, 24),
Foo.q.d1 < datetime.date(2006, 6, 10),
)
)
self.assertEquals([foo2], foo_list)
# where AND, DateCol, gt, lt
foo_list = conn.select(
Foo,
AND(
Foo.q.d1 > datetime.date(2005, 11, 24),
Foo.q.d1 < datetime.date(2006, 6, 10),
)
)
self.assertEquals([foo2], foo_list)
# where AND, DateCol, gt, le
foo_list = conn.select(
Foo,
AND(
Foo.q.d1 >= datetime.date(2005, 11, 24),
Foo.q.d1 <= datetime.date(2006, 6, 10),
)
)
# FIXME: depending on db order
self.assertEquals([foo1, foo2, foo3], foo_list)
示例8: test_insert_ascii
# 需要导入模块: from bindertest.tabledefs import Foo [as 别名]
# 或者: from bindertest.tabledefs.Foo import new [as 别名]
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()
示例9: test_select_insert
# 需要导入模块: from bindertest.tabledefs import Foo [as 别名]
# 或者: from bindertest.tabledefs.Foo import new [as 别名]
def test_select_insert(self):
"New operation closes a partly consumed cursor."
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)
foo_iter = conn.xselect(Foo)
conn.insert(Foo, foo2)
try:
foo_iter.next()
except conn.DbError, e:
self.assertEquals("Result cursor closed.", str(e))
示例10: test_delete_by_id_more_than_one_row
# 需要导入模块: from bindertest.tabledefs import Foo [as 别名]
# 或者: from bindertest.tabledefs.Foo import new [as 别名]
def test_delete_by_id_more_than_one_row(self):
conn = connect()
foo1 = Foo.new(foo_id=1, i1=101)
foo2 = Foo.new(foo_id=2, i1=101)
conn.insert(Foo, foo1)
conn.insert(Foo, foo2)
Foo2 = Table("foo", AutoIdCol("i1"), IntCol("foo_id"))
try:
conn.delete_by_id(Foo2, 101)
except AssertionError, e:
expected = "delete_by_id(): more than 1 row deleted", ("foo", "i1", 101, 2)
self.assertEquals(expected, get_assert_tuple_args(e))
示例11: test_insert_unicode
# 需要导入模块: from bindertest.tabledefs import Foo [as 别名]
# 或者: from bindertest.tabledefs.Foo import new [as 别名]
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()
示例12: test_update_by_id_more_than_one_row
# 需要导入模块: from bindertest.tabledefs import Foo [as 别名]
# 或者: from bindertest.tabledefs.Foo import new [as 别名]
def test_update_by_id_more_than_one_row(self):
conn = connect()
foo1 = Foo.new(foo_id=1, i1=101)
foo2 = Foo.new(foo_id=2, i1=101)
conn.insert(Foo, foo1)
conn.insert(Foo, foo2)
Foo2 = Table("foo", AutoIdCol("i1"), UnicodeCol("s1", 10))
try:
foo3 = Foo2.new(i1=101, s1="xyz")
conn.update_by_id(Foo2, foo3)
except AssertionError, e:
expected = "update_by_id(): more than 1 row updated", ("foo", "i1", 101, 2)
self.assertEquals(expected, get_assert_tuple_args(e))
示例13: test_update_1_row
# 需要导入模块: from bindertest.tabledefs import Foo [as 别名]
# 或者: from bindertest.tabledefs.Foo import new [as 别名]
def test_update_1_row(self):
conn = connect()
foo1 = Foo.new(foo_id=1, i1=101, s1="alpha")
foo2 = Foo.new(foo_id=2, i1=23, s1="beta")
foo3 = Foo.new(foo_id=3, i1=42, s1="alpha", d1=datetime.date(2006, 6, 10))
conn.insert(Foo, foo1)
conn.insert(Foo, foo2)
conn.insert(Foo, foo3)
foo4a = Foo.new(foo_id=4, i1=102, s1="gamma")
rowcount = conn.update(Foo, foo4a, Foo.q.foo_id == 2)
self.assertEquals(1, rowcount)
foo_list = conn.select(Foo, order_by=Foo.q.foo_id.ASC)
self.assertEquals([foo1, foo3, foo4a], foo_list)
示例14: test_auto_id
# 需要导入模块: from bindertest.tabledefs import Foo [as 别名]
# 或者: from bindertest.tabledefs.Foo import new [as 别名]
def test_auto_id(self):
conn = connect()
foo1 = Foo.new(i1=101, s1="alpha")
self.assert_(foo1["foo_id"] is None)
conn.insert(Foo, foo1)
self.assertEquals(1, foo1["foo_id"])
foo2 = Foo.new(s1="beta")
self.assert_(foo2["foo_id"] is None)
conn.insert(Foo, foo2)
self.assertEquals(2, foo2["foo_id"])
foo_list = conn.select(Foo)
# FIXME: depending on db order
self.assertEquals([foo1, foo2], foo_list)
示例15: test
# 需要导入模块: from bindertest.tabledefs import Foo [as 别名]
# 或者: from bindertest.tabledefs.Foo import new [as 别名]
def test(self):
foo = Foo.new(foo_id=4, i1=23, s1="pqr", d1=datetime.date(2006, 5, 4))
bar = Bar.new(
bi=5, bs="abc", bd=datetime.date(2006, 3, 21), bdt1=datetime.datetime(2005, 11, 22, 0, 43, 12), bb=True
)
# no where condition
sql, values = sqlgen.update(Foo, foo, None, sqlgen.DIALECT_SQLITE, "?")
self.assertEquals("UPDATE foo SET foo_id=?,i1=?,s1=?,d1=?", sql)
self.assertEquals([4, 23, u"pqr", "2006-05-04"], values)
# AutoIdCol
sql, values = sqlgen.update(Foo, foo, Foo.q.foo_id == 2, sqlgen.DIALECT_MYSQL, "%s")
self.assertEquals("UPDATE foo SET foo_id=%s,i1=%s,s1=%s,d1=%s WHERE foo_id=%s", sql)
self.assertEquals([4, 23, u"pqr", "2006-05-04", 2], values)
# IntCol
sql, values = sqlgen.update(Foo, foo, Foo.q.i1 == 32, sqlgen.DIALECT_SQLITE, "?")
self.assertEquals("UPDATE foo SET foo_id=?,i1=?,s1=?,d1=? WHERE i1=?", sql)
self.assertEquals([4, 23, u"pqr", "2006-05-04", 32], values)
# IntCol AND UnicodeCol
sql, values = sqlgen.update(Foo, foo, AND(Foo.q.i1 == 12, Foo.q.s1 == "aeiou"), sqlgen.DIALECT_MYSQL, "%s")
self.assertEquals("UPDATE foo SET foo_id=%s,i1=%s,s1=%s,d1=%s WHERE i1=%s AND s1=%s", sql)
self.assertEquals([4, 23, u"pqr", "2006-05-04", 12, "aeiou"], values)
# IntCol AND DateCol / NULL
sql, values = sqlgen.update(Bar, bar, AND(Bar.q.bi == 12, Bar.q.bd == None), sqlgen.DIALECT_SQLITE, "?")
self.assertEquals("UPDATE bar SET bi=?,bs=?,bd=?,bdt1=?,bb=? WHERE bi=? AND bd is NULL", sql)
self.assertEquals([5, u"abc", "2006-03-21", "2005-11-22T00:43:12Z", 1, 12], values)
# IntCol OR UnicodeCol
sql, values = sqlgen.update(Foo, foo, OR(Foo.q.i1 == 12, Foo.q.s1 == "aeiou"), sqlgen.DIALECT_MYSQL, "%s")
self.assertEquals("UPDATE foo SET foo_id=%s,i1=%s,s1=%s,d1=%s WHERE i1=%s OR s1=%s", sql)
self.assertEquals([4, 23, u"pqr", "2006-05-04", 12, "aeiou"], values)
# IntCol OR DateCol / NULL
sql, values = sqlgen.update(Bar, bar, OR(Bar.q.bi == 12, Bar.q.bd == None), sqlgen.DIALECT_SQLITE, "?")
self.assertEquals("UPDATE bar SET bi=?,bs=?,bd=?,bdt1=?,bb=? WHERE bi=? OR bd is NULL", sql)
self.assertEquals([5, u"abc", "2006-03-21", "2005-11-22T00:43:12Z", 1, 12], values)