Skip to content

Commit

Permalink
Use .env for flask test config
Browse files Browse the repository at this point in the history
  • Loading branch information
BorjaEst committed Sep 6, 2022
1 parent 553d55b commit 1a6a4e2
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 9 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ target/

# DotEnv configuration
.env
.env.back

# Database
*.db
Expand Down
6 changes: 3 additions & 3 deletions examples/example_flask.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ class ProductionConfig(Config):

# In production you might want to reduce the number of OP
TRUSTED_OP_LIST = ["https://aai.egi.eu/oidc/"]
FLAAT_ISSUER = "https://aai.egi.eu/oidc/"
FLAAT_ISS = "https://aai.egi.eu/oidc/"

# Define your request timeout for production
FLAAT_REQUEST_TIMEOUT = 1.2
Expand Down Expand Up @@ -107,9 +107,9 @@ class TestingConfig(Config):
# ------------------------------------------------------------------
# Standard flask Application Factories snippet, source --------------
# https://flask.palletsprojects.com/en/2.1.x/patterns/appfactories
def create_app(config="ProductionConfig"):
def create_app(config=f"{__name__}.ProductionConfig"):
app = Flask(__name__)
app.config.from_object(f"{__name__}.{config}")
app.config.from_object(config)

# Init application plugins
flaat.init_app(app)
Expand Down
6 changes: 3 additions & 3 deletions flaat/flask/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def __init__(self, access_levels=config.DEFAULT_ACCESS_LEVELS, app=None):

def init_app(self, app):
app.config.setdefault("TRUSTED_OP_LIST", [])
app.config.setdefault("FLAAT_ISSUER", "")
app.config.setdefault("FLAAT_ISS", "")
app.config.setdefault("FLAAT_CLIENT_ID", "")
app.config.setdefault("FLAAT_CLIENT_SECRET", "")
app.config.setdefault("FLAAT_REQUEST_TIMEOUT", 1.2) # seconds
Expand Down Expand Up @@ -52,14 +52,14 @@ def iss(self):
"""Returns the Flaat configured issuer URL.
:return: Issuer URL of the pinned issuer
"""
return current_app.config["FLAAT_ISSUER"]
return current_app.config["FLAAT_ISS"]

def set_issuer(self, issuer: str):
"""Pins the given issuer. Only users of this issuer will be able
to use services.
:param issuer: Issuer URL of the pinned issuer.
"""
current_app.config["FLAAT_ISSUER"] = issuer.rstrip("/")
current_app.config["FLAAT_ISS"] = issuer.rstrip("/")

@property
def client_id(self):
Expand Down
5 changes: 2 additions & 3 deletions flaat/flask/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,10 @@
import copy

from flaat import issuers
from flaat.test_env import FLAAT_TRUSTED_OPS_LIST
from pytest_cases import fixture


@fixture(scope="session", params=["ProductionConfig"])
@fixture(scope="session", params=["flaat.test_env"])
def configuration(request):
return request.param

Expand All @@ -19,7 +18,7 @@ def app(configuration):
from examples.example_flask import create_app

app = create_app(configuration)
app.config["TRUSTED_OP_LIST"] = FLAAT_TRUSTED_OPS_LIST
app.config["ADMIN_EMAILS"] = ["[email protected]", "[email protected]"]
app.config["TESTING"] = True
# other setup can go here
yield app
Expand Down

0 comments on commit 1a6a4e2

Please sign in to comment.