Skip to content

Commit

Permalink
Refactored app_context in test base
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexanderWatzinger committed Nov 28, 2024
1 parent 10555cb commit fec2a26
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 13 deletions.
Empty file modified files/export/.gitignore
100644 → 100755
Empty file.
Empty file modified files/processed_images/resized/.gitignore
100644 → 100755
Empty file.
Empty file modified files/uploads/.gitignore
100644 → 100755
Empty file.
25 changes: 12 additions & 13 deletions tests/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down

0 comments on commit fec2a26

Please sign in to comment.