"""
$URL: svn+ssh://svn.mems-exchange.org/repos/trunk/dulcinea/lib/test/utest_user.py $
$Id: utest_user.py 28600 2006-08-17 14:13:32Z rmasse $
"""
from dulcinea.user import get_realm, DulcineaUser as User
from sancho.utest import raises
from dulcinea.common import CommonTest

class DulcineaUserTest (CommonTest):

    def check_init (self):
        raises(TypeError, User, '!@#$%^')
        User('amk')
        u = User(None)
        u.set_id('foo')
        raises(AssertionError, User('foo').set_id, 'foo')
        raises(TypeError, User(None).set_id, '!foo')
        u = User(None)
        assert u.id == None
        u.set_id('foo')
        assert u.id == "foo"
        raises(AssertionError, u.set_id, 'bar')

    def check_password (self):
        user = User('foo')
        user.set_password("biteme")
        assert user.has_password("biteme")
        assert not user.has_password("dontbiteme")
        assert not user.has_password("biteme", realm='bogus')
        assert user.has_password("biteme", realm=get_realm())
        password1 = user.generate_password()
        assert user.has_password(password1)
        password2 = user.generate_password()
        assert user.has_password(password2)
        assert password1 != password2


if __name__ == "__main__":
    DulcineaUserTest()
