-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #70 from peopledoc/customize-columns
- Loading branch information
Showing
12 changed files
with
155 additions
and
149 deletions.
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
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
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
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 |
---|---|---|
@@ -0,0 +1,45 @@ | ||
from septentrion import core | ||
|
||
|
||
def test_initialize(db): | ||
|
||
settings_kwargs = { | ||
# database connection settings | ||
"host": db["host"], | ||
"port": db["port"], | ||
"username": db["user"], | ||
"dbname": db["dbname"], | ||
# migrate settings | ||
"target_version": "1.1", | ||
"migrations_root": "example_migrations", | ||
} | ||
|
||
# create table with no error | ||
core.initialize(**settings_kwargs) | ||
# action is idempotent, no error either | ||
core.initialize(**settings_kwargs) | ||
|
||
|
||
def test_initialize_customize_names(db): | ||
|
||
settings_kwargs = { | ||
# database connection settings | ||
"host": db["host"], | ||
"port": db["port"], | ||
"username": db["user"], | ||
"dbname": db["dbname"], | ||
# migrate settings | ||
"target_version": "1.1", | ||
"migrations_root": "example_migrations", | ||
# customize table | ||
"table": "my_own_table", | ||
# customize columns | ||
"name_column": "name_custo", | ||
"version_column": "version_custo", | ||
"applied_at_column": "applied_custo", | ||
} | ||
|
||
# create table with no error | ||
core.initialize(**settings_kwargs) | ||
# action is idempotent, no error either | ||
core.initialize(**settings_kwargs) |
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 |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import psycopg2.errors | ||
import pytest | ||
|
||
from septentrion import db as db_module | ||
|
||
|
||
def test_execute(db, settings_factory): | ||
settings = settings_factory(**db) | ||
with db_module.execute(settings=settings, query="SELECT 1;") as cursor: | ||
assert cursor.fetchall() == [[1]] | ||
|
||
|
||
def test_execute_sql_injection(db, settings_factory): | ||
settings = settings_factory(**db, table='"pg_enum"; -- SQLi') | ||
with pytest.raises(psycopg2.errors.UndefinedTable) as exc_info: | ||
with db_module.execute( | ||
settings=settings, query="SELECT * FROM {table};" | ||
) as cursor: | ||
assert cursor.fetchall() == [[1]] | ||
|
||
assert 'relation ""pg_enum"; -- SQLi" does not exist' in str(exc_info.value) |
Oops, something went wrong.