SUBMIT-781 Create backend unit tests for models and updated invitation logic#831
SUBMIT-781 Create backend unit tests for models and updated invitation logic#831leodube-aot wants to merge 11 commits intobcgov:developfrom
Conversation
| cls._add_completed_status(aggregated_statuses, statuses) | ||
| cls._add_submitted_status(aggregated_statuses, statuses) | ||
| cls._add_passed_consultation_check(aggregated_statuses, statuses) | ||
| cls._add_review_rejected(aggregated_statuses, statuses) |
There was a problem hiding this comment.
duplicated from line 122
| else: | ||
| account.save() | ||
| return account | ||
| return account.persist(session) |
There was a problem hiding this comment.
We use this pattern quite frequently: if session - flush, else - save. I moved this into a common method called persist that does the same thing, but avoids duplicate code.
| type_id = fields.Int(data_key="type_id") | ||
| status = fields.List(fields.Enum(enum=PackageStatus), | ||
| enum=PackageStatus, data_key="status") | ||
| status = fields.List(fields.Enum(enum=PackageStatus), data_key="status", metadata={"enum": PackageStatus}) |
There was a problem hiding this comment.
Marshmallow 3.x deprecated passing extra metadata (like enum, description, example, etc.) as direct keyword arguments to fields. They need to be wrapped in an explicit metadata={} dict.
| user = UserModel.query.filter(UserModel.id == user_id).first() | ||
| return user.user_status.status_name if user else None | ||
| return UserModel.get_status_name_by_id(user_id) |
There was a problem hiding this comment.
Part of the refactoring: Encapsulated Model.query.filter calls and moved into the model file itself. Now we call the encapsulated query. No logic actually changes here.
| return query.order_by(cls.name).all() | ||
|
|
||
| @classmethod | ||
| def get_proponent_by_id( |
There was a problem hiding this comment.
This wasn't deleted, just moved into the proponent_service file. This method does a lot of orchestration work, pulling from several other db models. Makes more sense as a service.
Ticket: SUBMIT-781 Create backend unit tests for work/phase/invitation/account management
Description
Refactoring
datetime.utcnowtodatetime.now(UTC)./servicesinto specific/modelsfiles. This was to try to keep direct orm operations in the models (ie.db.queryoperations)persistmethod on theBaseModelto avoid duplicate code.