forked from bcgov/lear
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
21817 staff review models (bcgov#2797)
- Loading branch information
1 parent
4c0a3a1
commit 07b450f
Showing
7 changed files
with
367 additions
and
0 deletions.
There are no files selected for viewing
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,56 @@ | ||
"""review | ||
Revision ID: ec9652171563 | ||
Revises: 01b28a2bb730 | ||
Create Date: 2024-06-26 16:13:07.413995 | ||
""" | ||
from alembic import op | ||
import sqlalchemy as sa | ||
from sqlalchemy.dialects import postgresql | ||
|
||
# revision identifiers, used by Alembic. | ||
revision = 'ec9652171563' | ||
down_revision = '01b28a2bb730' | ||
branch_labels = None | ||
depends_on = None | ||
|
||
|
||
def upgrade(): | ||
# ### commands auto generated by Alembic - please adjust! ### | ||
op.add_column('filings', sa.Column('resubmission_date', sa.DateTime(timezone=True), nullable=True)) | ||
|
||
op.create_table('reviews', | ||
sa.Column('id', sa.Integer(), nullable=False), | ||
sa.Column('nr_number', sa.String(length=15), nullable=True), | ||
sa.Column('identifier', sa.String(length=50), nullable=True), | ||
sa.Column('completing_party', sa.String(length=150), nullable=True), | ||
sa.Column('status', sa.Enum('AWAITING_REVIEW', 'CHANGE_REQUESTED', 'RESUBMITTED', 'APPROVED', 'REJECTED', name='review_status'), nullable=False), | ||
sa.Column('submission_date', sa.DateTime(timezone=True), nullable=True), | ||
sa.Column('creation_date', sa.DateTime(timezone=True), nullable=True), | ||
sa.Column('filing_id', sa.Integer(), nullable=False), | ||
sa.ForeignKeyConstraint(['filing_id'], ['filings.id'], ), | ||
sa.PrimaryKeyConstraint('id') | ||
) | ||
op.create_table('review_results', | ||
sa.Column('id', sa.Integer(), nullable=False), | ||
sa.Column('status', sa.Enum('AWAITING_REVIEW', 'CHANGE_REQUESTED', 'RESUBMITTED', 'APPROVED', 'REJECTED', name='review_status'), nullable=False), | ||
sa.Column('comments', sa.Text(), nullable=True), | ||
sa.Column('reviewer_id', sa.Integer(), nullable=True), | ||
sa.Column('creation_date', sa.DateTime(timezone=True), nullable=True), | ||
sa.Column('submission_date', sa.DateTime(timezone=True), nullable=True), | ||
sa.Column('review_id', sa.Integer(), nullable=False), | ||
sa.ForeignKeyConstraint(['review_id'], ['reviews.id'], ), | ||
sa.ForeignKeyConstraint(['reviewer_id'], ['users.id'], ), | ||
sa.PrimaryKeyConstraint('id') | ||
) | ||
# ### end Alembic commands ### | ||
|
||
|
||
def downgrade(): | ||
# ### commands auto generated by Alembic - please adjust! ### | ||
op.drop_column('filings', 'resubmission_date') | ||
op.drop_table('review_results') | ||
op.drop_table('reviews') | ||
op.execute("DROP TYPE review_status;") | ||
# ### end Alembic commands ### |
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 |
---|---|---|
@@ -0,0 +1,77 @@ | ||
# 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. | ||
"""This module holds the data about review.""" | ||
from __future__ import annotations | ||
|
||
from enum import auto | ||
|
||
from legal_api.utils.base import BaseEnum | ||
from legal_api.utils.datetime import datetime | ||
|
||
from .db import db | ||
|
||
|
||
class ReviewStatus(BaseEnum): | ||
"""Render an Enum of the review status.""" | ||
|
||
AWAITING_REVIEW = auto() | ||
CHANGE_REQUESTED = auto() | ||
RESUBMITTED = auto() | ||
APPROVED = auto() | ||
REJECTED = auto() | ||
|
||
|
||
class Review(db.Model): # pylint: disable=too-many-instance-attributes | ||
"""This class manages the review.""" | ||
|
||
__tablename__ = 'reviews' | ||
|
||
id = db.Column(db.Integer, primary_key=True) | ||
nr_number = db.Column('nr_number', db.String(15)) | ||
identifier = db.Column('identifier', db.String(50)) | ||
completing_party = db.Column('completing_party', db.String(150)) | ||
status = db.Column('status', db.Enum(ReviewStatus), nullable=False) | ||
submission_date = db.Column('submission_date', | ||
db.DateTime(timezone=True), | ||
default=datetime.utcnow) # last submission date | ||
creation_date = db.Column('creation_date', db.DateTime(timezone=True), default=datetime.utcnow) | ||
|
||
# parent keys | ||
filing_id = db.Column('filing_id', db.Integer, db.ForeignKey('filings.id'), nullable=False) | ||
|
||
# relationships | ||
review_results = db.relationship('ReviewResult', lazy='dynamic') | ||
|
||
def save(self): | ||
"""Save the object to the database immediately.""" | ||
db.session.add(self) | ||
db.session.commit() | ||
|
||
@classmethod | ||
def find_by_id(cls, review_id) -> Review: | ||
"""Return review by the id.""" | ||
review = None | ||
if review_id: | ||
review = cls.query.filter_by(id=review_id).one_or_none() | ||
return review | ||
|
||
@classmethod | ||
def get_review(cls, filing_id) -> Review: | ||
"""Return review by the filing id.""" | ||
review = None | ||
if filing_id: | ||
review = (db.session.query(Review). | ||
filter(Review.filing_id == filing_id). | ||
one_or_none()) | ||
return review |
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,71 @@ | ||
# 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. | ||
"""This module holds the data about review result.""" | ||
from __future__ import annotations | ||
|
||
from typing import List | ||
|
||
from sqlalchemy.orm import backref | ||
|
||
from legal_api.utils.datetime import datetime | ||
|
||
from .db import db | ||
from .review import ReviewStatus | ||
|
||
|
||
class ReviewResult(db.Model): # pylint: disable=too-many-instance-attributes | ||
"""This class manages the review result.""" | ||
|
||
__tablename__ = 'review_results' | ||
|
||
id = db.Column(db.Integer, primary_key=True) | ||
status = db.Column('status', db.Enum(ReviewStatus), nullable=False) | ||
comments = db.Column(db.Text) | ||
|
||
reviewer_id = db.Column('reviewer_id', db.Integer, db.ForeignKey('users.id')) | ||
reviewer = db.relationship('User', | ||
backref=backref('reviewer', uselist=False), | ||
foreign_keys=[reviewer_id]) | ||
|
||
creation_date = db.Column('creation_date', db.DateTime(timezone=True), default=datetime.utcnow) | ||
submission_date = db.Column('submission_date', db.DateTime(timezone=True)) # submission/re-submission date | ||
|
||
# parent keys | ||
review_id = db.Column('review_id', db.Integer, db.ForeignKey('reviews.id'), nullable=False) | ||
|
||
def save(self): | ||
"""Save the object to the database immediately.""" | ||
db.session.add(self) | ||
db.session.commit() | ||
|
||
@ classmethod | ||
def get_review_results(cls, review_id) -> List[ReviewResult]: | ||
"""Return review results by the review id.""" | ||
review_results = None | ||
if review_id: | ||
review_results = (db.session.query(ReviewResult). | ||
filter(ReviewResult.review_id == review_id). | ||
all()) | ||
return review_results | ||
|
||
@ classmethod | ||
def get_last_review_result(cls, review_id) -> ReviewResult: | ||
"""Return the last review result by the review id.""" | ||
review_result = None | ||
if review_id: | ||
review_result = (db.session.query(ReviewResult). | ||
filter(ReviewResult.review_id == review_id). | ||
order_by(ReviewResult.creation_date.desc()). | ||
first()) | ||
return review_result |
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,58 @@ | ||
# 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 Review Model. | ||
Test-Suite to ensure that the Review Model is working as expected. | ||
""" | ||
import copy | ||
from registry_schemas.example_data import ( | ||
CONTINUATION_IN, | ||
) | ||
|
||
from legal_api.models import Review, ReviewStatus | ||
|
||
from tests.unit.models import factory_filing | ||
|
||
|
||
def test_review_save(session): | ||
"""Assert that the review was saved.""" | ||
filing_dict = { | ||
'filing': { | ||
'header': { | ||
'name': 'continuationIn', | ||
'date': '2019-04-08', | ||
'certifiedBy': 'full name', | ||
'email': '[email protected]', | ||
} | ||
} | ||
} | ||
filing_dict['filing']['continuationIn'] = copy.deepcopy(CONTINUATION_IN) | ||
filing = factory_filing(None, filing_dict) | ||
|
||
review = Review() | ||
review.filing_id = filing.id | ||
review.nr_number = filing_dict['filing']['continuationIn']['nameRequest']['nrNumber'] | ||
review.identifier = filing_dict['filing']['continuationIn']['foreignJurisdiction']['identifier'] | ||
review.completing_party = 'completing party' | ||
review.status = ReviewStatus.AWAITING_REVIEW | ||
review.save() | ||
|
||
assert review.id | ||
|
||
review = Review.find_by_id(review.id) | ||
assert review | ||
|
||
review = Review.get_review(review.filing_id) | ||
assert review |
Oops, something went wrong.