Skip to content

Commit

Permalink
customize test function names
Browse files Browse the repository at this point in the history
this is an effort to have the test suite run when all tests are executed.. this smells a little, but for now it will have to do.
  • Loading branch information
radusuciu committed Feb 28, 2024
1 parent 0b3724a commit 77f9480
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 15 deletions.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ dev = [
]

[tool.pytest.ini_options]
addopts = "'--docker-compose' './tests/docker-compose.yml' '--docker-compose-no-build' '--use-running-containers' '--sw'"
addopts = "'--docker-compose' './tests/docker-compose.yml' '--docker-compose-no-build' '--use-running-containers'"
DJANGO_SETTINGS_MODULE = "test_project.settings"

[tool.ruff]
Expand Down
28 changes: 14 additions & 14 deletions tests/test_change_detection.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class FirstOfTwo(SqlFun):
IMMUTABLE;
"""

migration_paths = make_sqlfun_migrations()
migration_paths = make_sqlfun_migrations('changed_body')
call_command('migrate')

assert function_exists('first_of_two')
Expand All @@ -36,7 +36,7 @@ class FirstOfTwo(SqlFun):

FirstOfTwo.sql = FirstOfTwo.sql.replace('SELECT first', 'SELECT second')

migration_paths.extend(make_sqlfun_migrations())
migration_paths.extend(make_sqlfun_migrations('changed_body'))
call_command('migrate')

with connection.cursor() as cursor:
Expand All @@ -53,7 +53,7 @@ class FirstOfTwo(SqlFun):
"""Returns the sum of two numbers plus one."""
app_label = 'test_project'
sql = """
CREATE OR REPLACE FUNCTION first_of_two(
CREATE OR REPLACE FUNCTION first_of_two_deleted(
first integer,
second integer
) RETURNS integer as $$
Expand All @@ -63,21 +63,21 @@ class FirstOfTwo(SqlFun):
IMMUTABLE;
"""

migrations_paths = make_sqlfun_migrations()
migrations_paths = make_sqlfun_migrations('deleted_function')
call_command('migrate')

assert function_exists('first_of_two')
assert function_exists('first_of_two_deleted')

FirstOfTwo.deregister()

migrations_paths.extend(make_sqlfun_migrations())
migrations_paths.extend(make_sqlfun_migrations('deleted_function'))
call_command('migrate')

assert not function_exists('first_of_two')
assert not function_exists('first_of_two_deleted')

with connection.cursor() as cursor:
with pytest.raises(Exception):
cursor.execute('SELECT first_of_two(1, 2)')
cursor.execute('SELECT first_of_two_deleted(1, 2)')

for path in migrations_paths:
path.unlink()
Expand All @@ -89,7 +89,7 @@ class FirstOfTwo(SqlFun):
"""Returns the sum of two numbers plus one."""
app_label = 'test_project'
sql = """
CREATE OR REPLACE FUNCTION first_of_two(
CREATE OR REPLACE FUNCTION first_of_two_change_parameter_number(
first integer,
second integer
) RETURNS integer as $$
Expand All @@ -99,23 +99,23 @@ class FirstOfTwo(SqlFun):
IMMUTABLE;
"""

migration_paths = make_sqlfun_migrations()
migration_paths = make_sqlfun_migrations('change_parameter_number')
call_command('migrate')

assert function_exists('first_of_two')
assert function_exists('first_of_two_change_parameter_number')

FirstOfTwo.sql = FirstOfTwo.sql.replace('first integer', 'first integer, third integer')

migration_paths.extend(make_sqlfun_migrations())
migration_paths.extend(make_sqlfun_migrations('change_parameter_number'))
call_command('migrate')

with connection.cursor() as cursor:
cursor.execute('SELECT first_of_two(1, 2, 3)')
cursor.execute('SELECT first_of_two_change_parameter_number(1, 2, 3)')
assert cursor.fetchone()[0] == 1

# test that exception is raised if we don't pass in the third parameter
with pytest.raises(Exception):
cursor.execute('SELECT first_of_two(1, 2, 3, 4)')
cursor.execute('SELECT first_of_two_change_parameter_number(1, 2, 3, 4)')

for path in migration_paths:
path.unlink()

0 comments on commit 77f9480

Please sign in to comment.