def testAnonymousSession(self):
     ## Create a new session
     session = AnonymousSession(self.cfg)
     ## Fetch an existing session
     session_key = session.getKey()
     session = AnonymousSession(self.cfg, session_key)
     self.assertEqual(session.getKey(), session_key)
     ## Creation should fail if missing
     shutil.rmtree(session.getDir())
     self.assertRaises(MobyleError, AnonymousSession, self.cfg, session_key)
     ## Creation should fail if disabled
     self.cfg._anonymous_session = "no"
     self.assertRaises(MobyleError, AnonymousSession, self.cfg)
 def getAnonymousSession( self , key = None ):
     """
     @return: an anonymous session. If key is None create a new anonymous session
     @rtype: Session object
     @param key: the key to identify a anonymous session
     @type key: string
     @raise SessionError: if key is specified and doesn't match any session.
     """
     anonymousSessionAllowed = self.cfg.anonymousSession()
     if anonymousSessionAllowed== 'no':
         self.log.error("SessionFactory/can't create anonymous session ANONYMOUS_SESSION is set to \"no\" in Local/Config/Config.py")          
         raise SessionError , "can't create anonymous session: permission denied"
     try:
         session = self.__sessions[ key ]
     except KeyError: 
         if key :
             sessionDir = self.__getSessionDir( key )
             
             if os.path.exists( sessionDir ):
                 self.log.debug( "SessionFactory.getAnonymousSession( key= %s )/ the dir exist I 'll return this session" % key)
                 session = AnonymousSession( self.cfg , key )
             else: 
                 self.log.error( "can't retrieve anonymous session, the Key: %s doesn't match with any Session" % key )
                 raise SessionError , "wrong Key: %s" % key
                
         else: #new session
             session = AnonymousSession( self.cfg )
             self.log.debug( "SessionFactory.getAnonymousSession( key= %s ) / a new anonymous has been created . I 'll return this session" % key)
             
         self.__sessions[session.getKey()] = session  
         
     self.log.debug( "SessionFactory.getAnonymousSession( key= %s ) I return this anonymous session :key=" + str( session.getKey() )) 
     return session