adodbapitestconfig.py :  » Windows » pyExcelerator » pywin32-214 » adodbapi » tests » Python Open Source

Home
Python Open Source
1.3.1.2 Python
2.Ajax
3.Aspect Oriented
4.Blog
5.Build
6.Business Application
7.Chart Report
8.Content Management Systems
9.Cryptographic
10.Database
11.Development
12.Editor
13.Email
14.ERP
15.Game 2D 3D
16.GIS
17.GUI
18.IDE
19.Installer
20.IRC
21.Issue Tracker
22.Language Interface
23.Log
24.Math
25.Media Sound Audio
26.Mobile
27.Network
28.Parser
29.PDF
30.Project Management
31.RSS
32.Search
33.Security
34.Template Engines
35.Test
36.UML
37.USB Serial
38.Web Frameworks
39.Web Server
40.Web Services
41.Web Unit
42.Wiki
43.Windows
44.XML
Python Open Source » Windows » pyExcelerator 
pyExcelerator » pywin32 214 » adodbapi » tests » adodbapitestconfig.py
# Configure this in order to run the testcases.
"adodbapitestconfig.py v 2.2.6"

import os
import sys
print sys.version
#attempt to find adodbapi in this directory's parent
cwd = os.getcwd()
adoPath = os.path.normpath(cwd + '/../adodbapi.py')
if os.path.exists(adoPath):
    if adoPath not in sys.path:
        sys.path.insert(1,os.path.dirname(adoPath))
import adodbapi
# adodbapitest.py will import this same version when we return

try:
    print adodbapi.version # show version
except:
    print '"adodbapi.version" not present or not working.'
print __doc__

doAccessTest = True
doSqlServerTest = True
doMySqlTest = True

try: #If mx extensions are installed, use mxDateTime
    import mx.DateTime
    doMxDateTimeTest=True
except: 
    doMxDateTimeTest=False #Requires eGenixMXExtensions
doDateTimeTest=True #Requires Python 2.3 Alpha2
    
iterateOverTimeTests=True

if doAccessTest:
    _accessdatasource = None  #set to None for automatic creation
    #r"C:\Program Files\Microsoft Office\Office\Samples\northwind.mdb;"
    if _accessdatasource == None:
        # following setup code borrowed from pywin32 odbc test suite
        # kindly contributed by Frank Millman.
        import tempfile
        import os
        try:
            from win32com.client.gencache import EnsureDispatch
            from win32com.client import constants
            win32 = True
        except ImportError: #perhaps we are running IronPython
            win32 = False
        if not win32:
            from System import Activator,Type
        _accessdatasource = os.path.join(tempfile.gettempdir(), "test_odbc.mdb")
        if os.path.isfile(_accessdatasource):
            os.unlink(_accessdatasource)
        # Create a brand-new database - what is the story with these?
        for suffix in (".36", ".35", ".30"):
            try:
                if win32:
                    dbe = EnsureDispatch("DAO.DBEngine" + suffix)
                else:
                    type= Type.GetTypeFromProgID("DAO.DBEngine" + suffix)
                    dbe =  Activator.CreateInstance(type)
                break
            except:
                pass
        else:
            raise RuntimeError("Can't find a DB engine")
        print '    ...Creating ACCESS db at',_accessdatasource    
        if win32:
            workspace = dbe.Workspaces(0)
            newdb = workspace.CreateDatabase(_accessdatasource, 
                                            constants.dbLangGeneral,
                                            constants.dbEncrypt)
        else:
            newdb = dbe.CreateDatabase(_accessdatasource,';LANGID=0x0409;CP=1252;COUNTRY=0')
        newdb.Close()
    connStrAccess = r"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + _accessdatasource
    # for ODBC connection try...
    # connStrAccess = "Driver={Microsoft Access Driver (*.mdb)};db=%s;Uid=;Pwd=;" + _accessdatasource

if doSqlServerTest:
    _computername=r".\SQLEXPRESS" #or name of computer with SQL Server
    _databasename="Northwind" #or something else
    #_username="guest"
    #_password="12345678"
    connStrSQLServer = r"Provider=SQLOLEDB.1; Integrated Security=SSPI; Initial Catalog=%s;Data Source=%s" %(_databasename, _computername)
    #connStrSQLServer = r"Provider=SQLOLEDB.1; User ID=%s; Password=%s; Initial Catalog=%s;Data Source=%s" %(_username,_password,_databasename, _computername)
    print '    ...Testing MS-SQL login...'
    try:
        s = adodbapi.connect(connStrSQLServer) #connect to server
        s.close()
    except adodbapi.DatabaseError, inst:
        print inst.args[0]    # should be the error message
        doSqlServerTest = False

if doMySqlTest:
    _computername='192.168.1.1'
    _databasename='test'
    _username = 'Test'
    _password = '12345678'
    _driver="MySQL ODBC 5.1 Driver"     # or _driver="MySQL ODBC 3.51 Driver"
    connStrMySql = 'Driver={%s};Server=%s;Port=3306;Database=%s;user=%s;password=%s;Option=3;' % \
                   (_driver,_computername,_databasename,_username,_password)
    print '    ...Testing MySql login...'
    try:
        s = adodbapi.connect(connStrMySql) #connect to server
        s.close()
    except adodbapi.DatabaseError,  inst:
        print inst.args[0]    # should be the error message
        doMySqlTest = False
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.