generated from cfpb/open-source-project-template
-
Notifications
You must be signed in to change notification settings - Fork 1
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 filing_task and filing_task_state tables #50
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
d76bef6
Added filing_task and filing_task_state tables
jcadam14 a26a894
Needed to add task obj to FilingTaskState for order param
jcadam14 9c7d500
Linting
jcadam14 fe83c45
Merge branch 'main' into 45-add-filing-steps-tables
jcadam14 bd4dfb0
Added order to the filing_task alembic script
jcadam14 ce15300
Updated migration pytest to include order column for filing_task
jcadam14 4769f20
Changed order to task_order because 'order' is a reserved keyword in …
jcadam14 33e3df2
Updated filing_task_state alembic script downgrade to drop TYPE
jcadam14 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
40 changes: 40 additions & 0 deletions
40
db_revisions/versions/078cbbc69fe5_update_filing_table_for_filing_tasks.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
"""update filing table for filing tasks | ||
|
||
Revision ID: 078cbbc69fe5 | ||
Revises: 4e8ae26c1a22 | ||
Create Date: 2024-01-30 13:15:44.323900 | ||
|
||
""" | ||
from typing import Sequence, Union | ||
|
||
from alembic import op, context | ||
import sqlalchemy as sa | ||
|
||
|
||
# revision identifiers, used by Alembic. | ||
revision: str = "078cbbc69fe5" | ||
down_revision: Union[str, None] = "4e8ae26c1a22" | ||
branch_labels: Union[str, Sequence[str], None] = None | ||
depends_on: Union[str, Sequence[str], None] = None | ||
|
||
|
||
def upgrade() -> None: | ||
op.drop_column("filing", "state") | ||
if "sqlite" not in context.get_context().dialect.name: | ||
op.execute(sa.DDL("DROP TYPE filingstate")) | ||
|
||
|
||
def downgrade() -> None: | ||
op.add_column( | ||
"filing", | ||
sa.Column( | ||
"state", | ||
sa.Enum( | ||
"FILING_STARTED", | ||
"FILING_INSTITUTION_APPROVED", | ||
"FILING_IN_PROGRESS", | ||
"FILING_COMPLETE", | ||
name="filingstate", | ||
), | ||
), | ||
) |
30 changes: 30 additions & 0 deletions
30
db_revisions/versions/4ca961a003e1_create_filing_task_table.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
"""create filing task table | ||
|
||
Revision ID: 4ca961a003e1 | ||
Revises: f30c5c3c7a42 | ||
Create Date: 2024-01-30 12:59:15.720135 | ||
|
||
""" | ||
from typing import Sequence, Union | ||
|
||
from alembic import op | ||
import sqlalchemy as sa | ||
|
||
|
||
# revision identifiers, used by Alembic. | ||
revision: str = "4ca961a003e1" | ||
down_revision: Union[str, None] = "f30c5c3c7a42" | ||
branch_labels: Union[str, Sequence[str], None] = None | ||
depends_on: Union[str, Sequence[str], None] = None | ||
|
||
|
||
def upgrade() -> None: | ||
op.create_table( | ||
"filing_task", | ||
sa.Column("name", sa.String, primary_key=True), | ||
sa.Column("task_order", sa.INTEGER, nullable=False), | ||
) | ||
|
||
|
||
def downgrade() -> None: | ||
op.drop_table("filing_task") |
51 changes: 51 additions & 0 deletions
51
db_revisions/versions/4e8ae26c1a22_create_filing_task_state_table.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
"""create filing task state table | ||
|
||
Revision ID: 4e8ae26c1a22 | ||
Revises: 4ca961a003e1 | ||
Create Date: 2024-01-30 13:02:52.041229 | ||
|
||
""" | ||
from typing import Sequence, Union | ||
|
||
from alembic import op, context | ||
import sqlalchemy as sa | ||
|
||
|
||
# revision identifiers, used by Alembic. | ||
revision: str = "4e8ae26c1a22" | ||
down_revision: Union[str, None] = "4ca961a003e1" | ||
branch_labels: Union[str, Sequence[str], None] = None | ||
depends_on: Union[str, Sequence[str], None] = None | ||
|
||
|
||
def upgrade() -> None: | ||
op.create_table( | ||
"filing_task_state", | ||
sa.Column("filing", sa.INTEGER, primary_key=True), | ||
sa.Column("task_name", sa.String, primary_key=True), | ||
sa.Column( | ||
"state", | ||
sa.Enum( | ||
"NOT_STARTED", | ||
"IN_PROGRESS", | ||
"COMPLETED", | ||
name="filingtaskstate", | ||
), | ||
), | ||
sa.Column("user", sa.String, nullable=False), | ||
sa.Column("change_timestamp", sa.DateTime, nullable=False), | ||
sa.ForeignKeyConstraint( | ||
["filing"], | ||
["filing.id"], | ||
), | ||
sa.ForeignKeyConstraint( | ||
["task_name"], | ||
["filing_task.name"], | ||
), | ||
) | ||
|
||
|
||
def downgrade() -> None: | ||
op.drop_table("filing_task_state") | ||
if "sqlite" not in context.get_context().dialect.name: | ||
op.execute(sa.DDL("DROP TYPE filingtaskstate")) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,8 +12,10 @@ | |
FilingPeriodDTO, | ||
FilingDAO, | ||
FilingDTO, | ||
FilingTaskStateDAO, | ||
FilingTaskDAO, | ||
FilingType, | ||
FilingState, | ||
FilingTaskState, | ||
SubmissionState, | ||
) | ||
from entities.repos import submission_repo as repo | ||
|
@@ -29,6 +31,11 @@ async def setup( | |
): | ||
mocker.patch.object(entities_engine, "SessionLocal", return_value=session_generator) | ||
|
||
filing_task_1 = FilingTaskDAO(name="Task-1", task_order=1) | ||
filing_task_2 = FilingTaskDAO(name="Task-2", task_order=2) | ||
transaction_session.add(filing_task_1) | ||
transaction_session.add(filing_task_2) | ||
|
||
filing_period = FilingPeriodDAO( | ||
name="FilingPeriod2024", | ||
start_period=datetime.now(), | ||
|
@@ -40,13 +47,11 @@ async def setup( | |
|
||
filing1 = FilingDAO( | ||
lei="1234567890", | ||
state=FilingState.FILING_STARTED, | ||
institution_snapshot_id="Snapshot-1", | ||
filing_period=1, | ||
) | ||
filing2 = FilingDAO( | ||
lei="ABCDEFGHIJ", | ||
state=FilingState.FILING_STARTED, | ||
institution_snapshot_id="Snapshot-1", | ||
filing_period=1, | ||
) | ||
|
@@ -101,28 +106,44 @@ async def test_get_filing_period(self, query_session: AsyncSession): | |
assert res.filing_type == FilingType.MANUAL | ||
|
||
async def test_add_and_modify_filing(self, transaction_session: AsyncSession): | ||
new_filing = FilingDTO( | ||
lei="12345ABCDE", | ||
state=FilingState.FILING_IN_PROGRESS, | ||
institution_snapshot_id="Snapshot-1", | ||
filing_period=1, | ||
) | ||
new_filing = FilingDTO(lei="12345ABCDE", institution_snapshot_id="Snapshot-1", filing_period=1, tasks=[]) | ||
res = await repo.upsert_filing(transaction_session, new_filing) | ||
assert res.id == 3 | ||
assert res.lei == "12345ABCDE" | ||
assert res.state == FilingState.FILING_IN_PROGRESS | ||
assert res.institution_snapshot_id == "Snapshot-1" | ||
|
||
mod_filing = FilingDTO( | ||
id=3, | ||
lei="12345ABCDE", | ||
state=FilingState.FILING_COMPLETE, | ||
institution_snapshot_id="Snapshot-1", | ||
filing_period=1, | ||
) | ||
mod_filing = FilingDTO(id=3, lei="12345ABCDE", institution_snapshot_id="Snapshot-2", filing_period=1, tasks=[]) | ||
res = await repo.upsert_filing(transaction_session, mod_filing) | ||
assert res.id == 3 | ||
assert res.lei == "12345ABCDE" | ||
assert res.state == FilingState.FILING_COMPLETE | ||
assert res.institution_snapshot_id == "Snapshot-2" | ||
|
||
async def test_get_filing_tasks(self, transaction_session: AsyncSession): | ||
tasks = await repo.get_filing_tasks(transaction_session) | ||
assert len(tasks) == 2 | ||
assert tasks[0].name == "Task-1" | ||
assert tasks[1].name == "Task-2" | ||
|
||
async def test_add_task_to_filing(self, query_session: AsyncSession, transaction_session: AsyncSession): | ||
filing = await repo.get_filing(query_session, filing_id=1) | ||
task = await query_session.scalar(select(FilingTaskDAO).where(FilingTaskDAO.name == "Task-1")) | ||
filing_task = FilingTaskStateDAO( | ||
filing=filing.id, task=task, user="[email protected]", state=FilingTaskState.IN_PROGRESS | ||
) | ||
filing.tasks = [filing_task] | ||
seconds_now = datetime.utcnow().timestamp() | ||
await repo.upsert_filing(transaction_session, filing) | ||
|
||
filing_task_states = (await transaction_session.scalars(select(FilingTaskStateDAO))).all() | ||
|
||
assert len(filing_task_states) == 1 | ||
assert filing_task_states[0].task.name == "Task-1" | ||
assert filing_task_states[0].filing == 1 | ||
assert filing_task_states[0].state == FilingTaskState.IN_PROGRESS | ||
assert filing_task_states[0].user == "[email protected]" | ||
assert filing_task_states[0].change_timestamp.timestamp() == pytest.approx( | ||
seconds_now, abs=1.0 | ||
) # allow for possible 1 second difference | ||
|
||
async def test_get_filing(self, query_session: AsyncSession): | ||
res = await repo.get_filing_period(query_session, filing_period_id=1) | ||
|
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
does the downgrade remove the custom type just by dropping the table, or do we need to do the drop type thing as well?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you, updated the downgrade to have a drop of the filingtaskstate TYPE. Note that sqlite doesn't have that concept so it checks for the dialect.