From: Kevin C. <ke...@us...> - 2005-12-16 12:40:22
|
Update of /cvsroot/mailmanager/MailManager/tests In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv18348/tests Modified Files: Tag: RELENG_2_0_1 testDatabase.py Log Message: Moved the ZSQL support into the testStructures include Index: testDatabase.py =================================================================== RCS file: /cvsroot/mailmanager/MailManager/tests/testDatabase.py,v retrieving revision 1.4.2.12 retrieving revision 1.4.2.13 diff -u -d -r1.4.2.12 -r1.4.2.13 --- testDatabase.py 10 Nov 2005 18:24:55 -0000 1.4.2.12 +++ testDatabase.py 16 Dec 2005 12:40:07 -0000 1.4.2.13 @@ -163,127 +163,7 @@ import Globals -class ZSQLString(DocumentTemplate.HTML): - """ - This is a class to load ZSQL files from disk and parse the dtml - correctly, allowing them to be called without the need to use - Zope. The code here is based on that in Shared.DC.ZRDB.DA, in order - to try and fully emulate using these methods directly through Zope - """ - commands={} - for k, v in DocumentTemplate.HTML.commands.items(): - commands[k]=v - commands['sqlvar']=sqlvar.SQLVar - commands['sqltest']=sqltest.SQLTest - commands['sqlgroup']=sqlgroup.SQLGroup - - _proxy_roles=() - -class ZSQLFile(DocumentTemplate.HTMLFile): - """ - This is a class to load ZSQL files from disk and parse the dtml - correctly, allowing them to be called without the need to use - Zope. The code here is based on that in Shared.DC.ZRDB.DA, in order - to try and fully emulate using these methods directly through Zope - """ - commands={} - for k, v in DocumentTemplate.HTML.commands.items(): - commands[k]=v - commands['sqlvar']=sqlvar.SQLVar - commands['sqltest']=sqltest.SQLTest - commands['sqlgroup']=sqlgroup.SQLGroup - - _proxy_roles=() - -class ZSQLMethod: - schema = 'testschema' - - postgres_mapping = { - 'sql_delimiter' : ';', - 'sql_boolean' : 'BOOL', - 'sql_binary' : 'BYTEA', - #'sql_interval' : 'INTERVAL', - 'sql_interval' : 'BIGINT', - 'sql_database' : 'postgres', - 'sql_deferrable' : '', - 'sql_datetimestamp' : 'TIMESTAMP', - 'sql_initdefer' : '', - 'sql_indexlimit' : '', - 'sql_serialpkey' : 'SERIAL PRIMARY KEY', - 'sql_tabletype' : '', - 'sql_true' : '\'t\'', - 'sql_false' : '\'f\'', - 'sql_constraints' : True, - 'sql_charset' : '', - 'suboptimise' : True} - - mysql_mapping = { - 'sql_delimiter' : '\0', - 'sql_boolean' : 'BOOL', - 'sql_binary' : 'BLOB', - 'sql_interval' : 'BIGINT', - 'sql_database' : 'mysql', - 'sql_deferrable' : '', - 'sql_datetimestamp' : 'DATETIME', - 'sql_initdefer' : '', - 'sql_indexlimit' : '(255)', - 'sql_serialpkey' : 'INT PRIMARY KEY AUTO_INCREMENT', - 'sql_tabletype' : 'TYPE=InnoDB', - 'sql_true' : 1, - 'sql_false' : 0, - 'sql_constraints' : False, - 'sql_charset' : 'DEFAULT CHARSET=UTF8', - 'mysql_max_allowed_packet' : 32 * 1024 * 1024, - 'suboptimise' : False} - - def sql_quote__(self, v): - "Taken from Shared.DC.ZRDB.Connection" - if v.find("\'") >= 0: v=join(split(v,"\'"),"''") - return "'%s'" % v - - def getQuery(self, **params): - import copy - if self.dbplatform == 'postgres': - mapping = copy.copy(self.postgres_mapping) - if self.schema: - mapping['schema'] = self.schema + '.' - else: - mapping['schema'] = '' - mapping['sql_quote__'] = self.sql_quote__ - else: - mapping = copy.copy(self.mysql_mapping) - mapping['schema'] = '' - mapping['sql_quote__'] = self.sql_quote__ - - sqldata = self.getZSQLData(mapping=mapping, **params) - return sqldata - -class ZSQLStringMethod(ZSQLMethod): - - def __init__(self, data, dbplatform='postgres'): - self.zsqldata = data - self.dbplatform = dbplatform - - def getZSQLData(self, mapping, **params): - sqldata = ZSQLString(self.zsqldata, mapping = mapping)(**params) - return sqldata - -class ZSQLFileMethod(ZSQLMethod): - zsqlroot = os.path.join(Globals.INSTANCE_HOME, 'Products', 'MailManager', 'sql') - - def sql_quote__(self, v): - "Taken from Shared.DC.ZRDB.Connection" - if v.find("\'") >= 0: v=join(split(v,"\'"),"''") - return "'%s'" % v - - def __init__(self, filename, dbplatform='postgres'): - self.zsqlfile = os.path.join(self.zsqlroot, filename) - self.dbplatform = dbplatform - - def getZSQLData(self, mapping, **params): - sqldata = ZSQLFile(file_name = self.zsqlfile, mapping = mapping)(**params) - return sqldata - +from Products.MailManager.tests.classes.testStructures import ZSQLString, ZSQLFile, ZSQLMethod, ZSQLStringMethod, ZSQLFileMethod |