[Checkins] SVN: Products.PluggableAuthService/branches/maurits-login-transform/Products/PluggableAuthService/tests/test_PluggableAuthService.py Add test for PAS.updateLoginName.

Maurits van Rees cvs-admin at zope.org
Tue Jan 15 19:34:55 UTC 2013


Log message for revision 129037:
  Add test for PAS.updateLoginName.
  
  Might want to merge IUpdateLoginNamePlugin into IUserEnumerationPlugin.

Changed:
  U   Products.PluggableAuthService/branches/maurits-login-transform/Products/PluggableAuthService/tests/test_PluggableAuthService.py

-=-
Modified: Products.PluggableAuthService/branches/maurits-login-transform/Products/PluggableAuthService/tests/test_PluggableAuthService.py
===================================================================
--- Products.PluggableAuthService/branches/maurits-login-transform/Products/PluggableAuthService/tests/test_PluggableAuthService.py	2013-01-11 12:55:37 UTC (rev 129036)
+++ Products.PluggableAuthService/branches/maurits-login-transform/Products/PluggableAuthService/tests/test_PluggableAuthService.py	2013-01-15 19:34:54 UTC (rev 129037)
@@ -157,6 +157,18 @@
         self._group_id = group_id
         self.identifier = None
 
+
+class DummyLoginNameUpdater(DummyUserEnumerator):
+
+    def updateUser(self, user_id, login_name):
+        if user_id == self._user_id:
+            self._login = login_name
+
+    def updateAllLoginNames(self, quit_on_first_error=True):
+        # Let's lowercase all login names.
+        self.login = self._login.lower()
+        
+
 class DummyGroupPlugin(DummyPlugin):
 
     def __init__(self, id, groups=()):
@@ -527,6 +539,18 @@
         directlyProvides( cp, IChallengePlugin )
         return cp
 
+    def _makeLoginNameUpdater( self, user_id, login_name ):
+
+        from Products.PluggableAuthService.interfaces.plugins \
+             import IUserEnumerationPlugin
+        from Products.PluggableAuthService.interfaces.plugins \
+             import IUpdateLoginNamePlugin
+
+        updater = DummyLoginNameUpdater( user_id, login_name )
+        directlyProvides( updater, IUserEnumerationPlugin, IUpdateLoginNamePlugin )
+
+        return updater
+
     def test_empty( self ):
 
         zcuf = self._makeOne()
@@ -2423,7 +2447,32 @@
         user3 = zcuf.searchPrincipals( name='FOO' )[0]
         self.assertEqual(user1, user3)
 
+    def test_updateLoginName( self ):
 
+        from Products.PluggableAuthService.interfaces.plugins \
+             import IUserEnumerationPlugin
+        from Products.PluggableAuthService.interfaces.plugins \
+             import IUpdateLoginNamePlugin
+
+        plugins = self._makePlugins()
+        zcuf = self._makeOne( plugins )
+
+        foo = self._makeLoginNameUpdater( user_id='JOE', login_name='Joe' )
+        zcuf._setObject( 'foo', foo )
+
+        plugins = zcuf._getOb( 'plugins' )
+        plugins.activatePlugin( IUserEnumerationPlugin, 'foo' )
+        plugins.activatePlugin( IUpdateLoginNamePlugin, 'foo' )
+
+        self.assertEqual(foo._login, 'Joe')
+        zcuf.updateLoginName('JOE', 'James')
+        self.assertEqual(foo._login, 'James')
+
+        # Try lowercase
+        zcuf.login_transform = 'lower'
+        zcuf.updateLoginName('JOE', 'James')
+        self.assertEqual(foo._login, 'james')
+
     def test_no_challenger(self):
         # make sure that the response's _unauthorized gets propogated
         # if no challengers exist (or have fired)



More information about the checkins mailing list