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 is_voluntary to Filing, added alembic script, and updated the t… #454

Merged
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
28 changes: 28 additions & 0 deletions db_revisions/versions/26f11ac15b3c_add_is_voluntary_to_filing.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
"""add is_voluntary to filing

Revision ID: 26f11ac15b3c
Revises: f4091e4ce218
Create Date: 2024-10-16 15:15:41.261646

"""

from typing import Sequence, Union

from alembic import op
import sqlalchemy as sa


# revision identifiers, used by Alembic.
revision: str = "26f11ac15b3c"
down_revision: Union[str, None] = "f4091e4ce218"
branch_labels: Union[str, Sequence[str], None] = None
depends_on: Union[str, Sequence[str], None] = None


def upgrade() -> None:
with op.batch_alter_table("filing") as batch_op:
batch_op.add_column(sa.Column("is_voluntary", sa.Boolean, nullable=False))


def downgrade() -> None:
op.drop_column("filing", "is_voluntary")
1 change: 1 addition & 0 deletions src/sbl_filing_api/entities/models/dao.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ class FilingDAO(Base):
confirmation_id: Mapped[str] = mapped_column(nullable=True)
creator_id: Mapped[int] = mapped_column(ForeignKey("user_action.id"))
creator: Mapped[UserActionDAO] = relationship(lazy="selectin", foreign_keys=[creator_id])
is_voluntary: Mapped[bool] = mapped_column(default=False)

def __str__(self):
return f"ID: {self.id}, Filing Period: {self.filing_period}, LEI: {self.lei}, Tasks: {self.tasks}, Institution Snapshot ID: {self.institution_snapshot_id}, Contact Info: {self.contact_info}"
Expand Down
7 changes: 7 additions & 0 deletions src/sbl_filing_api/entities/models/dto.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ class FilingDTO(BaseModel):
confirmation_id: str | None = None
signatures: List[UserActionDTO] = []
creator: UserActionDTO
is_voluntary: bool


class FilingPeriodDTO(BaseModel):
Expand All @@ -110,3 +111,9 @@ class StateUpdateDTO(BaseModel):
model_config = ConfigDict(from_attributes=True)

state: FilingTaskState


class VoluntaryUpdateDTO(BaseModel):
model_config = ConfigDict(from_attribute=True)

is_voluntary: bool
16 changes: 16 additions & 0 deletions src/sbl_filing_api/routers/filing.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
ContactInfoDTO,
SubmissionState,
UserActionDTO,
VoluntaryUpdateDTO,
)

from sbl_filing_api.entities.repos import submission_repo as repo
Expand Down Expand Up @@ -403,3 +404,18 @@ async def get_submission_report(request: Request, response: Response, lei: str,
name="Report Not Found",
detail=f"Report for ({id}) does not exist.",
)


@router.put("/institutions/{lei}/filings/{period_code}/is-voluntary", response_model=FilingDTO)
@requires("authenticated")
async def update_is_voluntary(request: Request, lei: str, period_code: str, update_value: VoluntaryUpdateDTO):
result = await repo.get_filing(request.state.db_session, lei, period_code)
if result:
result.is_voluntary = update_value.is_voluntary
res = await repo.upsert_filing(request.state.db_session, result)
return res
raise RegTechHttpException(
status_code=status.HTTP_404_NOT_FOUND,
name="Filing Not Found",
detail=f"A Filing for the LEI ({lei}) and period ({period_code}) that was attempted to be updated does not exist.",
)
5 changes: 5 additions & 0 deletions tests/api/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ def get_filing_mock(mocker: MockerFixture) -> Mock:
action_type=UserActionType.SUBMIT,
timestamp=datetime.now(),
),
is_voluntary=False,
)
return mock

Expand Down Expand Up @@ -129,6 +130,7 @@ def get_filings_mock(mocker: MockerFixture) -> Mock:
action_type=UserActionType.SUBMIT,
timestamp=datetime.now(),
),
is_voluntary=False,
),
FilingDAO(
id=1,
Expand Down Expand Up @@ -157,6 +159,7 @@ def get_filings_mock(mocker: MockerFixture) -> Mock:
action_type=UserActionType.SUBMIT,
timestamp=datetime.now(),
),
is_voluntary=False,
),
FilingDAO(
id=1,
Expand Down Expand Up @@ -185,6 +188,7 @@ def get_filings_mock(mocker: MockerFixture) -> Mock:
action_type=UserActionType.SUBMIT,
timestamp=datetime.now(),
),
is_voluntary=False,
),
]
return mock
Expand Down Expand Up @@ -220,6 +224,7 @@ def post_filing_mock(mocker: MockerFixture) -> Mock:
action_type=UserActionType.CREATE,
timestamp=datetime.now(),
),
is_voluntary=False,
)
return mock

Expand Down
11 changes: 11 additions & 0 deletions tests/api/routers/test_filing_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -545,6 +545,15 @@ async def test_patch_filing(
assert res.status_code == 200
assert res.json()["institution_snapshot_id"] == "v3"

# update is_voluntary
mock.return_value.is_voluntary = True
res = client.put(
"/v1/filing/institutions/1234567890ABCDEFGH00/filings/2025/is-voluntary",
json={"is_voluntary": True},
)
assert res.status_code == 200
assert res.json()["is_voluntary"] is True

# no existing filing for contact_info
get_filing_mock.return_value = None
res = client.put(
Expand Down Expand Up @@ -704,6 +713,7 @@ def test_put_contact_info(
action_type=UserActionType.CREATE,
timestamp=datetime.datetime.now(),
),
is_voluntary=False,
)

client = TestClient(app_fixture)
Expand Down Expand Up @@ -797,6 +807,7 @@ def test_no_extension(
action_type=UserActionType.CREATE,
timestamp=datetime.datetime.now(),
),
is_voluntary=True,
)

client = TestClient(app_fixture)
Expand Down
8 changes: 8 additions & 0 deletions tests/migrations/test_migrations.py
Original file line number Diff line number Diff line change
Expand Up @@ -434,3 +434,11 @@ def test_migrations_to_f4091e4ce218(alembic_runner: MigrationContext, alembic_en
assert [c for c in columns if c["name"] == "user_id"][0]["type"].length == 36
assert [c for c in columns if c["name"] == "user_name"][0]["type"].length == 255
assert [c for c in columns if c["name"] == "user_email"][0]["type"].length == 255


def test_migrations_to_26f11ac15b3c(alembic_runner: MigrationContext, alembic_engine: Engine):
alembic_runner.migrate_up_to("26f11ac15b3c")

inspector = sqlalchemy.inspect(alembic_engine)

assert "is_voluntary" in set([c["name"] for c in inspector.get_columns("filing")])
Loading