Skip to content

Commit

Permalink
Try instantiating in config again
Browse files Browse the repository at this point in the history
  • Loading branch information
StephenBrown2 committed Jan 29, 2020
1 parent 695f883 commit 88f4e33
Show file tree
Hide file tree
Showing 17 changed files with 18 additions and 39 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from app import crud
from app.api.utils.db import get_db
from app.api.utils.security import get_current_user
from app.core.config import Settings
from app.core.config import settings
from app.core.jwt import create_access_token
from app.core.security import get_password_hash
from app.models.user import User as DBUser
Expand All @@ -20,7 +20,6 @@
verify_password_reset_token,
)

settings = Settings()
router = APIRouter()


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,11 @@
from app import crud
from app.api.utils.db import get_db
from app.api.utils.security import get_current_active_superuser, get_current_active_user
from app.core.config import Settings
from app.core.config import settings
from app.models.user import User as DBUser
from app.schemas.user import User, UserCreate, UserUpdate
from app.utils import send_new_account_email

settings = Settings()
router = APIRouter()


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,11 @@

from app import crud
from app.api.utils.db import get_db
from app.core.config import Settings
from app.core.config import settings
from app.core.jwt import ALGORITHM
from app.models.user import User
from app.schemas.token import TokenPayload

settings = Settings()
reusable_oauth2 = OAuth2PasswordBearer(tokenUrl=f"{settings.API_V1_STR}/login/access-token")


Expand Down
2 changes: 2 additions & 0 deletions {{cookiecutter.project_slug}}/backend/app/app/core/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,3 +88,5 @@ def get_emails_enabled(cls, v, values):

class Config:
case_sensitive = True

settings = Settings()
3 changes: 1 addition & 2 deletions {{cookiecutter.project_slug}}/backend/app/app/core/jwt.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@

import jwt

from app.core.config import Settings
from app.core.config import settings

settings = Settings()
ALGORITHM = "HS256"
access_token_jwt_subject = "access"

Expand Down
4 changes: 1 addition & 3 deletions {{cookiecutter.project_slug}}/backend/app/app/db/init_db.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
from app import crud
from app.core.config import Settings
from app.core.config import settings
from app.schemas.user import UserCreate

# make sure all SQL Alchemy models are imported before initializing DB
# otherwise, SQL Alchemy might fail to initialize properly relationships
# for more details: https://github.com/tiangolo/full-stack-fastapi-postgresql/issues/28
from app.db import base

settings = Settings()

def init_db(db_session):
# Tables should be created with Alembic migrations
# But if you don't want to use migrations, create
Expand Down
3 changes: 1 addition & 2 deletions {{cookiecutter.project_slug}}/backend/app/app/db/session.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
from sqlalchemy import create_engine
from sqlalchemy.orm import scoped_session, sessionmaker

from app.core.config import Settings
from app.core.config import settings

settings = Settings()
engine = create_engine(settings.SQLALCHEMY_DATABASE_URI, pool_pre_ping=True)
db_session = scoped_session(
sessionmaker(autocommit=False, autoflush=False, bind=engine)
Expand Down
4 changes: 1 addition & 3 deletions {{cookiecutter.project_slug}}/backend/app/app/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,9 @@
from starlette.requests import Request

from app.api.api_v1.api import api_router
from app.core.config import Settings
from app.core.config import settings
from app.db.session import Session

settings = Settings()

app = FastAPI(title=settings.PROJECT_NAME, openapi_url=f"{settings.API_V1_STR}/openapi.json")

# Set all CORS enabled origins
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import requests

from app.core.config import Settings
from app.core.config import settings
from app.tests.utils.utils import get_server_api


def test_celery_worker_test(superuser_token_headers):
settings = Settings()
server_api = get_server_api()
data = {"msg": "test"}
r = requests.post(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
import requests

from app.core.config import Settings
from app.core.config import settings
from app.tests.utils.item import create_random_item
from app.tests.utils.utils import get_server_api
from app.tests.utils.user import create_random_user

settings = Settings()

def test_create_item(superuser_token_headers):
server_api = get_server_api()
data = {"title": "Foo", "description": "Fighters"}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
import requests

from app.core.config import Settings
from app.core.config import settings
from app.tests.utils.utils import get_server_api

settings = Settings()

def test_get_access_token():
server_api = get_server_api()
login_data = {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
import requests

from app import crud
from app.core.config import Settings
from app.core.config import settings
from app.db.session import db_session
from app.schemas.user import UserCreate
from app.tests.utils.utils import get_server_api, random_lower_string

settings = Settings()

def test_get_users_superuser_me(superuser_token_headers):
server_api = get_server_api()
r = requests.get(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import pytest

from app.core.config import Settings
from app.core.config import settings
from app.tests.utils.utils import get_server_api, get_superuser_token_headers
from app.tests.utils.user import authentication_token_from_email

Expand All @@ -16,5 +16,4 @@ def superuser_token_headers():

@pytest.fixture(scope="module")
def normal_user_token_headers():
settings = Settings()
return authentication_token_from_email(settings.EMAIL_TEST_USER)
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
import requests

from app import crud
from app.core.config import Settings
from app.core.config import settings
from app.db.session import db_session
from app.schemas.user import UserCreate, UserUpdate
from app.tests.utils.utils import get_server_api, random_lower_string


def user_authentication_headers(server_api, email, password):
settings = Settings()
data = {"username": email, "password": password}

r = requests.post(f"{server_api}{settings.API_V1_STR}/login/access-token", data=data)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@

import requests

from app.core.config import Settings

settings = Settings()
from app.core.config import settings

def random_lower_string():
return "".join(random.choices(string.ascii_lowercase, k=32))
Expand Down
4 changes: 1 addition & 3 deletions {{cookiecutter.project_slug}}/backend/app/app/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,7 @@
from emails.template import JinjaTemplate
from jwt.exceptions import InvalidTokenError

from app.core.config import Settings

settings = Settings()
from app.core.config import settings

password_reset_jwt_subject = "preset"

Expand Down
3 changes: 1 addition & 2 deletions {{cookiecutter.project_slug}}/backend/app/app/worker.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
from raven import Client

from app.core.config import Settings
from app.core.config import settings
from app.core.celery_app import celery_app

settings = Settings()
client_sentry = Client(settings.SENTRY_DSN)


Expand Down

0 comments on commit 88f4e33

Please sign in to comment.