#!/www/python/bin/python
"""
$URL: svn+ssh://svn.mems-exchange.org/repos/trunk/dulcinea/lib/test/test_user_database.py $
$Id: test_user_database.py 23436 2004-02-05 18:39:13Z dbinger $
"""

from sancho.unittest import TestScenario, parse_args, run_scenarios
from dulcinea.errors import ConflictError
from dulcinea.user import DulcineaUser
from dulcinea.user_database import DulcineaUserDatabase, ContactDatabase

tested_modules = ["dulcinea.user_database"]

class Test(TestScenario):

    def check_user_database(self):
        user1 = DulcineaUser('1')
        user2 = DulcineaUser('2')
        self.test_stmt("self.db = DulcineaUserDatabase()")
        self.test_stmt("self.db.add_user(user1)")
        self.test_val("self.db.get_user_ids()", ['1'])
        self.test_val("self.db.get_users()", [user1])
        self.test_stmt("self.db.add_user(user2)")
        self.test_val("self.db.get_users(sort=True)", [user1, user2])
        self.test_val("self.db.get_user('1')", user1)
        self.test_val("self.db['1']", user1)
        self.test_exc("self.db.add_user(user1)", ConflictError)
        self.test_val("self.db.get_admin()", None)

    def check_contact_database(self):
        self.test_stmt("self.db = ContactDatabase()")
        self.test_val("str(self.db.get_admin())", 'admin')

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