From fec2a263a4581bfa1ca5b3956d1f4d495ca9dbf3 Mon Sep 17 00:00:00 2001 From: Alexander Watzinger Date: Thu, 28 Nov 2024 18:10:35 +0100 Subject: [PATCH] Refactored app_context in test base --- files/export/.gitignore | 0 files/processed_images/resized/.gitignore | 0 files/uploads/.gitignore | 0 tests/base.py | 25 +++++++++++------------ 4 files changed, 12 insertions(+), 13 deletions(-) mode change 100644 => 100755 files/export/.gitignore mode change 100644 => 100755 files/processed_images/resized/.gitignore mode change 100644 => 100755 files/uploads/.gitignore diff --git a/files/export/.gitignore b/files/export/.gitignore old mode 100644 new mode 100755 diff --git a/files/processed_images/resized/.gitignore b/files/processed_images/resized/.gitignore old mode 100644 new mode 100755 diff --git a/files/uploads/.gitignore b/files/uploads/.gitignore old mode 100644 new mode 100755 diff --git a/tests/base.py b/tests/base.py index 9ce8e35bc..d62eac7f9 100644 --- a/tests/base.py +++ b/tests/base.py @@ -15,22 +15,21 @@ class TestBaseCase(unittest.TestCase): def setUp(self) -> None: app.testing = True app.config.from_pyfile('testing.py') - self.setup_database() self.client = app.test_client() self.app = self.client # Remove after updated API tests - app.app_context().push() # Always provide app.app_context - self.client.post( - url_for('login'), - data={'username': 'Alice', 'password': 'test'}) - with app.test_request_context(): - app.preprocess_request() - self.alice_id = 2 - self.precision_type = \ - Type.get_hierarchy('External reference match') - self.test_path = Path(app.root_path).parent / 'tests' - self.static_path = Path(app.root_path) / 'static' - app.app_context().push() # Push again for e.g. logged-in user + with app.app_context(): + self.client.post( + url_for('login'), + data={'username': 'Alice', 'password': 'test'}) + with app.test_request_context(): + app.preprocess_request() + self.alice_id = 2 + self.precision_type = \ + Type.get_hierarchy('External reference match') + self.test_path = Path(app.root_path).parent / 'tests' + self.static_path = Path(app.root_path) / 'static' + app.app_context().push() def setup_database(self) -> None: connection = psycopg2.connect(