[Zope-Checkins] CVS: Zope3/lib/python/Zope/Server/Authentication/tests - __init__.py:1.1.2.1 testDictionaryAuthentication.py:1.1.2.1 testSimpleUser.py:1.1.2.1

Stephan Richter srichter@cbu.edu
Tue, 2 Apr 2002 10:35:23 -0500


Update of /cvs-repository/Zope3/lib/python/Zope/Server/Authentication/tests
In directory cvs.zope.org:/tmp/cvs-serv15879/Authentication/tests

Added Files:
      Tag: Zope3-Server-Branch
	__init__.py testDictionaryAuthentication.py testSimpleUser.py 
Log Message:
Added a most trivial Authentication mechanism for two reasons:

1. Allow us easy testing of the server framework.
2. Support for non-Zope authentication, so that the servers can be used
   independently of Zope.


=== Added File Zope3/lib/python/Zope/Server/Authentication/tests/__init__.py ===
##############################################################################
#
# Copyright (c) 2001, 2002 Zope Corporation and Contributors.
# All Rights Reserved.
# 
# This software is subject to the provisions of the Zope Public License,
# Version 2.0 (ZPL).  A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE.
# 
##############################################################################
"""

$Id: __init__.py,v 1.1.2.1 2002/04/02 15:35:22 srichter Exp $
"""


=== Added File Zope3/lib/python/Zope/Server/Authentication/tests/testDictionaryAuthentication.py ===
##############################################################################
#
# Copyright (c) 2001, 2002 Zope Corporation and Contributors.
# All Rights Reserved.
# 
# This software is subject to the provisions of the Zope Public License,
# Version 2.0 (ZPL).  A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE.
# 
##############################################################################
"""

$Id: testDictionaryAuthentication.py,v 1.1.2.1 2002/04/02 15:35:22 srichter Exp $
"""


import unittest
from Interface.Verify import verifyClass
from Zope.Server.Authentication.IAuthentication import IAuthentication 
from Zope.Server.Authentication.DictionaryAuthentication import \
     DictionaryAuthentication as DictAuth
from Zope.Server.Authentication.SimpleUser import SimpleUser, AnonymousUser

class Test( unittest.TestCase ):

    def setUp(self):
        self.auth = DictAuth({'foo': 'bar',
                              'blah': 'plah',
                              'stupid': 'nonesense'})


    def testAuthenticationUsers(self):
        self.assertEqual(self.auth.user_class, SimpleUser)
        self.assertEqual(self.auth.anonymous_user, AnonymousUser)


    def testAuthenticate(self):
        self.assertEqual(self.auth.authenticate('foo', 'bar').username,
                         SimpleUser('foo').username)
        self.assertEqual(self.auth.authenticate('blah', ''),
                         AnonymousUser)
        self.assertEqual(self.auth.authenticate('foo', 'nonesense'),
                         AnonymousUser)        


    def testInterface(self):
        self.failUnless(IAuthentication.isImplementedByInstancesOf(DictAuth))
        self.failUnless(verifyClass(IAuthentication, DictAuth))        
        


def test_suite():
    loader = unittest.TestLoader()
    return loader.loadTestsFromTestCase( Test )

if __name__=='__main__':
    unittest.TextTestRunner().run( test_suite() )


=== Added File Zope3/lib/python/Zope/Server/Authentication/tests/testSimpleUser.py ===
##############################################################################
#
# Copyright (c) 2001, 2002 Zope Corporation and Contributors.
# All Rights Reserved.
# 
# This software is subject to the provisions of the Zope Public License,
# Version 2.0 (ZPL).  A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE.
# 
##############################################################################
"""

$Id: testSimpleUser.py,v 1.1.2.1 2002/04/02 15:35:22 srichter Exp $
"""

import unittest
from Interface.Verify import verifyClass
from Zope.Server.Authentication.IUser import IUser 
from Zope.Server.Authentication.SimpleUser import SimpleUser, AnonymousUser

class Test( unittest.TestCase ):


    def testAnonymousUser(self):
        self.assertEqual(AnonymousUser.username, 'anonymous')


    def testSimpleUser(self):
        simple_user = SimpleUser('simple')
        self.assertEqual(simple_user.username, 'simple')


    def testInterface(self):
        self.failUnless(IUser.isImplementedByInstancesOf(SimpleUser))
        self.failUnless(verifyClass(IUser, SimpleUser))        
        


def test_suite():
    loader = unittest.TestLoader()
    return loader.loadTestsFromTestCase( Test )

if __name__=='__main__':
    unittest.TextTestRunner().run( test_suite() )