Skip to content

Commit

Permalink
Add TemplateUnit.__repr__ and modify its __str__ method (Bugfix) (#1049)
Browse files Browse the repository at this point in the history
Add TemplateUnit.__repr__ and modify its __str__ method

Update TemplateUnit.__str__ to use the new template_id field for more
accuracy.

Add proper representation, similar to JobDefinition objects.
  • Loading branch information
pieqq authored Mar 12, 2024
1 parent cd17d9a commit 5a56038
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
6 changes: 5 additions & 1 deletion checkbox-ng/plainbox/impl/unit/template.py
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,11 @@ def instantiate_template(cls, data, raw_data, origin, provider, parameters,

def __str__(self):
"""String representation of Template unit objects."""
return "{} <~ {}".format(self.id, self.resource_id)
return "{} <~ {}".format(self.template_id, self.resource_id)

def __repr__(self):
return "<TemplateUnit template_id:{!r}>".format(
self.template_id)

@property
def unit(self):
Expand Down
19 changes: 19 additions & 0 deletions checkbox-ng/plainbox/impl/unit/test_template.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,25 @@

class TemplateUnitTests(TestCase):

def test_str(self):
template = TemplateUnit({
"template-resource": "resource",
"template-id": "check-devices",
"id": "check-device-{dev_name}",
})
self.assertEqual(str(template), "check-devices <~ resource")

def test_repr(self):
template = TemplateUnit({
"template-resource": "resource",
"template-id": "check-devices",
"id": "check-device-{dev_name}",
})
self.assertEqual(
repr(template),
"<TemplateUnit template_id:'check-devices'>"
)

def test_id(self):
template = TemplateUnit({
"template-resource": "resource",
Expand Down

0 comments on commit 5a56038

Please sign in to comment.