#!/www/python/bin/python

"""$URL: svn+ssh://svn/repos/trunk/dulcinea/lib/test/utest_user.py $
$Id: utest_user.py 25054 2004-09-09 18:04:30Z dbinger $

Test for dulcinea.user.
"""

from sancho.utest import UTest
from dulcinea.user import DulcineaUser as User


class DulcineaUserTest (UTest):

    def check_init (self):
        "Check constructor"
        try:
            User('!@#$%^')
            assert 0
        except ValueError: pass
        User('amk')
        u = User() ; u.set_id('foo')
        try:
            User('foo').set_id('foo')
            assert 0
        except AssertionError: pass
        try:
            u = User() ; u.set_id('!foo')
            assert 0
        except ValueError: pass

        u = User()
        assert u.id == None
        u.set_id('foo')
        assert u.id == "foo"
        try:
            u.set_id('bar')
            assert 0
        except AssertionError: pass

    def check_password (self):
        "Test password-related methods"
        user = User('foo')
        user.set_password("biteme")
        assert user.valid_password("biteme")
        assert not user.valid_password("dontbiteme")
        password1 = user.generate_password()
        assert user.valid_password(password1)
        password2 = user.generate_password()
        assert user.valid_password(password2)
        assert password1 != password2


if __name__ == "__main__":
    DulcineaUserTest()
