-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
tests: migrate away from SQlite In-Memory db.
- Loading branch information
1 parent
61bb501
commit df1507c
Showing
20 changed files
with
131 additions
and
136 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
Binary file not shown.
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 |
---|---|---|
|
@@ -5,7 +5,7 @@ | |
msgid "" | ||
msgstr "" | ||
"Project-Id-Version: PACKAGE 1.0\n" | ||
"POT-Creation-Date: 2024-07-02 14:17+0200\n" | ||
"POT-Creation-Date: 2024-07-02 23:44+0200\n" | ||
"PO-Revision-Date: 2024-05-21 21:20+0200\n" | ||
"Last-Translator: cyrill <[email protected]>\n" | ||
"Language-Team: German <[email protected]>\n" | ||
|
@@ -338,6 +338,10 @@ msgstr "Ihr Kommentar" | |
msgid "Search Results" | ||
msgstr "Suchergebnisse" | ||
|
||
#: src/privatim/views/templates/search_results.pt | ||
msgid "No results containing all your search terms were found." | ||
msgstr "Es wurden keine Ergebnisse gefunden, die alle Ihre Suchbegriffe enthalten." | ||
|
||
#: src/privatim/views/templates/search_results.pt | ||
#: src/privatim/views/templates/activities.pt | ||
msgid "Show Details" | ||
|
Binary file not shown.
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 |
---|---|---|
|
@@ -5,7 +5,7 @@ | |
msgid "" | ||
msgstr "" | ||
"Project-Id-Version: PACKAGE 1.0\n" | ||
"POT-Creation-Date: 2024-07-02 14:17+0200\n" | ||
"POT-Creation-Date: 2024-07-02 23:44+0200\n" | ||
"PO-Revision-Date: 2024-04-11 15:53+0200\n" | ||
"Last-Translator: cyrill <[email protected]>\n" | ||
"Language-Team: French <[email protected]>\n" | ||
|
@@ -335,7 +335,11 @@ msgstr "Votre commentaire" | |
|
||
#: src/privatim/views/templates/search_results.pt | ||
msgid "Search Results" | ||
msgstr "" | ||
msgstr "Résultats de la recherche" | ||
|
||
#: src/privatim/views/templates/search_results.pt | ||
msgid "No results containing all your search terms were found.." | ||
msgstr "Aucun résultat ne contient tous les termes de votre recherche." | ||
|
||
#: src/privatim/views/templates/search_results.pt | ||
#: src/privatim/views/templates/activities.pt | ||
|
@@ -348,11 +352,11 @@ msgstr "Changer le mot de passe" | |
|
||
#: src/privatim/views/templates/activities.pt | ||
msgid "Unbekannter Ersteller" | ||
msgstr "" | ||
msgstr "Créateur inconnu" | ||
|
||
#: src/privatim/views/templates/activities.pt | ||
msgid "Kein Leiter" | ||
msgstr "" | ||
msgstr "Pas de chef" | ||
|
||
#: src/privatim/views/templates/activities.pt | ||
msgid "Show Meeting" | ||
|
@@ -607,7 +611,7 @@ msgstr "Membres" | |
|
||
#: src/privatim/forms/search_form.py | ||
msgid "Search" | ||
msgstr "" | ||
msgstr "Suchen" | ||
|
||
#: src/privatim/forms/widgets/widgets.py | ||
msgid "Uploaded file" | ||
|
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,7 +6,7 @@ | |
msgid "" | ||
msgstr "" | ||
"Project-Id-Version: PACKAGE 1.0\n" | ||
"POT-Creation-Date: 2024-07-02 14:17+0200\n" | ||
"POT-Creation-Date: 2024-07-02 23:44+0200\n" | ||
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" | ||
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n" | ||
"Language-Team: LANGUAGE <[email protected]>\n" | ||
|
@@ -328,6 +328,10 @@ msgstr "" | |
msgid "Search Results" | ||
msgstr "" | ||
|
||
#: ./src/privatim/views/templates/search_results.pt | ||
msgid "No results containing all your search terms were found.." | ||
msgstr "" | ||
|
||
#: ./src/privatim/views/templates/search_results.pt | ||
#: ./src/privatim/views/templates/activities.pt | ||
msgid "Show Details" | ||
|
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 |
---|---|---|
@@ -1,21 +1,21 @@ | ||
from privatim.cli.upgrade import UpgradeContext | ||
|
||
|
||
def test_has_table(config): | ||
upgrade = UpgradeContext(config.dbsession) | ||
def test_has_table(pg_config): | ||
upgrade = UpgradeContext(pg_config.dbsession) | ||
assert upgrade.has_table('consultations') | ||
assert not upgrade.has_table('bogus') | ||
|
||
|
||
def test_drop_table(config): | ||
upgrade = UpgradeContext(config.dbsession) | ||
assert upgrade.has_table('meetings') | ||
assert upgrade.drop_table('meetings') | ||
def test_drop_table(pg_config): | ||
upgrade = UpgradeContext(pg_config.dbsession) | ||
assert upgrade.has_table('agenda_items') | ||
assert upgrade.drop_table('agenda_items') | ||
assert not upgrade.has_table('meetings') | ||
assert not upgrade.drop_table('bogus') | ||
|
||
|
||
def test_has_column(config): | ||
upgrade = UpgradeContext(config.dbsession) | ||
def test_has_column(pg_config): | ||
upgrade = UpgradeContext(pg_config.dbsession) | ||
assert upgrade.has_column('meetings', 'id') | ||
assert not upgrade.has_column('meetings', 'bogus') |
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 |
---|---|---|
@@ -1,7 +1,6 @@ | ||
import warnings | ||
import pytest | ||
import transaction | ||
from libcloud.storage.drivers.local import LocalStorageDriver | ||
from pyramid import testing | ||
from sqlalchemy import engine_from_config | ||
from privatim import main | ||
|
@@ -10,90 +9,45 @@ | |
from privatim.models.consultation import Status, Consultation | ||
from privatim.orm import Base, get_engine, get_session_factory, get_tm_session | ||
from privatim.testing import DummyRequest, DummyMailer, MockRequests | ||
from sqlalchemy_file.storage import StorageManager | ||
|
||
from tests.shared.client import Client | ||
|
||
|
||
from typing import TYPE_CHECKING | ||
if TYPE_CHECKING: | ||
from pyramid.config import Configurator | ||
|
||
|
||
@pytest.fixture | ||
def base_config(_postgresql): | ||
@pytest.fixture(scope='function') | ||
def base_config(postgresql): | ||
msg = '.*SQLAlchemy must convert from floating point.*' | ||
warnings.filterwarnings('ignore', message=msg) | ||
|
||
# config = testing.setUp(settings={ | ||
# 'sqlalchemy.url': 'sqlite:///:memory:', | ||
# }) | ||
|
||
config = testing.setUp(settings={ | ||
'sqlalchemy.url': ( | ||
f'postgresql+psycopg://{_postgresql.info.user}:@' | ||
f'{_postgresql.info.host}:{_postgresql.info.port}' | ||
f'/{_postgresql.info.dbname}' | ||
f'postgresql+psycopg://{postgresql.info.user}:@' | ||
f'{postgresql.info.host}:{postgresql.info.port}' | ||
f'/{postgresql.info.dbname}' | ||
), | ||
}) | ||
yield config | ||
testing.tearDown() | ||
transaction.abort() | ||
|
||
|
||
@pytest.fixture | ||
def config(base_config, monkeypatch, tmpdir) -> 'Configurator': | ||
""" Returns the config used in tests. Note that this has side effects | ||
on `DummyRequest` in that the session becomes available. """ | ||
|
||
base_config.include('privatim.models') | ||
base_config.include('pyramid_chameleon') | ||
base_config.include('pyramid_layout') | ||
settings = base_config.get_settings() | ||
|
||
engine = get_engine(settings) | ||
|
||
# enable foreign key constraints in sqlite, so we can rely on them | ||
# working during testing. | ||
# sqlalchemy.event.listen( | ||
# engine, | ||
# 'connect', | ||
# lambda c, r: c.execute('pragma foreign_keys=ON') | ||
# ) | ||
|
||
Base.metadata.create_all(engine) | ||
session_factory = get_session_factory(engine) | ||
|
||
dbsession = get_tm_session(session_factory, transaction.manager) | ||
base_config.dbsession = dbsession | ||
|
||
orig_init = DummyRequest.__init__ | ||
|
||
def init_with_dbsession(self, *args, dbsession=dbsession, **kwargs): | ||
orig_init(self, *args, dbsession=dbsession, **kwargs) | ||
|
||
monkeypatch.setattr(DummyRequest, '__init__', init_with_dbsession) | ||
|
||
# Store static files in a temporary directory | ||
if not StorageManager._storages: | ||
# NOTE: StorageManager does not expose any method to check if some | ||
# storage has already been added. However, if you attempt to add a | ||
# storage that already exists, StorageManager raises a RuntimeError. | ||
tmpdir.mkdir('assets') | ||
container = LocalStorageDriver(tmpdir).get_container('assets') | ||
StorageManager.add_storage("default", container) | ||
@pytest.fixture(scope='function', autouse=True) | ||
def run_around_tests(engine): | ||
# todo: check if this is actually needed? | ||
|
||
return base_config | ||
# This fixture will run before and after each test | ||
# Thanks to the autouse=True parameter | ||
yield | ||
# After the test, we ensure all tables are dropped | ||
Base.metadata.drop_all(bind=engine) | ||
|
||
|
||
# requires pytest-postgresql: | ||
@pytest.fixture(scope='session') | ||
def pg_config(_postgresql, monkeypatch): | ||
@pytest.fixture(scope='function') | ||
def pg_config(postgresql, monkeypatch): | ||
config = testing.setUp(settings={ | ||
'sqlalchemy.url': ( | ||
f'postgresql+psycopg://{_postgresql.info.user}:@' | ||
f'{_postgresql.info.host}:{_postgresql.info.port}' | ||
f'/{_postgresql.info.dbname}' | ||
f'postgresql+psycopg://{postgresql.info.user}:@' | ||
f'{postgresql.info.host}:{postgresql.info.port}' | ||
f'/{postgresql.info.dbname}' | ||
), | ||
}) | ||
config.include('privatim.models') | ||
|
@@ -125,13 +79,13 @@ def init_with_dbsession(self, *args, dbsession=dbsession, **kwargs): | |
transaction.abort() | ||
|
||
|
||
@pytest.fixture | ||
def session(config): | ||
@pytest.fixture(scope='function') | ||
def session(pg_config): | ||
# convenience fixture | ||
return config.dbsession | ||
return pg_config.dbsession | ||
|
||
|
||
@pytest.fixture | ||
@pytest.fixture(scope='function') | ||
def user(session): | ||
user = User( | ||
email='[email protected]', | ||
|
@@ -169,13 +123,13 @@ def user_with_working_group(session): | |
|
||
|
||
@pytest.fixture | ||
def mailer(config): | ||
def mailer(pg_config): | ||
mailer = DummyMailer() | ||
config.registry.registerUtility(mailer) | ||
pg_config.registry.registerUtility(mailer) | ||
return mailer | ||
|
||
|
||
@pytest.fixture(scope='session') | ||
@pytest.fixture(scope='function') | ||
def engine(app_settings): | ||
engine = engine_from_config(app_settings) | ||
Base.metadata.create_all(engine) | ||
|
@@ -186,40 +140,35 @@ def engine(app_settings): | |
return engine | ||
|
||
|
||
@pytest.fixture(scope='session') | ||
@pytest.fixture(scope='function') | ||
def connection(engine): | ||
connection = engine.connect() | ||
yield connection | ||
connection.close() | ||
|
||
|
||
@pytest.fixture(scope='session') | ||
def _postgresql(postgresql): | ||
return postgresql | ||
|
||
|
||
@pytest.fixture(scope='session') | ||
def app_settings(_postgresql): | ||
@pytest.fixture(scope='function') | ||
def app_settings(postgresql): | ||
yield {'sqlalchemy.url': ( | ||
f'postgresql+psycopg://{_postgresql.info.user}:@' | ||
f'{_postgresql.info.host}:{_postgresql.info.port}' | ||
f'/{_postgresql.info.dbname}' | ||
f'postgresql+psycopg://{postgresql.info.user}:@' | ||
f'{postgresql.info.host}:{postgresql.info.port}' | ||
f'/{postgresql.info.dbname}' | ||
)} | ||
|
||
|
||
@pytest.fixture(scope="session") | ||
@pytest.fixture(scope='function') | ||
def app_inner(app_settings): | ||
app = main({}, **app_settings) | ||
yield app | ||
|
||
|
||
@pytest.fixture(scope='session') | ||
@pytest.fixture(scope='function') | ||
def app(app_inner, connection): | ||
app_inner.app.app.registry["dbsession_factory"].kw["bind"] = connection | ||
yield app_inner | ||
|
||
|
||
@pytest.fixture(scope='session') | ||
@pytest.fixture(scope='function') | ||
def client(app, engine): | ||
|
||
client = Client(app) | ||
|
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
Oops, something went wrong.