Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add uniqueness for Template Units id (BugFix) (canonical#951)
* Make sure Template units are units with id A Template unit always contains an id field. It should therefore inherit UnitWithId instead of Unit, so that the `partial_id()` and `id()` methods are inherited as well. * Prevent Template Units id from being rendered when using Jinja2 By default, templates using Jinja2 engine gets their id rendered as soon as they get accessed, but since they don't have the appropriate environment, the parameters are replaced with an empty string. This is why when you run the command `checkbox-cli list template`, you may see things like this: template 'com.canonical.certification::camera/still_' instead of template 'com.canonical.certification::camera/still_{{ name }}' Note that this does not happen with standard Python formatted strings: template 'com.canonical.certification::camera/led_{name}' In order to make the behavior consistent regardless of the template engine used, this commit: - introduces a unit property that always returns "template" (similar to how the Job unit always returns "job"). - modifies Unit.get_record_value() to prevent rendering using Jinja2 templating if the unit is a Checkbox Template It also contains unit tests for both the TemplateUnit and its Validator. * Have Template Unit's "template-id" field generated from the "id" field, if absent * Expose Template Unit's template-id field instead of id PlainBoxObject is used when exposing Units at a high level; for instance, when running `checkbox-cli list template`. Instead of exposing the Template Unit's id field, expose the template-id field. * Use Template partial_id and id, similar to Job's partial_id and id In order to have more granularity on what is displayed for the template id, use methods similar to the Job Unit. * Add unit test to ensure templates have a unique id * Implement explain() in TemplateUnit This method overrides UnitWithId.explain() which displays the Unit's id. In the case of a Template, this is misleading, and the template_id (or, in this case, template_partial_id to prevent displaying the provider namespace) should be used instead. This is useful when reporting errors using `./manage.py validate`, for instance. * Update Template Unit documentation about template-id field * Cleanup Template Unit reference documentation
- Loading branch information