-
Notifications
You must be signed in to change notification settings - Fork 73
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
23539 add batch_processing to colin_event_ids table #3021
Merged
kzdev420
merged 4 commits into
bcgov:main
from
kzdev420:23539_track_colin_dissolution_stage_event_ids_in_colin_event_ids_table
Oct 9, 2024
Merged
Changes from 3 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
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
28 changes: 28 additions & 0 deletions
28
legal-api/migrations/versions/83a110e10979_add_batch_processing_id_to_colin_event_.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,28 @@ | ||
"""add_batch_processing_id_to_colin_event_ids | ||
|
||
Revision ID: 83a110e10979 | ||
Revises: d55dfc5c1358 | ||
Create Date: 2024-10-07 15:34:55.319366 | ||
|
||
""" | ||
from alembic import op | ||
import sqlalchemy as sa | ||
|
||
|
||
# revision identifiers, used by Alembic. | ||
revision = '83a110e10979' | ||
down_revision = 'd55dfc5c1358' | ||
branch_labels = None | ||
depends_on = None | ||
|
||
|
||
def upgrade(): | ||
op.add_column('colin_event_ids', sa.Column('batch_processing_id', sa.Integer(), nullable=True)) | ||
op.add_column('colin_event_ids', sa.Column('batch_processing_step', sa.Enum('WARNING_LEVEL_1', 'WARNING_LEVEL_2', 'DISSOLUTION', name='batch_processing_step'), nullable=True)) | ||
op.create_foreign_key('colin_event_ids_batch_processing_id_fkey', 'colin_event_ids', 'batch_processing', ['batch_processing_id'], ['id']) | ||
|
||
|
||
def downgrade(): | ||
op.drop_constraint('colin_event_ids_batch_processing_id_fkey', 'colin_event_ids', type_='foreignkey') | ||
op.drop_column('colin_event_ids', 'batch_processing_id') | ||
op.drop_column('colin_event_ids', 'batch_processing_step') |
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 |
---|---|---|
@@ -0,0 +1,101 @@ | ||
# Copyright © 2024 Province of British Columbia | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
"""Tests to assure the Colin Event Id Model. | ||
|
||
Test-Suite to ensure that the Colin Event Id Model is working as expected. | ||
""" | ||
from legal_api.models.colin_event_id import ColinEventId | ||
from registry_schemas.example_data import ANNUAL_REPORT | ||
|
||
from tests.unit.models import factory_business, factory_batch, factory_batch_processing, factory_filing | ||
|
||
|
||
def test_valid_colin_event_id_save(session): | ||
"""Assert that a valid Colin Event Id can be saved.""" | ||
business_identifier = 'BC1234567' | ||
business = factory_business(business_identifier) | ||
filing = factory_filing(business, ANNUAL_REPORT) | ||
colin_event_id = ColinEventId(filing_id=filing.id) | ||
colin_event_id.save() | ||
assert colin_event_id.colin_event_id | ||
|
||
# Save with batch_processing | ||
batch = factory_batch() | ||
batch_processing = factory_batch_processing( | ||
batch_id=batch.id, | ||
business_id=business.id, | ||
identifier=business_identifier | ||
) | ||
colin_event_id.batch_processing_id = batch_processing.id | ||
colin_event_id.batch_processing_step = batch_processing.step | ||
colin_event_id.save() | ||
assert colin_event_id.batch_processing_id | ||
assert colin_event_id.batch_processing_step | ||
assert colin_event_id.batch_processing | ||
|
||
|
||
def test_get_by_colin_id(session): | ||
"""Assert that the method returns correct value.""" | ||
business_identifier = 'BC1234567' | ||
business = factory_business(business_identifier) | ||
filing = factory_filing(business, ANNUAL_REPORT) | ||
colin_event_id = ColinEventId(filing_id=filing.id) | ||
colin_event_id.save() | ||
|
||
res = ColinEventId.get_by_colin_id(colin_event_id.colin_event_id) | ||
|
||
assert res | ||
assert res.filing_id == colin_event_id.filing_id | ||
|
||
|
||
def test_get_by_filing_id(session): | ||
"""Assert that the method returns correct value.""" | ||
business_identifier = 'BC1234567' | ||
business = factory_business(business_identifier) | ||
filing = factory_filing(business, ANNUAL_REPORT) | ||
colin_event_id = ColinEventId(filing_id=filing.id) | ||
colin_event_id.save() | ||
|
||
res = ColinEventId.get_by_filing_id(filing.id) | ||
|
||
assert res | ||
assert len(res) == 1 | ||
assert res[0] == colin_event_id.colin_event_id | ||
|
||
|
||
def test_get_by_batch_processing_id(session): | ||
"""Assert that the method returns correct value.""" | ||
business_identifier = 'BC1234567' | ||
business = factory_business(business_identifier) | ||
filing = factory_filing(business, ANNUAL_REPORT) | ||
|
||
batch = factory_batch() | ||
batch_processing = factory_batch_processing( | ||
batch_id=batch.id, | ||
business_id=business.id, | ||
identifier=business_identifier | ||
) | ||
colin_event_id = ColinEventId( | ||
filing_id=filing.id, | ||
batch_processing_id = batch_processing.id, | ||
batch_processing_step = batch_processing.step | ||
) | ||
colin_event_id.save() | ||
|
||
res = ColinEventId.get_by_batch_processing_id(batch_processing.id) | ||
|
||
assert res | ||
assert len(res) == 1 | ||
assert res[0] == colin_event_id.colin_event_id |
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.
Something I found interesting and didn't know about how alembic and sqlalchemy handles re-using enums:
To me it looked like you were re-creating the enum, so I was wondering what would happen if I changed the enum values here, and if it would have any effect on the existing
batch_processing_step
enum.Turns out this has no effect on the values
batch_processing.batch_processing_step
orcolin_event_id.batch_processing_step
. So alembic must be pointing thecolin_event_id.batch_processing_step
enum to the existing one.Taking it a step further, you can remove all the enum values here and it still works as long as the
name
parameter points to the correct enum.Can you update this line to remove the enum values? Just to avoid any confusion as to what this line is doing.
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.
Good Catch.
I removed it and tested it. It works well