[Zope3-checkins] CVS: Products3/demo/passwdauth/tests - __init__.py:1.1 passwd:1.1 test_passwdauth.py:1.1

Stephan Richter srichter@cosmos.phy.tufts.edu
Thu, 17 Jul 2003 10:58:21 -0400


Update of /cvs-repository/Products3/demo/passwdauth/tests
In directory cvs.zope.org:/tmp/cvs-serv3769/tests

Added Files:
	__init__.py passwd test_passwdauth.py 
Log Message:
Ahh, I totally forgot to check this in. It is the code that comes with this
recipe: http://dev.zope.org/Zope3/NewPrincipalSourcePlugins


=== Added File Products3/demo/passwdauth/tests/__init__.py ===


=== Added File Products3/demo/passwdauth/tests/passwd ===
foo1:bar1:Foo Bar 1
foo2:bar2:Foo Bar 2


=== Added File Products3/demo/passwdauth/tests/test_passwdauth.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: test_passwdauth.py,v 1.1 2003/07/17 14:58:15 srichter Exp $
"""
import os
from zopeproducts.passwdauth import tests, PasswdPrincipalSource
from zope.exceptions import NotFoundError
from unittest import TestCase, TestSuite, main, makeSuite

class PasswdPrincipalSourceTest(TestCase):

    def setUp(self):
        dir = os.path.split(tests.__file__)[0]
        self.source = PasswdPrincipalSource(
            os.path.join(dir, 'passwd'))

    def test_getPrincipal(self):
        self.assertEqual(self.source.getPrincipal('foo1').password,
                         'bar1')
        self.assertEqual(self.source.getPrincipal('foo2').password,
                         'bar2')
        self.assertRaises(NotFoundError, self.source.getPrincipal,
                          ('foo',))

    def test_getPrincipals(self):
        self.assertEqual(len(self.source.getPrincipals('foo')), 2)
        self.assertEqual(len(self.source.getPrincipals('')), 2)
        self.assertEqual(len(self.source.getPrincipals('2')), 1)

    def test_authenticate(self):
        self.assertEqual(self.source.authenticate('foo1', 'bar1').id,
                         'foo1')
        self.assertEqual(self.source.authenticate('foo1', 'bar'),
                         None)
        self.assertEqual(self.source.authenticate('foo', 'bar'),
                         None)
    
def test_suite():
    return TestSuite((
        makeSuite(PasswdPrincipalSourceTest),
        ))
    
if __name__=='__main__':
    main(defaultTest='test_suite')