Spaces:
Sleeping
Sleeping
File size: 6,516 Bytes
fc12014 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 |
# Configure this to _YOUR_ environment in order to run the testcases.
"testADOdbapiConfig.py v 2.6.2.B00"
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# #
# # TESTERS:
# #
# # You will need to make numerous modifications to this file
# # to adapt it to your own testing environment.
# #
# # Skip down to the next "# #" line --
# # -- the things you need to change are below it.
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
import platform
import random
import sys
import is64bit
import setuptestframework
import tryconnection
print("\nPython", sys.version)
node = platform.node()
try:
print(
"node=%s, is64bit.os()= %s, is64bit.Python()= %s"
% (node, is64bit.os(), is64bit.Python())
)
except:
pass
if "--help" in sys.argv:
print(
"""Valid command-line switches are:
--package - create a temporary test package
--all - run all possible tests
--time - do time format test
--nojet - do not test against an ACCESS database file
--mssql - test against Microsoft SQL server
--pg - test against PostgreSQL
--mysql - test against MariaDB
"""
)
exit()
try:
onWindows = bool(sys.getwindowsversion()) # seems to work on all versions of Python
except:
onWindows = False
# create a random name for temporary table names
_alphabet = (
"PYFGCRLAOEUIDHTNSQJKXBMWVZ" # why, yes, I do happen to use a dvorak keyboard
)
tmp = "".join([random.choice(_alphabet) for x in range(9)])
mdb_name = "xx_" + tmp + ".mdb" # generate a non-colliding name for the temporary .mdb
testfolder = setuptestframework.maketemp()
if "--package" in sys.argv:
# create a new adodbapi module
pth = setuptestframework.makeadopackage(testfolder)
else:
# use the adodbapi module in which this file appears
pth = setuptestframework.find_ado_path()
if pth not in sys.path:
# look here _first_ to find modules
sys.path.insert(1, pth)
# function to clean up the temporary folder -- calling program must run this function before exit.
cleanup = setuptestframework.getcleanupfunction()
import adodbapi # will (hopefully) be imported using the "pth" discovered above
print(adodbapi.version) # show version
print(__doc__)
verbose = False
for a in sys.argv:
if a.startswith("--verbose"):
arg = True
try:
arg = int(a.split("=")[1])
except IndexError:
pass
adodbapi.adodbapi.verbose = arg
verbose = arg
doAllTests = "--all" in sys.argv
doAccessTest = not ("--nojet" in sys.argv)
doSqlServerTest = "--mssql" in sys.argv or doAllTests
doMySqlTest = "--mysql" in sys.argv or doAllTests
doPostgresTest = "--pg" in sys.argv or doAllTests
doTimeTest = ("--time" in sys.argv or doAllTests) and onWindows
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# # start your environment setup here v v v
SQL_HOST_NODE = "testsql.2txt.us,1430"
if doAccessTest:
c = {
"mdb": setuptestframework.makemdb(testfolder, mdb_name),
# macro definition for keyword "provider" using macro "is64bit" -- see documentation
# is64bit will return true for 64 bit versions of Python, so the macro will select the ACE provider
"macro_is64bit": [
"provider",
"Microsoft.ACE.OLEDB.12.0", # 64 bit provider
"Microsoft.Jet.OLEDB.4.0", # 32 bit provider
],
}
# ;Mode=ReadWrite;Persist Security Info=False;Jet OLEDB:Bypass UserInfo Validation=True"
connStrAccess = "Provider=%(provider)s;Data Source=%(mdb)s"
print(" ...Testing ACCESS connection to {} file...".format(c["mdb"]))
doAccessTest, connStrAccess, dbAccessconnect = tryconnection.try_connection(
verbose, connStrAccess, 10, **c
)
if doSqlServerTest:
c = {
"host": SQL_HOST_NODE, # name of computer with SQL Server
"database": "adotest",
"user": "adotestuser", # None implies Windows security
"password": "Sq1234567",
# macro definition for keyword "security" using macro "auto_security"
"macro_auto_security": "security",
"provider": "MSOLEDBSQL; MARS Connection=True",
}
connStr = "Provider=%(provider)s; Initial Catalog=%(database)s; Data Source=%(host)s; %(security)s;"
print(" ...Testing MS-SQL login to {}...".format(c["host"]))
(
doSqlServerTest,
connStrSQLServer,
dbSqlServerconnect,
) = tryconnection.try_connection(verbose, connStr, 30, **c)
if doMySqlTest:
c = {
"host": "testmysql.2txt.us",
"database": "adodbapitest",
"user": "adotest",
"password": "12345678",
"port": "3330", # note the nonstandard port for obfuscation
"driver": "MySQL ODBC 5.1 Driver",
} # or _driver="MySQL ODBC 3.51 Driver
c["macro_is64bit"] = [
"provider",
"Provider=MSDASQL;",
] # turn on the 64 bit ODBC adapter only if needed
cs = (
"%(provider)sDriver={%(driver)s};Server=%(host)s;Port=3330;"
+ "Database=%(database)s;user=%(user)s;password=%(password)s;Option=3;"
)
print(" ...Testing MySql login to {}...".format(c["host"]))
doMySqlTest, connStrMySql, dbMySqlconnect = tryconnection.try_connection(
verbose, cs, 5, **c
)
if doPostgresTest:
_computername = "testpg.2txt.us"
_databasename = "adotest"
_username = "adotestuser"
_password = "12345678"
kws = {"timeout": 4}
kws["macro_is64bit"] = [
"prov_drv",
"Provider=MSDASQL;Driver={PostgreSQL Unicode(x64)}",
"Driver=PostgreSQL Unicode",
]
# get driver from http://www.postgresql.org/ftp/odbc/versions/
# test using positional and keyword arguments (bad example for real code)
print(" ...Testing PostgreSQL login to {}...".format(_computername))
doPostgresTest, connStrPostgres, dbPostgresConnect = tryconnection.try_connection(
verbose,
"%(prov_drv)s;Server=%(host)s;Database=%(database)s;uid=%(user)s;pwd=%(password)s;port=5430;", # note nonstandard port
_username,
_password,
_computername,
_databasename,
**kws,
)
assert (
doAccessTest or doSqlServerTest or doMySqlTest or doPostgresTest
), "No database engine found for testing"
|