Move the rhnsql-test into the directory containing all the test covering the rhnSQL module.
This makes possible to run the test using nosetests. That wasn't possible previously because of an import error. The test imports a function from `spacewalk.server.rhnSQL.driver_postgresql`. The import statement works fine from python's interactive shell, but not from nosetets. That happens because nosetests prepends the directory containing all the test files to the `PYTHONPATH`. With `rhnsql-tests.py` located inside of `/git_chekout/backend/test/unit/spacewalk/test/server` the PYTHONPATH used by nosetest is going to have `/git_checkout/backend/test/unit` as first element. That will cause nosetest to look for `spacewalk.server` module inside of `/git_checkout/backend/test/unit/spacewalk`. This directory actually exists on the system, but it just contains the test files. The right directory to load is `/path_to_python_modules/spacewalk/server`. --- .../server/test/unit-test/rhnSQL/rhnsql-tests.py | 73 ++++++++++++++++++++++ .../unit/spacewalk/test/server/rhnsql-tests.py | 73 ---------------------- 2 files changed, 73 insertions(+), 73 deletions(-) create mode 100644 backend/server/test/unit-test/rhnSQL/rhnsql-tests.py delete mode 100644 backend/test/unit/spacewalk/test/server/rhnsql-tests.py diff --git a/backend/server/test/unit-test/rhnSQL/rhnsql-tests.py b/backend/server/test/unit-test/rhnSQL/rhnsql-tests.py new file mode 100644 index 0000000..926a9c9 --- /dev/null +++ b/backend/server/test/unit-test/rhnSQL/rhnsql-tests.py @@ -0,0 +1,73 @@ +# +# Copyright (c) 2008--2010 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. +# + +""" +Pure unit tests for components of rhnSQL. + +NOTE: Not hitting the database here! +""" + +import unittest + +from spacewalk.server.rhnSQL.driver_postgresql import convert_named_query_params + +class RhnSQLTests(unittest.TestCase): + """ Pure unit tests for components of rhnSQL. """ + + def test_convert_named_query_params(self): + query = "INSERT INTO people(id, name, phone) VALUES(:id, :name, :phone)" + expected_query = \ + "INSERT INTO people(id, name, phone) VALUES($1, $2, $3)" + + (new_query, param_index, args_found) = convert_named_query_params(query) + self.assertEquals(expected_query, new_query) + self.assertEquals(3, len(param_index.keys())) + self.assertEquals(3, args_found) + self.assertEquals([1], param_index['id']) + self.assertEquals([2], param_index['name']) + self.assertEquals([3], param_index['phone']) + + def test_convert_named_params_none_required(self): + query = "SELECT * FROM people" + + (new_query, param_index, args_found) = convert_named_query_params(query) + self.assertEquals(query, new_query) + self.assertEquals(0, len(param_index.keys())) + + def test_convert_named_params_multiple_uses(self): + query = "INSERT INTO people(a, b, c, d) VALUES(:a, :b, :a, :b)" + expected_query = \ + "INSERT INTO people(a, b, c, d) VALUES($1, $2, $3, $4)" + + (new_query, param_index, args_found) = convert_named_query_params(query) + self.assertEquals(expected_query, new_query) + self.assertEquals(4, args_found) + self.assertEquals(2, len(param_index.keys())) + self.assertEquals([1, 3], param_index['a']) + self.assertEquals([2, 4], param_index['b']) + + def test_date_format_conversion_issue(self): + query = "SELECT TO_CHAR(issued, 'YYYY-MM-DD HH24:MI:SS') issued FROM rhnSatelliteCert WHERE id=:id, name=:name" + expected_query = "SELECT TO_CHAR(issued, 'YYYY-MM-DD HH24:MI:SS') issued FROM rhnSatelliteCert WHERE id=$1, name=$2" + (new_query, param_index, args_found) = convert_named_query_params(query) + self.assertEquals(expected_query, new_query) + self.assertEquals(2, args_found) + self.assertEquals(2, len(param_index.keys())) + self.assertEquals([1], param_index['id']) + self.assertEquals([2], param_index['name']) + + + + diff --git a/backend/test/unit/spacewalk/test/server/rhnsql-tests.py b/backend/test/unit/spacewalk/test/server/rhnsql-tests.py deleted file mode 100644 index 926a9c9..0000000 --- a/backend/test/unit/spacewalk/test/server/rhnsql-tests.py +++ /dev/null @@ -1,73 +0,0 @@ -# -# Copyright (c) 2008--2010 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. -# - -""" -Pure unit tests for components of rhnSQL. - -NOTE: Not hitting the database here! -""" - -import unittest - -from spacewalk.server.rhnSQL.driver_postgresql import convert_named_query_params - -class RhnSQLTests(unittest.TestCase): - """ Pure unit tests for components of rhnSQL. """ - - def test_convert_named_query_params(self): - query = "INSERT INTO people(id, name, phone) VALUES(:id, :name, :phone)" - expected_query = \ - "INSERT INTO people(id, name, phone) VALUES($1, $2, $3)" - - (new_query, param_index, args_found) = convert_named_query_params(query) - self.assertEquals(expected_query, new_query) - self.assertEquals(3, len(param_index.keys())) - self.assertEquals(3, args_found) - self.assertEquals([1], param_index['id']) - self.assertEquals([2], param_index['name']) - self.assertEquals([3], param_index['phone']) - - def test_convert_named_params_none_required(self): - query = "SELECT * FROM people" - - (new_query, param_index, args_found) = convert_named_query_params(query) - self.assertEquals(query, new_query) - self.assertEquals(0, len(param_index.keys())) - - def test_convert_named_params_multiple_uses(self): - query = "INSERT INTO people(a, b, c, d) VALUES(:a, :b, :a, :b)" - expected_query = \ - "INSERT INTO people(a, b, c, d) VALUES($1, $2, $3, $4)" - - (new_query, param_index, args_found) = convert_named_query_params(query) - self.assertEquals(expected_query, new_query) - self.assertEquals(4, args_found) - self.assertEquals(2, len(param_index.keys())) - self.assertEquals([1, 3], param_index['a']) - self.assertEquals([2, 4], param_index['b']) - - def test_date_format_conversion_issue(self): - query = "SELECT TO_CHAR(issued, 'YYYY-MM-DD HH24:MI:SS') issued FROM rhnSatelliteCert WHERE id=:id, name=:name" - expected_query = "SELECT TO_CHAR(issued, 'YYYY-MM-DD HH24:MI:SS') issued FROM rhnSatelliteCert WHERE id=$1, name=$2" - (new_query, param_index, args_found) = convert_named_query_params(query) - self.assertEquals(expected_query, new_query) - self.assertEquals(2, args_found) - self.assertEquals(2, len(param_index.keys())) - self.assertEquals([1], param_index['id']) - self.assertEquals([2], param_index['name']) - - - - -- 1.8.4 _______________________________________________ Spacewalk-devel mailing list Spacewalk-devel@redhat.com https://www.redhat.com/mailman/listinfo/spacewalk-devel