Skip to content

Commit

Permalink
Add unit tests for the new Template Unit fields
Browse files Browse the repository at this point in the history
  • Loading branch information
pieqq committed Feb 13, 2024
1 parent 4ea6fbc commit 83904fa
Showing 1 changed file with 68 additions and 0 deletions.
68 changes: 68 additions & 0 deletions checkbox-ng/plainbox/impl/unit/test_template.py
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,30 @@ def test_template_id__precedence_jinja2(self):
"id": "job_id_{{ param }}",
}).template_id, "template_id")

def test_template_summary(self):
self.assertEqual(TemplateUnit({
"template-summary": "summary",
}).template_summary, "summary")

def test_template_description(self):
self.assertEqual(TemplateUnit({
"template-description": "description",
}).template_description, "description")

def test_tr_template_summary(self):
"""Ensure template_summary is populated with the translated field."""
self.assertEqual(TemplateUnit({
"_template-summary": "summary",
}).template_summary, "summary")

def test_tr_template_description(self):
"""
Ensure template_description is populated with the translated field.
"""
self.assertEqual(TemplateUnit({
"_template-description": "description",
}).template_description, "description")

def test_template_resource__empty(self):
self.assertEqual(TemplateUnit({}).template_resource, None)

Expand Down Expand Up @@ -496,6 +520,50 @@ def test_template_unit__untranslatable(self):
issue_list, self.unit_cls.Meta.fields.template_unit,
Problem.unexpected_i18n, Severity.warning)

def test_template_summary__translatable(self):
issue_list = self.unit_cls({
'template-summary': 'template_summary'
}, provider=self.provider).check()
self.assertIssueFound(issue_list,
self.unit_cls.Meta.fields.template_summary,
Problem.expected_i18n,
Severity.warning)

def test_template_summary__present(self):
issue_list = self.unit_cls({
}, provider=self.provider).check()
self.assertIssueFound(issue_list,
self.unit_cls.Meta.fields.template_summary,
Problem.missing,
Severity.advice)

def test_template_summary__one_line(self):
issue_list = self.unit_cls({
'template-summary': 'line1\nline2'
}, provider=self.provider).check()
self.assertIssueFound(issue_list,
self.unit_cls.Meta.fields.template_summary,
Problem.wrong,
Severity.warning)

def test_template_summary__short_line(self):
issue_list = self.unit_cls({
'template-summary': 'x' * 81
}, provider=self.provider).check()
self.assertIssueFound(issue_list,
self.unit_cls.Meta.fields.template_summary,
Problem.wrong,
Severity.warning)

def test_template_description__translatable(self):
issue_list = self.unit_cls({
'template-description': 'template_description'
}, provider=self.provider).check()
self.assertIssueFound(issue_list,
self.unit_cls.Meta.fields.template_description,
Problem.expected_i18n,
Severity.warning)

def test_template_resource__untranslatable(self):
issue_list = self.unit_cls({
'_template-resource': 'template_resource'
Expand Down

0 comments on commit 83904fa

Please sign in to comment.