mirror of
https://salsa.debian.org/freeipa-team/freeipa.git
synced 2025-02-25 18:55:28 -06:00
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:
parent
7b015a2e76
commit
3113bfb0cf
@ -131,6 +131,7 @@ class SearchTracker(BaseTracker):
|
||||
|
||||
class ModificationTracker(BaseTracker):
|
||||
update_keys = None
|
||||
singlevalue_keys = None
|
||||
|
||||
def make_update_command(self, updates):
|
||||
"""Make function that modifies the entry using ${CMD}_mod"""
|
||||
@ -313,6 +314,33 @@ class EnableTracker(BaseTracker):
|
||||
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,
|
||||
CreationTracker):
|
||||
"""Wraps and tracks modifications to a plugin LDAP entry object
|
||||
|
Loading…
Reference in New Issue
Block a user