--- backend/server/test/cx_create_table.py | 68 ++++++++++++++++ backend/server/test/test_capabilities.py | 94 ++++++++++++++++++++++ backend/server/test/unit-test/cx_create_table.py | 68 ---------------- backend/server/test/unit-test/test_capabilities.py | 94 ---------------------- 4 files changed, 162 insertions(+), 162 deletions(-) create mode 100644 backend/server/test/cx_create_table.py create mode 100644 backend/server/test/test_capabilities.py delete mode 100644 backend/server/test/unit-test/cx_create_table.py delete mode 100644 backend/server/test/unit-test/test_capabilities.py
diff --git a/backend/server/test/cx_create_table.py b/backend/server/test/cx_create_table.py new file mode 100644 index 0000000..31e23c6 --- /dev/null +++ b/backend/server/test/cx_create_table.py @@ -0,0 +1,68 @@ +# +# Copyright (c) 2008 Red Hat, Inc. +# +# This software is licensed to you under the GNU General Public License, +# version 2 (GPLv2). There is NO WARRANTY for this software, express or +# implied, including the implied warranties of MERCHANTABILITY or FITNESS +# FOR A PARTICULAR PURPOSE. You should have received a copy of GPLv2 +# along with this software; if not, see +# http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt. +# +# Red Hat trademarks are not licensed under GPLv2. No permission is +# granted to use or replicate Red Hat trademarks that are incorporated +# in this software or its documentation. +# +import os +import sys +import cx_Oracle + +def main(): + if len(sys.argv) != 2: + sys.stdout.write("Usage: %s <connectstring>\n" % sys.argv[0]) + return 1 + dbh = cx_Oracle.connect(sys.argv[1]) + + table_name = "test_%d" % os.getpid() + if 1: + test2(dbh, table_name) + else: + test1(dbh, table_name) + test1(dbh, table_name) + +def test1(dbh, table_name): + tn = table_name.upper() + create_table(dbh, table_name) + assert tn in list_tables(dbh), "Table %s not created" % table_name + drop_table(dbh, table_name) + assert tn not in list_tables(dbh), "Table %s not dropped" % table_name + +def test2(dbh, table_name): + tn = table_name.upper() + h1 = create_table(dbh, table_name) + assert tn in list_tables(dbh), "Table %s not created" % table_name + h2 = drop_table(dbh, table_name) + assert tn not in list_tables(dbh), "Table %s not dropped" % table_name + + + h1.execute(None) + assert tn in list_tables(dbh), "Table %s not created" % table_name + h2.execute(None) + assert tn not in list_tables(dbh), "Table %s not dropped" % table_name + +def create_table(dbh, table_name): + h = dbh.cursor() + h.execute("create table %s (id int)" % table_name) + return h + +def drop_table(dbh, table_name): + h = dbh.cursor() + h.execute("drop table %s" % table_name) + return h + +def list_tables(dbh): + h = dbh.cursor() + h.execute("select table_name from user_tables") + return map(lambda x: x[0].upper(), h.fetchall()) + +if __name__ == '__main__': + sys.exit(main() or 0) diff --git a/backend/server/test/test_capabilities.py b/backend/server/test/test_capabilities.py new file mode 100644 index 0000000..e5b709d --- /dev/null +++ b/backend/server/test/test_capabilities.py @@ -0,0 +1,94 @@ +#!/usr/bin/python +# +# Copyright (c) 2008--2011 Red Hat, Inc. +# +# This software is licensed to you under the GNU General Public License, +# version 2 (GPLv2). There is NO WARRANTY for this software, express or +# implied, including the implied warranties of MERCHANTABILITY or FITNESS +# FOR A PARTICULAR PURPOSE. You should have received a copy of GPLv2 +# along with this software; if not, see +# http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt. +# +# Red Hat trademarks are not licensed under GPLv2. No permission is +# granted to use or replicate Red Hat trademarks that are incorporated +# in this software or its documentation. +# +# +# test case for bugzilla 127319 +# +# Usage: ./xxx.py <server-name> <db> +# + +import os +import sys + +_topdir = os.path.dirname(sys.argv[0]) +_basedir = os.path.abspath(_topdir + '/../..') +if _basedir not in sys.path: + sys.path.append(_basedir) + +import time +from rhn import rpclib +from spacewalk.server import rhnSQL, rhnServer, rhnCapability +from spacewalk.common.rhnConfig import ConfigParserError + +def main(): + if len(sys.argv) == 1: + server_name = 'xmlrpc.rhn.webdev.redhat.com' + else: + server_name = sys.argv[1] + + if len(sys.argv) <= 2: + db_name = 'rhnuser/rhnuser@webdev' + else: + db_name = sys.argv[2] + + try: + rhnSQL.initDB(db_name) + except ConfigParserError: + # database is not available when running in rpmbuild time + print "Test skipped" + return 0 + + uri = "http://%s/XMLRPC" % (server_name, ) + s = rpclib.Server(uri) + + username = password = "test-username-%.3f" % time.time() + email = "misa...@redhat.com" % username + + s.registration.reserve_user(username, password) + s.registration.new_user(username, password, email) + + data = { + 'os_release' : '9', + 'architecture' : 'athlon-redhat-linux', + 'profile_name' : 'Test profile for %s' % username, + 'username' : username, + 'password' : password, + } + systemid = s.registration.new_system(data) + + str_caps = [ + 'this.is.bogus1(0)=0', + 'this.is.bogus2(1)=1', + 'this.is.bogus3(2)=2', + ] + for cap in str_caps: + s.add_header('X-RHN-Client-Capability', cap) + + # Add some packages + packages = [ + ['a', '1', '1', ''], + ['b', '2', '2', ''], + ['c', '3', '3', ''], + ] + s.registration.update_packages(systemid, packages) + + sobj = rhnServer.get(systemid) + server_id = sobj.getid() + print "Registered server", server_id + + return 0 + +if __name__ == '__main__': + sys.exit(main() or 0) diff --git a/backend/server/test/unit-test/cx_create_table.py b/backend/server/test/unit-test/cx_create_table.py deleted file mode 100644 index 31e23c6..0000000 --- a/backend/server/test/unit-test/cx_create_table.py +++ /dev/null @@ -1,68 +0,0 @@ -# -# Copyright (c) 2008 Red Hat, Inc. -# -# This software is licensed to you under the GNU General Public License, -# version 2 (GPLv2). There is NO WARRANTY for this software, express or -# implied, including the implied warranties of MERCHANTABILITY or FITNESS -# FOR A PARTICULAR PURPOSE. You should have received a copy of GPLv2 -# along with this software; if not, see -# http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt. -# -# Red Hat trademarks are not licensed under GPLv2. No permission is -# granted to use or replicate Red Hat trademarks that are incorporated -# in this software or its documentation. -# -import os -import sys -import cx_Oracle - -def main(): - if len(sys.argv) != 2: - sys.stdout.write("Usage: %s <connectstring>\n" % sys.argv[0]) - return 1 - dbh = cx_Oracle.connect(sys.argv[1]) - - table_name = "test_%d" % os.getpid() - if 1: - test2(dbh, table_name) - else: - test1(dbh, table_name) - test1(dbh, table_name) - -def test1(dbh, table_name): - tn = table_name.upper() - create_table(dbh, table_name) - assert tn in list_tables(dbh), "Table %s not created" % table_name - drop_table(dbh, table_name) - assert tn not in list_tables(dbh), "Table %s not dropped" % table_name - -def test2(dbh, table_name): - tn = table_name.upper() - h1 = create_table(dbh, table_name) - assert tn in list_tables(dbh), "Table %s not created" % table_name - h2 = drop_table(dbh, table_name) - assert tn not in list_tables(dbh), "Table %s not dropped" % table_name - - - h1.execute(None) - assert tn in list_tables(dbh), "Table %s not created" % table_name - h2.execute(None) - assert tn not in list_tables(dbh), "Table %s not dropped" % table_name - -def create_table(dbh, table_name): - h = dbh.cursor() - h.execute("create table %s (id int)" % table_name) - return h - -def drop_table(dbh, table_name): - h = dbh.cursor() - h.execute("drop table %s" % table_name) - return h - -def list_tables(dbh): - h = dbh.cursor() - h.execute("select table_name from user_tables") - return map(lambda x: x[0].upper(), h.fetchall()) - -if __name__ == '__main__': - sys.exit(main() or 0) diff --git a/backend/server/test/unit-test/test_capabilities.py b/backend/server/test/unit-test/test_capabilities.py deleted file mode 100644 index 908dbdc..0000000 --- a/backend/server/test/unit-test/test_capabilities.py +++ /dev/null @@ -1,94 +0,0 @@ -#!/usr/bin/python -# -# Copyright (c) 2008--2011 Red Hat, Inc. -# -# This software is licensed to you under the GNU General Public License, -# version 2 (GPLv2). There is NO WARRANTY for this software, express or -# implied, including the implied warranties of MERCHANTABILITY or FITNESS -# FOR A PARTICULAR PURPOSE. You should have received a copy of GPLv2 -# along with this software; if not, see -# http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt. -# -# Red Hat trademarks are not licensed under GPLv2. No permission is -# granted to use or replicate Red Hat trademarks that are incorporated -# in this software or its documentation. -# -# -# test case for bugzilla 127319 -# -# Usage: ./xxx.py <server-name> <db> -# - -import os -import sys - -_topdir = os.path.dirname(sys.argv[0]) -_basedir = os.path.abspath(_topdir + '/../../..') -if _basedir not in sys.path: - sys.path.append(_basedir) - -import time -from rhn import rpclib -from spacewalk.server import rhnSQL, rhnServer, rhnCapability -from spacewalk.common.rhnConfig import ConfigParserError - -def main(): - if len(sys.argv) == 1: - server_name = 'xmlrpc.rhn.webdev.redhat.com' - else: - server_name = sys.argv[1] - - if len(sys.argv) <= 2: - db_name = 'rhnuser/rhnuser@webdev' - else: - db_name = sys.argv[2] - - try: - rhnSQL.initDB(db_name) - except ConfigParserError: - # database is not available when running in rpmbuild time - print "Test skipped" - return 0 - - uri = "http://%s/XMLRPC" % (server_name, ) - s = rpclib.Server(uri) - - username = password = "test-username-%.3f" % time.time() - email = "misa...@redhat.com" % username - - s.registration.reserve_user(username, password) - s.registration.new_user(username, password, email) - - data = { - 'os_release' : '9', - 'architecture' : 'athlon-redhat-linux', - 'profile_name' : 'Test profile for %s' % username, - 'username' : username, - 'password' : password, - } - systemid = s.registration.new_system(data) - - str_caps = [ - 'this.is.bogus1(0)=0', - 'this.is.bogus2(1)=1', - 'this.is.bogus3(2)=2', - ] - for cap in str_caps: - s.add_header('X-RHN-Client-Capability', cap) - - # Add some packages - packages = [ - ['a', '1', '1', ''], - ['b', '2', '2', ''], - ['c', '3', '3', ''], - ] - s.registration.update_packages(systemid, packages) - - sobj = rhnServer.get(systemid) - server_id = sobj.getid() - print "Registered server", server_id - - return 0 - -if __name__ == '__main__': - sys.exit(main() or 0) -- 1.8.4 _______________________________________________ Spacewalk-devel mailing list Spacewalk-devel@redhat.com https://www.redhat.com/mailman/listinfo/spacewalk-devel