Skip to content

Commit

Permalink
Added tests to ensure the different cases are covered zacharyvoase#4
Browse files Browse the repository at this point in the history
  • Loading branch information
Scott Walton committed May 9, 2013
1 parent 07e433f commit 8637ce4
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
2 changes: 1 addition & 1 deletion django_postgres/function.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ def create_function(connection, function_name, function_fields,
cursor.execute(function_sql)
ret = 'UPDATED' if function_exists else 'CREATED'
else:
ret = 'ERROR: Manually Drop This View'
ret = 'ERROR: Manually Drop This Function'

transaction.commit_unless_managed()
return ret
Expand Down
31 changes: 31 additions & 0 deletions tests/test_project/functiontest/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,34 @@ def test_create_function(self):
created = create_function(connection, name, field, definition)

self.assertEqual(created, 'CREATED')

def test_update_function(self):
"""Update a function with create_function. Functions can only be
updated if their signature matches the existing function.
"""
field = ('a_field integer', )
definition = 'SELECT 1 from auth_user WHERE id = $1'
name = 'my_function (integer)'
create_function(connection, name, field, definition)

definition = 'SELECT 2 from auth_user WHERE id = $1'

updated = create_function(connection, name, field, definition)

self.assertEqual(updated, 'UPDATED')

def test_error_function(self):
"""Error out if the user tried to update a function with an
incompatible signature.
"""
field = ('a_field integer', )
definition = 'SELECT 1 from auth_user WHERE id = $1'
name = 'my_function (integer)'
create_function(connection, name, field, definition)

name = 'my_function (integer, integer)'
definition = 'SELECT 1 from auth_user WHERE id > $1 and id < $2'

updated = create_function(connection, name, field, definition)

self.assertEqual(updated, 'ERROR: Manually Drop This Function')

0 comments on commit 8637ce4

Please sign in to comment.