Updated the inline documentation of the `convert_named_query_params` to reflect the changes made to its API. Updated the rhnsql-tests to the new API. --- backend/server/rhnSQL/driver_postgresql.py | 6 +---- .../server/test/unit-test/rhnSQL/rhnsql-tests.py | 31 +++++----------------- 2 files changed, 8 insertions(+), 29 deletions(-)
diff --git a/backend/server/rhnSQL/driver_postgresql.py b/backend/server/rhnSQL/driver_postgresql.py index 0ca640a..a814556 100644 --- a/backend/server/rhnSQL/driver_postgresql.py +++ b/backend/server/rhnSQL/driver_postgresql.py @@ -46,11 +46,7 @@ def convert_named_query_params(query): existing queries intact we'll convert them when provided to the postgresql driver. - RETURNS: tuple with: - - the new query with parameters replaced - - hash of each named parameter to an ordered list of the positions - where it was used. - - number of arguments found and replaced + RETURNS: the new query with parameters replaced """ log_debug(6, "Converting query for PostgreSQL: %s" % query) new_query = re.sub(r'(\W):(\w+)', r'\1%(\2)s', query.replace('%', '%%')) diff --git a/backend/server/test/unit-test/rhnSQL/rhnsql-tests.py b/backend/server/test/unit-test/rhnSQL/rhnsql-tests.py index 926a9c9..39aeeb0 100644 --- a/backend/server/test/unit-test/rhnSQL/rhnsql-tests.py +++ b/backend/server/test/unit-test/rhnSQL/rhnsql-tests.py @@ -29,45 +29,28 @@ class RhnSQLTests(unittest.TestCase): 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)" + "INSERT INTO people(id, name, phone) VALUES(%(id)s, %(name)s, %(phone)s)" - (new_query, param_index, args_found) = convert_named_query_params(query) + new_query = 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) + new_query = 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)" + "INSERT INTO people(a, b, c, d) VALUES(%(a)s, %(b)s, %(a)s, %(b)s)" - (new_query, param_index, args_found) = convert_named_query_params(query) + new_query = 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) + expected_query = "SELECT TO_CHAR(issued, 'YYYY-MM-DD HH24:MI:SS') issued FROM rhnSatelliteCert WHERE id=%(id)s, name=%(name)s" + new_query = 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