Skip to content

Commit

Permalink
22617 - Added max_size column to Batch (bcgov#2926)
Browse files Browse the repository at this point in the history
* 22617 - Added max_size column to Batch

* misc fixes to tests
  • Loading branch information
JazzarKarim authored Aug 19, 2024
1 parent 8a01080 commit ff2d445
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 0 deletions.
4 changes: 4 additions & 0 deletions jobs/involuntary-dissolutions/involuntary_dissolutions.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,9 @@ def stage_1_process(app: Flask): # pylint: disable=redefined-outer-name,too-man
num_dissolutions_allowed = Configuration.find_by_name(config_name='NUM_DISSOLUTIONS_ALLOWED').val
businesses_eligible = InvoluntaryDissolutionService.get_businesses_eligible(num_dissolutions_allowed)

# get the MAX_DISSOLUTIONS_ALLOWED number of businesses
max_dissolutions_allowed = Configuration.find_by_name(config_name='MAX_DISSOLUTIONS_ALLOWED').val

if len(businesses_eligible) == 0:
app.logger.debug('Skipping job run since there are no businesses eligible for dissolution.')
return
Expand All @@ -184,6 +187,7 @@ def stage_1_process(app: Flask): # pylint: disable=redefined-outer-name,too-man
batch = Batch(batch_type=Batch.BatchType.INVOLUNTARY_DISSOLUTION,
status=Batch.BatchStatus.PROCESSING,
size=len(businesses_eligible),
max_size=max_dissolutions_allowed,
start_date=datetime.utcnow())
batch.save()
app.logger.debug(f'New batch has been created with ID: {batch.id}')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ def test_stage_1_process(app, session):
assert batch.batch_type == Batch.BatchType.INVOLUNTARY_DISSOLUTION
assert batch.status == Batch.BatchStatus.PROCESSING
assert batch.size == 3
assert batch.max_size == 600
assert batch.start_date.date() == datetime.now().date()

batch_processings = BatchProcessing.find_by(batch_id=batch.id)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
"""add_max_size_to_batches
Revision ID: 12f725915617
Revises: 01dc3337e726
Create Date: 2024-08-15 10:49:33.155500
"""
from alembic import op
import sqlalchemy as sa


# revision identifiers, used by Alembic.
revision = '12f725915617'
down_revision = '01dc3337e726'
branch_labels = None
depends_on = None


def upgrade():
op.add_column('batches', sa.Column('max_size', sa.Integer(), nullable=True))


def downgrade():
op.drop_column('batches', 'max_size')
1 change: 1 addition & 0 deletions legal-api/src/legal_api/models/batch.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ class BatchStatus(BaseEnum):
start_date = db.Column('start_date', db.DateTime(timezone=True), default=datetime.utcnow)
end_date = db.Column('end_date', db.DateTime(timezone=True), nullable=True)
notes = db.Column('notes', db.String(150), default='', nullable=True)
max_size = db.Column('max_size', db.Integer, nullable=True)

def save(self):
"""Save the object to the database immediately."""
Expand Down
2 changes: 2 additions & 0 deletions legal-api/tests/unit/models/test_batch.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ def test_valid_batch_save(session):
batch_type=Batch.BatchType.INVOLUNTARY_DISSOLUTION,
status=Batch.BatchStatus.HOLD,
size=3,
max_size=10,
notes=''
)
batch.save()
Expand All @@ -38,6 +39,7 @@ def test_find_batch_by_id(session):
batch_type=Batch.BatchType.INVOLUNTARY_DISSOLUTION,
status=Batch.BatchStatus.HOLD,
size=3,
max_size=10,
notes=''
)
batch.save()
Expand Down

0 comments on commit ff2d445

Please sign in to comment.