tests: tracker: Add ConfigurationTracker to test *config-{mod,show} commands

https://pagure.io/freeipa/issue/7105

Reviewed-By: Florence Blanc-Renaud <frenaud@redhat.com>
This commit is contained in:
David Kupka 2017-01-26 17:11:16 +01:00 committed by Tomas Krizek
parent 7b015a2e76
commit 3113bfb0cf
No known key found for this signature in database
GPG Key ID: 22A2A94B5E49415A

View File

@ -131,6 +131,7 @@ class SearchTracker(BaseTracker):
class ModificationTracker(BaseTracker): class ModificationTracker(BaseTracker):
update_keys = None update_keys = None
singlevalue_keys = None
def make_update_command(self, updates): def make_update_command(self, updates):
"""Make function that modifies the entry using ${CMD}_mod""" """Make function that modifies the entry using ${CMD}_mod"""
@ -313,6 +314,33 @@ class EnableTracker(BaseTracker):
return super(EnableTracker, self).make_fixture(request) return super(EnableTracker, self).make_fixture(request)
class ConfigurationTracker(RetrievalTracker, ModificationTracker):
def make_fixture(self, request):
"""Make a pytest fixture for this tracker
Make sure that the state of entry in the end is the same
it was in the begining.
"""
retrieve = self.make_retrieve_command(all=True)
res = retrieve()['result']
original_state = {}
for k, v in res.items():
if k in self.update_keys:
original_state[k] = v[0] if k in self.singlevalue_keys else v
def revert():
update = self.make_update_command(original_state)
try:
update()
except errors.EmptyModlist:
# ignore no change
pass
request.addfinalizer(revert)
return super(ConfigurationTracker, self).make_fixture(request)
class Tracker(RetrievalTracker, SearchTracker, ModificationTracker, class Tracker(RetrievalTracker, SearchTracker, ModificationTracker,
CreationTracker): CreationTracker):
"""Wraps and tracks modifications to a plugin LDAP entry object """Wraps and tracks modifications to a plugin LDAP entry object