Skip to content

Commit

Permalink
Make full path of the object seen in the output for any change in Set…
Browse files Browse the repository at this point in the history
…Action and EditAction

Change-Id: I9c3a90f2fbf754876ca0ce083747549c22bd7b5b
  • Loading branch information
lavagetto committed Feb 27, 2018
1 parent 6d191f9 commit d95d8de
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 4 deletions.
5 changes: 3 additions & 2 deletions conftool/action.py
Expand Up @@ -86,7 +86,7 @@ def run(self):
print("Reported reason: {}".format(e))
self._check_amend(e)
self.entity.update(self.edited)
return "Entity successfully updated"
return "Entity {} successfully updated".format(self.entity.pprint())
finally:
os.unlink(self.temp)

Expand All @@ -108,6 +108,7 @@ def _to_file(self):
self.temp = f.name
else:
f = open(self.temp, 'wb')
f.write("# Editing object {}".format(self.entity.pprint()))
self.entity.fetch()
yaml.safe_dump(self.entity._to_net(), stream=f, encoding='utf-8')
f.close()
Expand Down Expand Up @@ -184,7 +185,7 @@ def run(self):
curval = getattr(self.entity, k)
if v != curval:
msg = "%s: %s changed %s => %s" % (
self.entity.name, k,
self.entity.pprint(), k,
curval, v)
desc.append(msg)
self.entity.update(self.args)
Expand Down
4 changes: 4 additions & 0 deletions conftool/kvobject.py
Expand Up @@ -247,6 +247,10 @@ def key(self):
def tags(self):
return self._current_tags

def pprint(self):
tags_path = os.path.join(*[self._current_tags[tag] for tag in self._tags])
return os.path.join(tags_path, self._name)

@classmethod
def dir(cls, *tags):
if len(tags) != len(cls._tags):
Expand Down
4 changes: 2 additions & 2 deletions conftool/tests/unit/test_action.py
Expand Up @@ -128,7 +128,7 @@ def test_edit_run(self):
a.temp = 'testunlink'
with mock.patch('conftool.action.os.unlink') as unlinker:
self.entity.update = mock.MagicMock()
self.assertEqual(a.run(), "Entity successfully updated")
self.assertEqual(a.run(), "Entity Foo/Bar/test successfully updated")
self.entity.update.assert_called_with(a.edited)
a._edit.assert_called_once()
exception = ValueError('test me')
Expand All @@ -137,7 +137,7 @@ def test_edit_run(self):
)
a._check_amend = mock.MagicMock()
with mock.patch('conftool.action.os.unlink') as unlinker:
self.assertEqual(a.run(), "Entity successfully updated")
self.assertEqual(a.run(), "Entity Foo/Bar/test successfully updated")
a._check_amend.assert_called_with(exception)
unlinker.assert_called_with(a.temp)

Expand Down
2 changes: 2 additions & 0 deletions conftool/tests/unit/test_kvobject.py
Expand Up @@ -23,6 +23,8 @@ def test_tags(self):
ent = MockBasicEntity()
self.assertEqual(ent.tags, {'A': 'a', 'B': 'b', 'C': 'c', 'D': 'd'})

def test_pprint(self):
self.assertEqual(self.entity.pprint(), 'Foo/Bar/test')

def test_kvpath(self):
"""
Expand Down

0 comments on commit d95d8de

Please sign in to comment.