Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added check to post filing. #498

Merged
merged 2 commits into from
Nov 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
"""update filing table for contact info
"""update filing table for contact info

Revision ID: 8eaef8ce4c23
Revises: 31e39764e3c0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@


def upgrade() -> None:

with op.batch_alter_table("user_action", schema=None) as batch_op:
batch_op.alter_column(
"user_name",
Expand Down
16 changes: 11 additions & 5 deletions src/sbl_filing_api/routers/filing.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@

from sbl_filing_api.entities.repos import submission_repo as repo

from sqlalchemy.exc import IntegrityError
from sqlalchemy.ext.asyncio import AsyncSession

from starlette.authentication import requires
Expand Down Expand Up @@ -77,6 +76,13 @@ async def post_filing(request: Request, lei: str, period_code: str):
period = await repo.get_filing_period(request.state.db_session, filing_period=period_code)

if period:
filing = await repo.get_filing(request.state.db_session, lei, period_code)
if filing:
raise RegTechHttpException(
status_code=status.HTTP_409_CONFLICT,
name="Filing Creation Conflict",
detail=f"Filing already exists for Filing Period {period_code} and LEI {lei}",
)
creator = None
try:
creator = await repo.add_user_action(
Expand All @@ -98,11 +104,11 @@ async def post_filing(request: Request, lei: str, period_code: str):

try:
return await repo.create_new_filing(request.state.db_session, lei, period_code, creator_id=creator.id)
except IntegrityError:
except Exception:
raise RegTechHttpException(
status_code=status.HTTP_409_CONFLICT,
name="Filing Creation Conflict",
detail=f"Filing already exists for Filing Period {period_code} and LEI {lei}",
status_code=status.HTTP_500_INTERNAL_SERVER_ERROR,
name="Filing Creation Error",
detail=f"An error occurred while creating a filing for LEI {lei} and Filing Period {period_code}.",
)

else:
Expand Down
17 changes: 13 additions & 4 deletions tests/api/routers/test_filing_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,17 +91,23 @@ def test_post_filing(
mocker: MockerFixture,
app_fixture: FastAPI,
get_filing_period_mock,
get_filing_mock,
post_filing_mock: Mock,
authed_user_mock: Mock,
):
client = TestClient(app_fixture)
get_filing_period_by_code_mock = mocker.patch("sbl_filing_api.entities.repos.submission_repo.get_filing_period")

# Filing already exists
res = client.post("/v1/filing/institutions/1234567890ZXWVUTSR00/filings/2024/")
assert res.status_code == 409
assert res.json()["error_detail"] == "Filing already exists for Filing Period 2024 and LEI 1234567890ZXWVUTSR00"

# testing with a period that does not exist
get_filing_mock.return_value = None
get_filing_period_by_code_mock.return_value = None
res = client.post("/v1/filing/institutions/1234567890ZXWVUTSR00/filings/2025/")
assert res.status_code == 404

assert (
res.json()["error_detail"]
== "The period (2025) does not exist, therefore a Filing can not be created for this period."
Expand Down Expand Up @@ -130,8 +136,12 @@ def test_post_filing(
mock_add_creator.side_effect = None
post_filing_mock.side_effect = IntegrityError(None, None, None)
res = client.post("/v1/filing/institutions/1234567890ZXWVUTSR00/filings/2024/")
assert res.status_code == 409
assert res.json()["error_detail"] == "Filing already exists for Filing Period 2024 and LEI 1234567890ZXWVUTSR00"
assert res.status_code == 500
assert (
res.json()["error_detail"]
== "An error occurred while creating a filing for LEI 1234567890ZXWVUTSR00 and Filing "
"Period 2024."
)

post_filing_mock.side_effect = None
res = client.post("/v1/filing/institutions/1234567890ZXWVUTSR00/filings/2024/")
Expand Down Expand Up @@ -872,7 +882,6 @@ def test_no_extension(
def test_bad_extension(
self, mocker: MockerFixture, app_fixture: FastAPI, authed_user_mock: Mock, get_filing_mock: Mock
):

client = TestClient(app_fixture)
contact_info_json = {
"id": 1,
Expand Down
Loading