-
Notifications
You must be signed in to change notification settings - Fork 20
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
Add Template_Categories table #2193
base: main
Are you sure you want to change the base?
Conversation
- Initial work on the models
- Fix typos - Update sqlalchemy model
- Added template_category_id to the template_history table - Adjusted model class name TemplateCategories -> TemplateCategory - WIP: Added some basic tests for the TemplateCategory dao
- Added a schema for TemplateCategory - Added from_json and serialize to the TemplateCategory model - Added the template/category Blueprint - Add some initial CRUD api endpoints
app/models.py
Outdated
@@ -1179,6 +1213,7 @@ class Template(TemplateBase): | |||
|
|||
service = db.relationship("Service", backref="templates") | |||
version = db.Column(db.Integer, default=0, nullable=False) | |||
category = db.relationship("TemplateCategory", backref="templates") |
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.
I would change this to template_category. Ignore my relationship comment above, this should work!
- Changed the category relationship in Template from TemplateCategory to template_category - dao_get_template_category_by_template_id now simply selects the template, and returns the associated template_category instead of using an expensive join
- Moved the default categories into our config file - Added dao_update_template_category - Added dao_delete_template_category_by_id - Added routes to: get and delete a template category - Added a route to get all template categories - Updated the migration file to use default category uuid's from the config file
- Squash more bugs - Fix formatting - Added a couple more tests for the filters on dao_get_all_template_categories
- Excluded the template_category table from deletion in notify_db_session to preserve the 3 generic template categories between test runs - Fixed inserts in the migration, apparently alembic / sqlalchemy doesn't like multi-line f-strings - Made a few tests shorter by excluding the description_en and description_fr columns as they are optional
- Allow passing of a uuid to dao_create_template_category - Fixed issues with get_template_categories and delete_template_category filters / flags - Added a fixture to re-populate the template_category table with generic categories and removed template_categories from the list of tables that are excluded from the post-test db clear
- formatting
- Fix incorrectly named prop call in dao - Added category as a declared attribute in TemplateBase model - Added a proper route to get a category by template id - Added a foreign key to templates_history for the category id - Fix a couple more tests
- Tweak tests - No longer excluding template_category_id in template_category_schema - Updated migration revision as 0453 was added for pinpoint work
Just saw the AC in this card to do exactly this - I will make the changes. We will also need to update |
- Remove NOT NULL constraint on templates.process_type
- Simplify the dao delete logic
- Adjust tests - formatting
@@ -241,6 +335,7 @@ def create_sample_template( | |||
subject_line="Subject", | |||
user=None, | |||
service=None, | |||
category=None, |
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.
Do we need template_category_id here instead of category?
assert dao_get_template_category_by_id(template_category.id) == template_category | ||
|
||
|
||
@pytest.mark.parametrize( |
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.
Originally I wanted to cut down the size of these parameters by creating the categories_to_insert
in the test body and modifying the hidden
field per test. When I did it this way, then between the tests the categories were not being removed from the test DB and the unique constraint on the name_en
and name_fr
was causing the tests to fail.
I can leave it as is or do something like set the name to a str(uuid)
to get around the unique constraint and shrink the size of this behemoth.
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.
Not a big deal I don't think. Weird that it couldnt delete the test data though.
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.
Looks good to me in general, I'll wait for Jumana for the sign off. I just approved your WAF update to fix the waffles issue - if you merge that one your tests should pass here I hope!
Deletes a `TemplateCategory`. By default, if the `TemplateCategory` is associated with any `Template`, it will not be deleted. | ||
If the `cascade` option is specified then the category will be forcible removed: | ||
1. The `Category` will be dissociated from templates that use it | ||
2. The template is assigned a category matching the priority of the previous category |
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.
Tiny edit here, but this makes it sound like it picks any category at random as long it has the same priority, instead of what (i think) it actually does which is picks the default category that matches the same priority.
assert dao_get_template_category_by_id(template_category.id) == template_category | ||
|
||
|
||
@pytest.mark.parametrize( |
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.
Not a big deal I don't think. Weird that it couldnt delete the test data though.
Summary | Résumé
This PR implements the backend work for Template Categories per the Short code ADR.
Change Details
template_categories
table to the DB in a migrationTemplateCategory
model and associations withTemplate
andTemplateHistory
/template-category
/template-category
/template-category
/template-category/<template_category_id>
/template-category/by-template-id/<template-id>
/template-category/<template_category_id>
/template-category/<template_category_id>?cascade=[True | False]
/service/<id>/template/<template_id>/category/<template_category_id>
Related Issues | Cartes liées
Test instructions | Instructions pour tester la modification
If you're using Postman, you can import this request collection to hit each new endpoint. I've included example payloads for create and update
Default generic Template Category id's you can use in the requests
/template/category
/template/category/<template_category_id>
Getting a Category
/template-category/<template_category_id>
/service/<service_id>/template/<template_id>/category/<template_category_id>
/template-category/by-template-id/<template-id>
Getting all Categories
You'll need to create some new categories to fully test the gets with filtering.
A
hidden
category - associate it with an SMS template1
not hidden
category - associate it with an email templateGet all categories -
/template-category
Get all categories filter by hidden
/template-category?hidden=[True | False | None]
Get all categories filter by template_type
/template-category?template_type=[sms | email]
Get all categories filter by hidden & template type
/template-category?hidden=[True | False | None]&template_type=[sms | email]
Deleting Categories
/template-category/template_category_id?cascade=False
category_id
from the earlier test where you associated it with a template/template-category/<template_category_id>?cascade=False
making surecascade=False
or omitted entirelycascade=True
in the query string and try deleting the same category againRelease Instructions | Instructions pour le déploiement
Reviewer checklist | Liste de vérification du réviseur