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

183 val json to results #193

Merged
merged 2 commits into from
May 2, 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
@@ -0,0 +1,26 @@
"""Renaming validation json to results

Revision ID: 5492f53d1fa5
Revises: e1b0d044c840
Create Date: 2024-05-01 13:40:54.288361

"""
from typing import Sequence, Union

from alembic import op

# revision identifiers, used by Alembic.
revision: str = "5492f53d1fa5"
down_revision: Union[str, None] = "e1b0d044c840"
branch_labels: Union[str, Sequence[str], None] = None
depends_on: Union[str, Sequence[str], None] = None


def upgrade() -> None:
with op.batch_alter_table("submission") as batch_op:
batch_op.alter_column("validation_json", new_column_name="validation_results")


def downgrade() -> None:
with op.batch_alter_table("submission") as batch_op:
batch_op.alter_column("validation_results", new_column_name="validation_json")
2 changes: 1 addition & 1 deletion src/sbl_filing_api/entities/models/dao.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class SubmissionDAO(Base):
accepter: Mapped[UserActionDAO] = relationship(lazy="selectin", foreign_keys=[accepter_id])
state: Mapped[SubmissionState] = mapped_column(SAEnum(SubmissionState))
validation_ruleset_version: Mapped[str] = mapped_column(nullable=True)
validation_json: Mapped[dict[str, Any]] = mapped_column(JSON, nullable=True)
validation_results: Mapped[dict[str, Any]] = mapped_column(JSON, nullable=True)
submission_time: Mapped[datetime] = mapped_column(server_default=func.now())
filename: Mapped[str]

Expand Down
2 changes: 1 addition & 1 deletion src/sbl_filing_api/entities/models/dto.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class SubmissionDTO(BaseModel):
id: int | None = None
state: SubmissionState | None = None
validation_ruleset_version: str | None = None
validation_json: Dict[str, Any] | None = None
validation_results: Dict[str, Any] | None = None
submission_time: datetime | None = None
filename: str
submitter: UserActionDTO
Expand Down
2 changes: 1 addition & 1 deletion src/sbl_filing_api/services/submission_processor.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ async def validate_and_update_submission(period_code: str, lei: str, submission:
)
else:
submission.state = SubmissionState.VALIDATION_SUCCESSFUL
submission.validation_json = build_validation_results(result)
submission.validation_results = build_validation_results(result)
submission_report = df_to_download(result[1])
await upload_to_storage(
period_code, lei, str(submission.id) + REPORT_QUALIFIER, submission_report.encode("utf-8")
Expand Down
6 changes: 3 additions & 3 deletions tests/entities/repos/test_submission_repo.py
Original file line number Diff line number Diff line change
Expand Up @@ -443,8 +443,8 @@ async def query_updated_dao():

await query_updated_dao()

validation_json = self.get_error_json()
res.validation_json = validation_json
validation_results = self.get_error_json()
res.validation_results = validation_results
res.state = SubmissionState.VALIDATION_WITH_ERRORS
# to test passing in a session to the update_submission function
async with session_generator() as update_session:
Expand All @@ -457,7 +457,7 @@ async def query_updated_dao():
assert new_res2.id == 5
assert new_res2.filing == 1
assert new_res2.state == SubmissionState.VALIDATION_WITH_ERRORS
assert new_res2.validation_json == validation_json
assert new_res2.validation_results == validation_results

await query_updated_dao()

Expand Down
9 changes: 9 additions & 0 deletions tests/migrations/test_migrations.py
Original file line number Diff line number Diff line change
Expand Up @@ -372,3 +372,12 @@ def test_migration_to_e1b0d044c840(alembic_runner: MigrationContext, alembic_eng

assert "phone_number" in [c["name"] for c in inspector.get_columns("contact_info")]
assert "phone" not in [c["name"] for c in inspector.get_columns("contact_info")]


def test_migration_to_5492f53d1fa5(alembic_runner: MigrationContext, alembic_engine: Engine):
alembic_runner.migrate_up_to("5492f53d1fa5")

inspector = sqlalchemy.inspect(alembic_engine)

assert "validation_results" in [c["name"] for c in inspector.get_columns("submission")]
assert "validation_json" not in [c["name"] for c in inspector.get_columns("submission")]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome checking for the columns

36 changes: 18 additions & 18 deletions tests/services/test_submission_processor.py
Original file line number Diff line number Diff line change
Expand Up @@ -316,10 +316,10 @@ async def mock_validate_and_update_submission(

async def test_build_validation_results_success(self):
result = (True, pd.DataFrame, ValidationPhase.LOGICAL.value)
validation_json = submission_processor.build_validation_results(result)
assert validation_json["syntax_errors"]["count"] == 0
assert validation_json["logic_errors"]["count"] == 0
assert validation_json["logic_warnings"]["count"] == 0
validation_results = submission_processor.build_validation_results(result)
assert validation_results["syntax_errors"]["count"] == 0
assert validation_results["logic_errors"]["count"] == 0
assert validation_results["logic_warnings"]["count"] == 0

async def test_build_validation_results_syntax_errors(self):
result = (
Expand Down Expand Up @@ -356,8 +356,8 @@ async def test_build_validation_results_syntax_errors(self):
),
ValidationPhase.SYNTACTICAL.value,
)
validation_json = submission_processor.build_validation_results(result)
assert validation_json["syntax_errors"]["count"] > 0
validation_results = submission_processor.build_validation_results(result)
assert validation_results["syntax_errors"]["count"] > 0

async def test_build_validation_results_logic_warnings(self):
result = (
Expand Down Expand Up @@ -394,10 +394,10 @@ async def test_build_validation_results_logic_warnings(self):
),
ValidationPhase.LOGICAL.value,
)
validation_json = submission_processor.build_validation_results(result)
assert validation_json["syntax_errors"]["count"] == 0
assert validation_json["logic_errors"]["count"] == 0
assert validation_json["logic_warnings"]["count"] > 0
validation_results = submission_processor.build_validation_results(result)
assert validation_results["syntax_errors"]["count"] == 0
assert validation_results["logic_errors"]["count"] == 0
assert validation_results["logic_warnings"]["count"] > 0

async def test_build_validation_results_logic_errors(self):
result = (
Expand Down Expand Up @@ -434,10 +434,10 @@ async def test_build_validation_results_logic_errors(self):
),
ValidationPhase.LOGICAL.value,
)
validation_json = submission_processor.build_validation_results(result)
assert validation_json["syntax_errors"]["count"] == 0
assert validation_json["logic_errors"]["count"] > 0
assert validation_json["logic_warnings"]["count"] == 0
validation_results = submission_processor.build_validation_results(result)
assert validation_results["syntax_errors"]["count"] == 0
assert validation_results["logic_errors"]["count"] > 0
assert validation_results["logic_warnings"]["count"] == 0

async def test_build_validation_results_logic_warnings_and_errors(self):
result = (
Expand Down Expand Up @@ -487,7 +487,7 @@ async def test_build_validation_results_logic_warnings_and_errors(self):
),
ValidationPhase.LOGICAL.value,
)
validation_json = submission_processor.build_validation_results(result)
assert validation_json["syntax_errors"]["count"] == 0
assert validation_json["logic_errors"]["count"] > 0
assert validation_json["logic_warnings"]["count"] > 0
validation_results = submission_processor.build_validation_results(result)
assert validation_results["syntax_errors"]["count"] == 0
assert validation_results["logic_errors"]["count"] > 0
assert validation_results["logic_warnings"]["count"] > 0
Loading