Skip to content
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 uniqueness for Template Units id (BugFix) #951

Merged
merged 9 commits into from
Feb 12, 2024
Merged

Commits on Jan 18, 2024

  1. 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.
    pieqq committed Jan 18, 2024
    Configuration menu
    Copy the full SHA
    d8c38cf View commit details
    Browse the repository at this point in the history
  2. 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.
    pieqq committed Jan 18, 2024
    Configuration menu
    Copy the full SHA
    81c9535 View commit details
    Browse the repository at this point in the history

Commits on Jan 22, 2024

  1. Configuration menu
    Copy the full SHA
    6f6cd46 View commit details
    Browse the repository at this point in the history
  2. 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.
    pieqq committed Jan 22, 2024
    Configuration menu
    Copy the full SHA
    ff727fe View commit details
    Browse the repository at this point in the history
  3. 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.
    pieqq committed Jan 22, 2024
    Configuration menu
    Copy the full SHA
    450b83c View commit details
    Browse the repository at this point in the history
  4. Configuration menu
    Copy the full SHA
    0ddf125 View commit details
    Browse the repository at this point in the history
  5. 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.
    pieqq committed Jan 22, 2024
    Configuration menu
    Copy the full SHA
    2660fab View commit details
    Browse the repository at this point in the history
  6. Configuration menu
    Copy the full SHA
    c24537d View commit details
    Browse the repository at this point in the history
  7. Configuration menu
    Copy the full SHA
    0e3d22d View commit details
    Browse the repository at this point in the history