Funktionierender Prototyp des Serious Games zur Vermittlung von Wissen zu Software-Engineering-Arbeitsmodellen.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

adodbapitestconfig.py 7.4KB

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