Skip to content

Commit

Permalink
fix: refactor fix
Browse files Browse the repository at this point in the history
  • Loading branch information
lchen-2101 committed Mar 18, 2024
1 parent d37d7f0 commit 04e0b20
Show file tree
Hide file tree
Showing 19 changed files with 136 additions and 104 deletions.
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ RUN poetry install --no-root
COPY ./src ./src
COPY ./db_revisions ./db_revisions

WORKDIR /usr/app/src
WORKDIR /usr/app/src/regtech_user_fi_management

EXPOSE 8888

Expand Down
4 changes: 2 additions & 2 deletions db_revisions/env.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from logging.config import fileConfig
from sqlalchemy import engine_from_config, pool
from alembic import context
from entities.models import Base
from regtech_user_fi_management.entities.models.dao import Base

# this is the Alembic Config object, which provides
# access to the values within the .ini file in use.
Expand All @@ -21,7 +21,7 @@

if ENV == "LOCAL":
file_dir = os.path.dirname(os.path.realpath(__file__))
load_dotenv(f"{file_dir}/../src/.env.local")
load_dotenv(f"{file_dir}/../src/regtech_user_fi_management/.env.local")
else:
load_dotenv()

Expand Down
92 changes: 48 additions & 44 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

File renamed without changes.
File renamed without changes.
4 changes: 3 additions & 1 deletion src/regtech_user_fi_management/config.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import os
from pathlib import Path
from typing import Set
from urllib import parse

from pydantic import field_validator, PostgresDsn, ValidationInfo
Expand All @@ -10,7 +11,7 @@

JWT_OPTS_PREFIX = "jwt_opts_"

env_files_to_load: list[Path|str] = [".env"]
env_files_to_load: list[Path | str] = [".env"]
if os.getenv("ENV", "LOCAL") == "LOCAL":
env_files_to_load.append(".env.local")

Expand All @@ -23,6 +24,7 @@ class Settings(BaseSettings):
inst_db_host: str
inst_db_scheme: str = "postgresql+asyncpg"
inst_conn: str | None = None
admin_scopes: Set[str] = set(["query-groups", "manage-users"])

def __init__(self, **data):
super().__init__(**data)
Expand Down
6 changes: 3 additions & 3 deletions src/regtech_user_fi_management/dependencies.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@
from sqlalchemy.ext.asyncio import AsyncSession
from typing import List, Optional
from itertools import chain
from config import settings
from regtech_user_fi_management.config import settings

from entities.engine import get_session
from entities.repos import institutions_repo as repo
from regtech_user_fi_management.entities.engine.engine import get_session
import regtech_user_fi_management.entities.repos.institutions_repo as repo
from starlette.authentication import AuthCredentials
from regtech_api_commons.models.auth import AuthenticatedUser

Expand Down
2 changes: 1 addition & 1 deletion src/regtech_user_fi_management/entities/listeners.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from sqlalchemy.orm import Mapper

from .models.dao import Base, FinancialInstitutionDao, SblTypeMappingDao
from entities.engine.engine import engine
from .engine.engine import engine


def inspect_fi(fi: FinancialInstitutionDao):
Expand Down
6 changes: 3 additions & 3 deletions src/regtech_user_fi_management/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@

def run_migrations():
file_dir = os.path.dirname(os.path.realpath(__file__))
alembic_cfg = Config(f"{file_dir}/../alembic.ini")
alembic_cfg.set_main_option("script_location", f"{file_dir}/../db_revisions")
alembic_cfg.set_main_option("prepend_sys_path", f"{file_dir}/../")
alembic_cfg = Config(f"{file_dir}/../../alembic.ini")
alembic_cfg.set_main_option("script_location", f"{file_dir}/../../db_revisions")
alembic_cfg.set_main_option("prepend_sys_path", f"{file_dir}/../../")
command.upgrade(alembic_cfg, "head")


Expand Down
6 changes: 3 additions & 3 deletions src/regtech_user_fi_management/routers/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@
from typing import Set
from fastapi import Depends, Request
from starlette.authentication import requires
from dependencies import check_domain
from regtech_user_fi_management.dependencies import check_domain

from regtech_api_commons.api import Router
from entities.models import UserProfile
from regtech_user_fi_management.entities.models.dto import UserProfile

from regtech_api_commons.models import RegTechUser
from regtech_api_commons.oauth2 import OAuth2Admin
from config import kc_settings
from regtech_user_fi_management.config import kc_settings

router = Router()

Expand Down
16 changes: 11 additions & 5 deletions src/regtech_user_fi_management/routers/institutions.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,19 @@
from fastapi import Depends, Request, HTTPException, Response
from http import HTTPStatus
from regtech_api_commons.oauth2.oauth2_admin import OAuth2Admin
from config import kc_settings
from regtech_user_fi_management.config import kc_settings
from regtech_api_commons.api import Router
from dependencies import check_domain, parse_leis, get_email_domain, lei_association_check, fi_search_association_check
from regtech_user_fi_management.dependencies import (
check_domain,
parse_leis,
get_email_domain,
lei_association_check,
fi_search_association_check,
)
from typing import Annotated, List, Tuple, Literal
from entities.engine import get_session
from entities.repos import institutions_repo as repo
from entities.models import (
from regtech_user_fi_management.entities.engine.engine import get_session
import regtech_user_fi_management.entities.repos.institutions_repo as repo
from regtech_user_fi_management.entities.models.dto import (
FinancialInstitutionDto,
FinancialInstitutionWithRelationsDto,
FinancialInsitutionDomainDto,
Expand Down
8 changes: 4 additions & 4 deletions tests/api/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from pytest_mock import MockerFixture
from starlette.authentication import AuthCredentials, UnauthenticatedUser
from regtech_api_commons.models import AuthenticatedUser
from entities.models import (
from regtech_user_fi_management.entities.models.dao import (
FinancialInstitutionDao,
FinancialInstitutionDomainDao,
FederalRegulatorDao,
Expand All @@ -22,9 +22,9 @@ def app_fixture(mocker: MockerFixture) -> FastAPI:
MockedEngine = mocker.patch("sqlalchemy.ext.asyncio.AsyncEngine")
mocked_engine.return_value = MockedEngine.return_value
mocker.patch("fastapi.security.OAuth2AuthorizationCodeBearer")
domain_denied_mock = mocker.patch("dependencies.email_domain_denied")
domain_denied_mock = mocker.patch("regtech_user_fi_management.dependencies.email_domain_denied")
domain_denied_mock.return_value = False
from main import app
from regtech_user_fi_management.main import app

return app

Expand Down Expand Up @@ -57,7 +57,7 @@ def unauthed_user_mock(auth_mock: Mock) -> Mock:

@pytest.fixture
def get_institutions_mock(mocker: MockerFixture, authed_user_mock: Mock) -> Mock:
mock = mocker.patch("entities.repos.institutions_repo.get_institutions")
mock = mocker.patch("regtech_user_fi_management.entities.repos.institutions_repo.get_institutions")
mock.return_value = [
FinancialInstitutionDao(
name="Test Bank 123",
Expand Down
Loading

0 comments on commit 04e0b20

Please sign in to comment.