From abad7a9a9c5607aaed646831e6e1b3079fa1e781 Mon Sep 17 00:00:00 2001 From: leodube-aot <122323255+leodube-aot@users.noreply.github.com> Date: Mon, 21 Oct 2024 12:31:11 -0700 Subject: [PATCH] Undo colin_event_id model changes (#3032) --- ...b30f43aa86_undo_colin_event_ids_changes.py | 27 +++++ .../src/legal_api/models/colin_event_id.py | 16 --- .../tests/unit/models/test_colin_event_id.py | 101 ------------------ 3 files changed, 27 insertions(+), 117 deletions(-) create mode 100644 legal-api/migrations/versions/f3b30f43aa86_undo_colin_event_ids_changes.py delete mode 100644 legal-api/tests/unit/models/test_colin_event_id.py diff --git a/legal-api/migrations/versions/f3b30f43aa86_undo_colin_event_ids_changes.py b/legal-api/migrations/versions/f3b30f43aa86_undo_colin_event_ids_changes.py new file mode 100644 index 0000000000..c20353379f --- /dev/null +++ b/legal-api/migrations/versions/f3b30f43aa86_undo_colin_event_ids_changes.py @@ -0,0 +1,27 @@ +"""Undo colin_event_ids changes. + +Revision ID: f3b30f43aa86 +Revises: 698885b80fc0 +Create Date: 2024-10-21 11:09:24.413272 + +""" +from alembic import op +import sqlalchemy as sa + + +# revision identifiers, used by Alembic. +revision = 'f3b30f43aa86' +down_revision = '698885b80fc0' +branch_labels = None +depends_on = None + + +def upgrade(): + 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') + +def downgrade(): + 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(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']) diff --git a/legal-api/src/legal_api/models/colin_event_id.py b/legal-api/src/legal_api/models/colin_event_id.py index c55c512d5d..594c1352fb 100644 --- a/legal-api/src/legal_api/models/colin_event_id.py +++ b/legal-api/src/legal_api/models/colin_event_id.py @@ -15,7 +15,6 @@ The ColinEventId class and Schema are held in this module. """ -from legal_api.models import BatchProcessing from .db import db @@ -27,11 +26,6 @@ class ColinEventId(db.Model): # pylint: disable=too-few-public-methods colin_event_id = db.Column('colin_event_id', db.Integer, unique=True, primary_key=True) filing_id = db.Column('filing_id', db.Integer, db.ForeignKey('filings.id')) - batch_processing_id = db.Column('batch_processing_id', db.Integer, db.ForeignKey('batch_processing.id')) - batch_processing_step = db.Column('batch_processing_step', db.Enum(BatchProcessing.BatchProcessingStep)) - - # relationships - batch_processing = db.relationship('BatchProcessing', lazy='select', uselist=False) def save(self): """Save the object to the database immediately.""" @@ -53,13 +47,3 @@ def get_by_colin_id(colin_id): colin_event_id_obj =\ db.session.query(ColinEventId).filter(ColinEventId.colin_event_id == colin_id).one_or_none() return colin_event_id_obj - - @staticmethod - def get_by_batch_processing_id(batch_processing_id): - """Get the list of colin_event_ids linked to the given batch_processing_id.""" - colin_event_id_objs = db.session.query(ColinEventId). \ - filter(ColinEventId.batch_processing_id == batch_processing_id).all() - id_list = [] - for obj in colin_event_id_objs: - id_list.append(obj.colin_event_id) - return id_list diff --git a/legal-api/tests/unit/models/test_colin_event_id.py b/legal-api/tests/unit/models/test_colin_event_id.py deleted file mode 100644 index 970e55a400..0000000000 --- a/legal-api/tests/unit/models/test_colin_event_id.py +++ /dev/null @@ -1,101 +0,0 @@ -# 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