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
|
# Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved.
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License as
# published by the Free Software Foundation; version 2 of the
# License.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
# 02110-1301 USA
import os
import sys
import glob
import unittest
import grt
try:
import coverage
except ImportError:
has_coverage = False
else:
has_coverage = True
CURRENT_DIR = os.path.abspath(os.path.dirname(__file__))
SRC_DIR = os.path.abspath(os.path.join(CURRENT_DIR, '../../../'))
test_params = { 'hostName' :'172.16.0.1',
'port' :1433,
'database' :'AdventureWorks',
'user' :'testuser',
'password' :'c3poLATxce090'
}
def create_connection(hostName, port, database, user, password=''):
driver = None
for i in grt.root.wb.rdbmsMgmt.rdbms:
if i.name == 'Mssql':
driver = i.defaultDriver
break
conn = None
if driver:
conn = grt.classes.db_mgmt_Connection()
conn.driver = driver
conn.name = hostName + ":" + str(port)
conn.hostIdentifier = "Mssql@" + conn.name
params = conn.parameterValues
params['hostName'] = hostName
params['port'] = port
params['database'] = database
params['userName'] = user
params['%userName%::Mssql@%hostName%:%port%'] = '%userName%::Mssql@%hostName%:%port%'
params['password'] = password
return conn
class MigrationTestCase(unittest.TestCase):
connection = create_connection(**test_params)
if __name__ == '__main__':
if has_coverage:
cov = coverage.coverage()
cov.start()
os.chdir(CURRENT_DIR)
sys.path[:0] = [ CURRENT_DIR, os.path.join(SRC_DIR, 'library/python') ]
suite = unittest.TestSuite()
names = [ os.path.splitext(fname)[0] for fname in glob.glob("test_*.py") ]
suite.addTest(unittest.defaultTestLoader.loadTestsFromNames(names))
result = unittest.TextTestRunner(stream=open(os.path.join(SRC_DIR, 'testing/python/test_results_migration.txt'), 'w'), verbosity=2).run(suite)
if has_coverage:
cov.stop()
report_file = open(os.path.join(SRC_DIR, 'testing/python/coverage_migration_report.txt'), 'a')
cov.report(file=report_file)
report_file.write('\n\n')
if not result.wasSuccessful():
sys.exit(1)
|