-
Notifications
You must be signed in to change notification settings - Fork 41
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Account for sql.SQL
and sql.Composed
Objects
#177
Merged
Merged
Changes from 1 commit
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
262b279
Fix ignore logic
max-muoto 73d8b05
Tweaks
max-muoto 7f77251
Fix
max-muoto 4f9be10
Merge branch 'main' of https://github.com/Opus10/django-pgtrigger int…
max-muoto 6ae5a86
Fix tests
max-muoto b662560
Under type-checking block
max-muoto efa81ee
Fix multiline
max-muoto aa45eeb
Remove unused kwarg
max-muoto bc0ec26
Fix
max-muoto 70e9ec0
Support psycopg2
max-muoto d4ad59a
Tweak
max-muoto c6f1d50
Tweak error
max-muoto 38801ed
Add pragma
max-muoto File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,6 +6,14 @@ | |
import pgtrigger.utils | ||
from pgtrigger.tests import models, utils | ||
|
||
if pgtrigger.utils.psycopg_maj_version == 3: | ||
from psycopg.sql import SQL, Literal | ||
else: | ||
from unittest.mock import MagicMock | ||
|
||
SQL = MagicMock() | ||
Literal = MagicMock() | ||
|
||
|
||
@pytest.mark.django_db | ||
def test_schema(): | ||
|
@@ -228,20 +236,26 @@ def test_custom_db_table_ignore(): | |
assert not models.CustomTableName.objects.exists() | ||
|
||
|
||
@pytest.mark.skipif( | ||
pgtrigger.utils.psycopg_maj_version == 3, reason="Psycopg2 preserves entire query" | ||
) | ||
@pytest.mark.django_db | ||
@pytest.mark.parametrize( | ||
"sql, params", | ||
"sql, params, min_psycopg_version", | ||
[ | ||
("select count(*) from auth_user where id = %s", (1,)), | ||
("select count(*) from auth_user", ()), | ||
(b"select count(*) from auth_user where id = %s", (1,)), | ||
(b"select count(*) from auth_user", ()), | ||
("select count(*) from auth_user where id = %s", (1,), 2), | ||
("select count(*) from auth_user", (), 2), | ||
(b"select count(*) from auth_user where id = %s", (1,), 2), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It makes sense to run these on 3 as the query can still technically be bytes. See https://github.com/psycopg/psycopg/blob/master/psycopg/psycopg/abc.py#L30 |
||
(b"select count(*) from auth_user", (), 2), | ||
(SQL("select count(*) from auth_user where id = %s"), (1,), 3), | ||
( # Formatting creates a composed object | ||
SQL("select {lit}").format(lit=Literal(1)), | ||
(), | ||
3, | ||
), | ||
], | ||
) | ||
def test_inject_trigger_ignore(settings, mocker, sql, params): | ||
def test_inject_trigger_ignore(settings, mocker, sql, params, min_psycopg_version): | ||
if pgtrigger.utils.psycopg_maj_version < min_psycopg_version: | ||
pytest.skip("Psycopg version is less than {}".format(min_psycopg_version)) | ||
|
||
settings.DEBUG = True | ||
expected_sql_base = "SELECT set_config('pgtrigger.ignore', '{ignored_triggers}', true)" | ||
# Order isn't deterministic, so we need to check for either order. | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just to avoid the parameterization failing on 3.