Hi,

I'm sending additional patch for stageuser plugin tests. It applies on top of 0002.3 patch sent earlier and reflects the change of 'stageuser-add --from-delete' command to 'user-stage'.


Lenka
From 03521e0683eb8a9a81d3acd97b08e2402affd270 Mon Sep 17 00:00:00 2001
From: Lenka Doudova <ldoud...@redhat.com>
Date: Wed, 19 Aug 2015 15:24:23 +0200
Subject: [PATCH] Updated automated test for stageuser plugin

Updated test - this version reflects the change of command 'stageuser-add --from-delete' to 'user-stage'.
Ticket: https://fedorahosted.org/freeipa/ticket/3813
Test plan: http://www.freeipa.org/page/V4/User_Life-Cycle_Management/Test_Plan
---
 ipatests/test_xmlrpc/test_stageuser_plugin.py | 42 ++++++++++++++++++++-------
 ipatests/test_xmlrpc/test_user_plugin.py      | 32 +++++++++++++++++++-
 2 files changed, 62 insertions(+), 12 deletions(-)

diff --git a/ipatests/test_xmlrpc/test_stageuser_plugin.py b/ipatests/test_xmlrpc/test_stageuser_plugin.py
index f3024a8f98a7fb4cf40e63b112a0f3946715633f..f0ca5669043daffe3392e3cfc035eadc069596ef 100644
--- a/ipatests/test_xmlrpc/test_stageuser_plugin.py
+++ b/ipatests/test_xmlrpc/test_stageuser_plugin.py
@@ -119,14 +119,13 @@ class StageUserTracker(Tracker):
 
         self.kwargs = kwargs
 
-    def make_create_command(self, options=None, force=None, from_delete=False):
+    def make_create_command(self, options=None, force=None):
         """ Make function that creates a staged user using stageuser-add """
         if options is not None:
             self.kwargs = options
         return self.make_command('stageuser_add', self.uid,
                                  givenname=self.givenname,
-                                 sn=self.sn, from_delete=from_delete,
-                                 **self.kwargs)
+                                 sn=self.sn, **self.kwargs)
 
     def make_delete_command(self):
         """ Make function that deletes a staged user using stageuser-del """
@@ -276,6 +275,13 @@ class StageUserTracker(Tracker):
             result=self.filter_attrs(self.update_keys | set(extra_keys))
         ), result)
 
+    def check_restore_preserved(self, result):
+        assert_deepequal(dict(
+            value=self.uid,
+            summary=u'Staged user account "%s"' % self.uid,
+            result=True,
+        ), result)
+
     def make_fixture_activate(self, request):
         """Make a pytest fixture for a staged user that is to be activated
 
@@ -307,6 +313,9 @@ class StageUserTracker(Tracker):
         self.uid = user.uid
         self.givenname = user.givenname
         self.sn = user.sn
+        self.dn = DN(
+            ('uid', self.uid), api.env.container_stageuser, api.env.basedn)
+        self.attrs[u'dn'] = self.dn
 
 
 @pytest.fixture(scope='class')
@@ -369,6 +378,12 @@ def user6(request):
     return tracker.make_fixture(request)
 
 
+@pytest.fixture(scope='class')
+def user7(request):
+    tracker = UserTracker(u'puser1', u'preserved', u'user')
+    return tracker.make_fixture_restore(request)
+
+
 class TestNonexistentStagedUser(XMLRPC_test):
     def test_retrieve_nonexistent(self, stageduser):
         stageduser.ensure_missing()
@@ -709,22 +724,27 @@ class TestPreserved(XMLRPC_test):
 
         user.delete()
 
-    def test_staged_from_preserved(self, user, stageduser):
-        user.make_preserved_user()
+    def test_staged_from_preserved(self, user7, stageduser):
+        user7.make_preserved_user()
 
         stageduser.ensure_missing()
-        stageduser = StageUserTracker(user.uid, user.givenname, user.sn)
-        stageduser.create_from_preserved(user)
-        command = user.make_create_command(from_delete=True)
+        stageduser = StageUserTracker(user7.uid, user7.givenname, user7.sn)
+        stageduser.create_from_preserved(user7)
+        command = user7.make_stage_command()
         result = command()
-        stageduser.check_create(result)
+        stageduser.check_restore_preserved(result)
+        stageduser.exists = True
 
-        command = user.make_retrieve_command()
+        command = user7.make_retrieve_command()
         with raises_exact(errors.NotFound(
                 reason=u'%s: user not found' % stageduser.uid)):
             command()
+
+        command = stageduser.make_retrieve_command()
+        result = command()
+        stageduser.check_retrieve(result)
+
         stageduser.delete()
-        user.delete()
 
 
 class TestManagers(XMLRPC_test):
diff --git a/ipatests/test_xmlrpc/test_user_plugin.py b/ipatests/test_xmlrpc/test_user_plugin.py
index ec72c3241ea9c075e32d36132d9869d23fd57f22..08f9d1667185d5477cbf49f293196714fd3a0864 100644
--- a/ipatests/test_xmlrpc/test_user_plugin.py
+++ b/ipatests/test_xmlrpc/test_user_plugin.py
@@ -34,7 +34,7 @@ from ipatests.util import (
     assert_equal, assert_not_equal, raises, assert_deepequal)
 from xmlrpc_test import (
     XMLRPC_test, Declarative, fuzzy_digits, fuzzy_uuid, fuzzy_password,
-    fuzzy_string, fuzzy_dergeneralizedtime, add_sid, add_oc)
+    fuzzy_string, fuzzy_dergeneralizedtime, add_sid, add_oc, raises_exact)
 from ipapython.dn import DN
 from ipatests.test_xmlrpc.ldaptracker import Tracker
 
@@ -1739,6 +1739,11 @@ class UserTracker(Tracker):
         """ Make function that enables user using user-enable """
         return self.make_command('user_enable', self.uid)
 
+    def make_stage_command(self):
+	""" Make function that restores preserved user by moving it to
+            staged container """
+        return self.make_command('user_stage', self.uid)
+
     def track_create(self):
         """ Update expected state for user creation """
         self.attrs = dict(
@@ -1945,3 +1950,28 @@ class UserTracker(Tracker):
         if (u'memberof_group' not in result[u'result'] or
                 result[u'result'][u'memberof_group'] != (u'ipausers',)):
             assert False
+
+    def make_fixture_restore(self, request):
+        """Make a pytest fixture for a preserved user that is to be moved to
+        staged area.
+
+        The fixture ensures the plugin entry does not exist before
+        and after the tests that use it. It takes into account
+        that the preserved user no longer exists after restoring it,
+        therefore the fixture verifies after the tests
+        that the preserved user doesn't exist instead of deleting it.
+        """
+        del_command = self.make_delete_command()
+        try:
+            del_command()
+        except errors.NotFound:
+            pass
+
+        def finish():
+            with raises_exact(errors.NotFound(
+                    reason=u'no such entry')):
+                del_command()
+
+        request.addfinalizer(finish)
+
+        return self
-- 
2.4.3

-- 
Manage your subscription for the Freeipa-devel mailing list:
https://www.redhat.com/mailman/listinfo/freeipa-devel
Contribute to FreeIPA: http://www.freeipa.org/page/Contribute/Code

Reply via email to