Skip to content

Commit

Permalink
feat: use api-commons lei check (#235)
Browse files Browse the repository at this point in the history
closes #225
  • Loading branch information
lchen-2101 authored May 20, 2024
1 parent 8a47d47 commit 7f03a6e
Show file tree
Hide file tree
Showing 7 changed files with 15 additions and 52 deletions.
Binary file removed .coverage.MP-C02DD58HMD6N.71829.XvzIZnmx
Binary file not shown.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ __pycache__/
#################
htmlcov/
.tox/
.coverage
.coverage*
.cache
nosetests.xml
coverage.xml
Expand Down
6 changes: 4 additions & 2 deletions poetry.lock

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

28 changes: 0 additions & 28 deletions src/sbl_filing_api/routers/dependencies.py

This file was deleted.

2 changes: 1 addition & 1 deletion src/sbl_filing_api/routers/filing.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@

from starlette.authentication import requires

from sbl_filing_api.routers.dependencies import verify_user_lei_relation
from regtech_api_commons.api.dependencies import verify_user_lei_relation

logger = logging.getLogger(__name__)

Expand Down
2 changes: 1 addition & 1 deletion tests/api/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def authed_user_mock(auth_mock: Mock) -> Mock:
"name": "Test User",
"preferred_username": "test_user",
"email": "test@local.host",
"institutions": ["1234567890ABCDEFGH00", "1234567890ABCDEFGH01"],
"institutions": ["1234567890ABCDEFGH00", "1234567890ABCDEFGH01", "1234567890ZXWVUTSR00"],
"sub": "123456-7890-ABCDEF-GHIJ",
}
auth_mock.return_value = (
Expand Down
27 changes: 8 additions & 19 deletions tests/api/routers/test_filing_api.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
import asyncio
import datetime
from http import HTTPStatus
import httpx
import os
import pytest

from copy import deepcopy
from datetime import datetime as dt

from unittest.mock import ANY, Mock, AsyncMock

from fastapi import FastAPI, Request, HTTPException
from fastapi import FastAPI, HTTPException
from fastapi.testclient import TestClient
from pytest_mock import MockerFixture

Expand All @@ -24,7 +22,6 @@
)
from sbl_filing_api.entities.models.dto import ContactInfoDTO
from sbl_filing_api.entities.models.model_enums import UserActionType
from sbl_filing_api.routers.dependencies import verify_lei
from sbl_filing_api.services import submission_processor
from sbl_filing_api.services.multithread_handler import handle_submission, check_future

Expand Down Expand Up @@ -327,9 +324,12 @@ def test_authed_upload_file(
assert res.json()["submitter"]["action_type"] == UserActionType.SUBMIT

get_filing_mock.return_value = None
res = client.post("/v1/filing/institutions/ABCDEFG/filings/2024/submissions", files=files)
res = client.post("/v1/filing/institutions/1234567890ABCDEFGH00/filings/2024/submissions", files=files)
assert res.status_code == 404
assert res.json()["error_detail"] == "There is no Filing for LEI ABCDEFG in period 2024, unable to submit file."
assert (
res.json()["error_detail"]
== "There is no Filing for LEI 1234567890ABCDEFGH00 in period 2024, unable to submit file."
)

def test_unauthed_upload_file(self, mocker: MockerFixture, app_fixture: FastAPI, submission_csv: str):
files = {"file": ("submission.csv", open(submission_csv, "rb"))}
Expand Down Expand Up @@ -594,28 +594,17 @@ def test_user_lei_association(
get_filing_mock: Mock,
get_filing_period_mock: Mock,
):
mocker.patch.dict(os.environ, {"ENV": "TEST"})
client = TestClient(app_fixture)
res = client.get("/v1/filing/periods")
assert res.status_code == 200

res = client.get("/v1/filing/institutions/1234567890ZXWVUTSR00/filings/2024/")
res = client.get("/v1/filing/institutions/1234567890ZXWVUTSR01/filings/2024/")
assert res.status_code == 403
assert res.json()["error_detail"] == "LEI 1234567890ZXWVUTSR00 is not associated with the user."
assert res.json()["error_detail"] == "LEI 1234567890ZXWVUTSR01 is not associated with the user."

res = client.get("/v1/filing/institutions/1234567890ABCDEFGH00/filings/2024/")
assert res.status_code == 200

def test_verify_lei_dependency(self, mocker: MockerFixture):
mock_user_fi_service = mocker.patch("sbl_filing_api.routers.dependencies.httpx.get")
mock_user_fi_service.return_value = httpx.Response(200, json={"is_active": False})
with pytest.raises(HTTPException) as http_exc:
request = Request(scope={"type": "http", "headers": [(b"authorization", b"123")]})
verify_lei(request=request, lei="1234567890ZXWVUTSR00")
assert isinstance(http_exc.value, HTTPException)
assert http_exc.value.status_code == 403
assert http_exc.value.detail == "LEI 1234567890ZXWVUTSR00 is in an inactive state."

async def test_unauthed_get_contact_info(self, app_fixture: FastAPI, unauthed_user_mock: Mock):
client = TestClient(app_fixture)
res = client.get("/v1/filing/institutions/1234567890ZXWVUTSR00/filings/2024/contact-info")
Expand Down

0 comments on commit 7f03a6e

Please sign in to comment.