#!/www/python/bin/python

"""$URL: svn+ssh://svn.mems-exchange.org/repos/trunk/dulcinea/lib/test/test_user.py $
$Id: test_user.py 23216 2003-11-21 21:00:24Z dbinger $

Test for dulcinea.user.
"""

from sancho.unittest import TestScenario, parse_args, run_scenarios
from dulcinea.user import DulcineaUser as User

tested_modules = [ "dulcinea.user" ]

class DulcineaUserTest (TestScenario):

    def check_init (self):
        "Check constructor"
        self.test_exc("User('!@#$%^')", ValueError)
        self.test_stmt("User('amk')")
        self.test_stmt("u = User() ; u.set_id('foo')")
        self.test_exc("User('foo').set_id('foo')", AssertionError)
        self.test_exc("u = User() ; u.set_id('!foo')", ValueError)

        u = User()
        self.test_val("u.id", None)
        self.test_stmt("u.set_id('foo')")
        self.test_val("u.id", "foo")
        self.test_exc("u.set_id('bar')", AssertionError)

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


if __name__ == "__main__":
    (scenarios, options) = parse_args()
    run_scenarios(scenarios, options)
