Skip to content

Commit

Permalink
test: update setup of behave
Browse files Browse the repository at this point in the history
  • Loading branch information
Johannes1803 committed Sep 23, 2023
1 parent 26018f1 commit 7265259
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 3 deletions.
2 changes: 2 additions & 0 deletions tests/features/access_private_data.feature
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
Feature: Access protected information

@fixture.settings_auth
@fixture.session_factory
@fixture.test_client
Scenario: Access protected information as logged-in user
Given I am logged in as a user
When I navigate to the private route
Then I get access to private data

@fixture.settings_auth
@fixture.session_factory
@fixture.test_client
Scenario: Access protected information as anonymous user
Given I am not logged in as a user
Expand Down
4 changes: 3 additions & 1 deletion tests/features/environment.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
from behave import use_fixture

from tests.features.fixtures import settings_auth, test_client
from tests.features.fixtures import session_factory, settings_auth, test_client


def before_tag(context, tag):
if tag == "fixture.settings_auth":
use_fixture(settings_auth, context)
elif tag == "fixture.session_factory":
use_fixture(session_factory, context)
elif tag == "fixture.test_client":
use_fixture(test_client, context)
10 changes: 8 additions & 2 deletions tests/features/fixtures.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from behave import fixture
from fastapi.testclient import TestClient

from in_concert.app.app_factory import create_app
from in_concert.app.app_factory import create_app, get_db_session_factory
from in_concert.settings import Auth0Settings, Auth0SettingsTest


Expand All @@ -12,9 +12,15 @@ def settings_auth(context) -> Auth0Settings:
return context.settings_auth


@fixture
def session_factory(context):
context.session_factory = get_db_session_factory(context.settings_auth)
return context.session_factory


@fixture
def test_client(context):
app = create_app(context.settings_auth)
app = create_app(context.settings_auth, context.session_factory)
test_client = TestClient(app)
context.test_client = test_client
return context.test_client

0 comments on commit 7265259

Please sign in to comment.