4 usage: %(progname)s [args] 7 import os, sys, string, time, getopt
19 output(
"------ TESTING MySQLdb ---------")
26 output(
"------ TESTING sqlite2 ----------")
33 output(
"------ TESTING sqlite3 ----------")
40 output(
"------ TESTING postgres ----------")
47 if dbType ==
"sqlite3":
49 elif dbType ==
"sqlite2":
51 elif dbType ==
"mysql":
53 elif dbType ==
"postgres":
56 db.enabledCompression()
58 db.addTable(
"agents",
"agents", AgentsTable)
59 try: db.agents.dropTable()
62 db.addTable(
"roles",
"roles", TestTable)
63 try: db.test.dropTable()
73 self.
d_addColumn(
"agent_id",odb.kInteger,
None,primarykey = 1,autoincrement = 1)
74 self.
d_addColumn(
"login",odb.kVarString,200,notnull=1)
75 self.
d_addColumn(
"ext_email",odb.kVarString,200,notnull=1, indexed=1)
76 self.
d_addColumn(
"hashed_pw",odb.kVarString,20,notnull=1)
77 self.
d_addColumn(
"name",odb.kBigString,compress_ok=1)
79 self.
d_addColumn(
"ticket_count",odb.kIncInteger,
None)
80 self.
d_addColumn(
"data",odb.kBlob,
None, compress_ok=1)
89 self.
d_addColumn(
"oid",odb.kInteger,
None,primarykey = 1,autoincrement = 1)
99 def __init__(self, methodName='runTest', db=None):
100 unittest.TestCase.__init__(self, methodName=methodName)
102 if self.
db is None: self.
db = gDB
107 self.db.agents.deleteAllRows()
115 a_row = self.db.agents.fetchRow( (
"agent_id", 1000) )
116 self.fail(
"fetchRow eNoMatchingRows")
128 newrow = self.db.agents.newRow()
129 newrow.name =
"name #%d" % new_id
130 newrow.login =
"name%d" % new_id
131 newrow.ext_email =
"%d@name" % new_id
132 newrow.hashed_pw =
"hashedpw" 134 msg =
"new insert id (%d) does not match expected value (%d)" % (newrow.agent_id,new_id)
135 self.assertEqual(newrow.agent_id,new_id, msg=msg)
141 row = self.db.agents.newRow()
143 row.login =
"name #2" 144 row.ext_email =
"name #2" 145 row.hashed_pw =
"lsjdf" 147 a_row = self.db.agents.fetchRow( (
"agent_id", 1) )
149 self.assertEqual(a_row.name,
"name #1")
160 a_row.save(cursor =
"dummy cursor")
161 except AttributeError, reason:
162 self.fail(
"row tried to access cursor on save() when no changes were made!")
170 a_row.auth_level = 10
172 b_row = self.db.agents.fetchRow( (
"agent_id", 1) )
173 self.assertEqual(b_row.auth_level, 10,
"save and load failed")
180 repl_row = self.db.agents.newRow(replace=1)
181 repl_row.agent_id = a_row.agent_id
182 repl_row.login = a_row.login +
"-" + a_row.login
183 repl_row.ext_email =
"foo" 184 repl_row.hashed_pw =
"hashed_pw" 187 b_row = self.db.agents.fetchRow( (
"agent_id", a_row.agent_id) )
188 if b_row.login != repl_row.login:
189 raise "replace failed" 196 a = a_row.UNKNOWN_ATTRIBUTE
197 self.fail(
"unknown attribute")
198 except AttributeError, reason:
206 a_row.UNKNOWN_ATTRIBUTE = 1
207 self.fail(
"unknown attribute")
208 except AttributeError, reason:
219 a = a_row[
"UNKNOWN_ATTRIBUTE"]
220 self.fail(
"unknown attribute")
221 except KeyError, reason:
229 a_row[
"UNKNOWN_ATTRIBUTE"] = 1
230 self.fail(
"unknown attribute")
231 except KeyError, reason:
242 a_row.agent_id =
"this is a string" 244 except eInvalidData, reason:
247 output(
"PASSED! invalid data for column type")
254 rows = self.db.agents.fetchRows( (
'agent_id', 1) )
255 self.assertEqual(len(rows), 1)
263 rows = self.db.agents.fetchAllRows()
273 row = self.db.agents.fetchRow( (
'agent_id', 1) )
276 row = self.db.agents.fetchRow( (
'agent_id', 1) )
286 row = self.db.agents.fetchRow( (
'agent_id',2) )
287 self.db.agents.deleteRow( (
'agent_id', 2) )
289 row = self.db.agents.fetchRow( (
'agent_id',2) )
297 row = self.db.agents.fetchRow( (
'agent_id',3) )
298 if row.databaseSizeForColumn(
'name') != len(row.name):
306 row = self.db.agents.fetchRowUsingPrimaryKey(3)
307 if row.agent_id != 3:
312 row = self.db.agents.lookup(agent_id=3)
313 if row.agent_id != 3:
317 row = self.db.agents.lookupCreate(agent_id=2)
321 row.ext_email =
"hassan@dotfunk.com" 322 row.hashed_pw =
"sdfj" 329 row = self.db.agents.newRow()
331 row.name =
"name #%d" % new_id
332 row.login =
"name%d" % new_id
333 row.ext_email =
"%d@name" % new_id
334 row.inc(
'ticket_count')
335 row.hashed_pw =
"hashed_pw" 337 new_id = row.agent_id
339 trow = self.db.agents.fetchRow( (
'agent_id',new_id) )
340 if trow.ticket_count != 1:
341 raise "ticket_count didn't inc!", repr(trow.ticket_count)
343 row.inc(
'ticket_count', count=2)
345 trow = self.db.agents.fetchRow( (
'agent_id',new_id) )
346 if trow.ticket_count != 3:
347 raise "ticket_count wrong, expected 3, got %d" % trow.ticket_count
349 trow.inc(
'ticket_count')
351 if trow.ticket_count != 4:
352 raise "ticket_count wrong, expected 4, got %d" % trow.ticket_count
359 b_row = self.db.agents.newRow(replace=1)
363 b_row.login =
"scott" 364 b_row.ext_email =
"scott@" 365 b_row.hashed_pw =
"lsdjf" 366 b_row.columnA =
"hello1" 367 b_row.columnB =
"hello2" 370 c_row = self.db.agents.fetchRow( (
"agent_id", b_row.agent_id) )
372 self.assertEqual(c_row.columnA,
"hello1")
373 self.assertEqual(c_row.columnB,
"hello2")
379 b_row = self.db.agents.fetchRow( (
"agent_id", 5) )
383 d =
"hello\0hello" * 100
387 b_row = self.db.agents.fetchRow( (
"agent_id", 5) )
388 self.assertEqual(b_row.data, d)
393 row = self.db.roles.newRow()
399 row2 = self.db.roles.lookup(oid=row.oid)
411 print __doc__ % vars()
413 def main(argv, stdout, environ):
415 optlist, args = getopt.getopt(argv[1:],
"", [
"help",
"test",
"debug"])
419 for (field, val)
in optlist:
420 if field ==
"--help":
423 elif field ==
"--debug":
425 elif field ==
"--test":
440 elif arg ==
"sqlite3":
444 elif arg ==
"postgres":
447 if __name__ ==
"__main__":
448 main(sys.argv, sys.stdout, os.environ)
def d_addValueColumn(self)
def test_lookupCreate(self)
def TEST_POSTGRES(output=warn)
def d_hasMany(self, tblname, col_name, foreign_key=None, order=None)
def test_unknownAttribute3(self)
def test_primarykey(self)
def d_addVColumn(self, col_name, type, size=None, default=None)
def test_rowCreation(self)
def TEST_SQLITE3(output=warn)
def d_addColumn(self, col_name, ctype, size=None, primarykey=0, notnull=0, indexed=0, default=None, unique=0, autoincrement=0, autoguid=0, safeupdate=0, enum_values=None, no_export=0, relations=None, foreign_key=None, compress_ok=0, int_date=0)
def test_virtualColumns(self)
def TEST_SQLITE(output=warn)
def TEST_MYSQL(output=warn)
T E S T S
if sql[:6] != "select": warn(repr(sql))
def test_unknownAttribute2(self)
def test_compression(self)
def main(argv, stdout, environ)
def test_deleteObject(self)
def __init__(self, methodName='runTest', db=None)
def test_unknownAttribute(self)
def test_fetchRow_One(self)
def d_belongsTo(self, col_name, tblNameStr=None, foreign_key=None, order=None)
def setupDB(dbType="sqlite3")