Skip to content
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

use python-sql instead of psycopg.sql for generating sql-queries #83

Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions dev/setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,12 @@ extend-ignore = E203,E501

[mypy]
disallow_untyped_defs = true

[mypy-sql.*]
ignore_missing_imports = true

[mypy-python_sql.*]
ignore_missing_imports = true

[mypy-helper_get_names.*]
ignore_missing_imports = true
jsangmeister marked this conversation as resolved.
Show resolved Hide resolved
2 changes: 1 addition & 1 deletion dev/sql/schema_relational.sql
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ BEGIN
END;
$$ LANGUAGE plpgsql;

-- MODELS_YML_CHECKSUM = '959d3a581a8015a294d769587ebb1b6e'
-- MODELS_YML_CHECKSUM = '385e6beb7945826015352886f2d0f97b'
-- Type definitions

-- Table definitions
Expand Down
Empty file added dev/src/__init__.py
Empty file.
2 changes: 1 addition & 1 deletion dev/src/db_utils.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from typing import Any

from sql import Column, Table # type: ignore
from src.python_sql import Column, Table
jsangmeister marked this conversation as resolved.
Show resolved Hide resolved


class DbUtils:
Expand Down
2 changes: 2 additions & 0 deletions dev/src/python_sql.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# imports from sql for usage with type: ignore, because mypy don'T recognize the original import
jsangmeister marked this conversation as resolved.
Show resolved Hide resolved
from sql import Column, Table # type: ignore # noqa:F401
8 changes: 4 additions & 4 deletions dev/tests/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
from psycopg import sql
from psycopg.types.json import Jsonb

from sql import Table
from src.db_utils import DbUtils
from src.python_sql import Table

# ADMIN_USERNAME = "admin"
# ADMIN_PASSWORD = "admin"
Expand All @@ -16,7 +16,7 @@
class BaseTestCase(TestCase):
temporary_template_db = "openslides_template"
work_on_test_db = "openslides_test"
db_connection: psycopg.Connection = None
db_connection: psycopg.Connection

# id's of pre loaded rows, see method populate_database
meeting1_id = 0
Expand Down Expand Up @@ -49,7 +49,7 @@ def set_db_connection(
raise Exception(f"Cannot connect to postgres: {e.message}")

@classmethod
def setup_class(cls):
def setup_class(cls) -> None:
env = os.environ
cls.set_db_connection("postgres", True)
with cls.db_connection:
Expand All @@ -76,7 +76,7 @@ def setup_class(cls):
cls.populate_database()

@classmethod
def teardown_class(cls):
def teardown_class(cls) -> None:
"""remove last test db and drop the temporary template db"""
cls.set_db_connection("postgres", True)
with cls.db_connection:
Expand Down
10 changes: 6 additions & 4 deletions dev/tests/test_generic_relations.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
from typing import Any

import psycopg
import pytest
from psycopg import sql

from sql import Table
from src.db_utils import DbUtils
from src.python_sql import Table
from tests.base import BaseTestCase

agenda_item_t = Table("agenda_item_t")
Expand Down Expand Up @@ -160,7 +162,7 @@ def test_o2o_generic_1t_1GrR_okay_with_setval(self) -> None:
)
).fetchone()["id"]
)
los_row = curs.execute(
los_row: dict[str, Any] = curs.execute(
*list_of_speakers_t.select(
list_of_speakers_t.id,
list_of_speakers_t.content_object_id,
Expand Down Expand Up @@ -789,7 +791,7 @@ def test_o2m_ntR_1r_insert_delete_okay(self) -> None:
"sequential_number",
],
)
projector = curs.execute(
projector: dict[str, Any] = curs.execute(
*projector_t.select(
*columns,
where=projector_t.used_as_default_projector_for_topic_in_meeting_id
Expand Down Expand Up @@ -879,7 +881,7 @@ def test_correct_permissions_in_group(self) -> None:
group_t = Table("group_t")
with self.db_connection.cursor() as curs:
with self.db_connection.transaction():
group = curs.execute(
group: dict[str, Any] = curs.execute(
*group_t.select(group_t.permissions, where=group_t.id == 1)
).fetchone()
assert "agenda_item.can_see_internal" in group["permissions"]
Expand Down