def test_add_user_role_already_exists(self):
        """test that we can't assign twice the same role to a user"""
        engine = temp_db.get_temp_db()
        t_db = TransactionDB(engine)
        user_id = t_db.add_user('Pere', 'pwd')
        t_db.add_role('radiologist', 'whatever')

        t_db.add_user_role(user_id, 'radiologist')
        t_db.add_user_role(user_id, 'radiologist')
    def test_add_user_role_ok(self):
        """test that we can assign a role to a user"""
        engine = temp_db.get_temp_db()
        t_db = TransactionDB(engine)
        user_id = t_db.add_user('Pere', 'pwd')
        t_db.add_role('radiologist', 'whatever', 128)

        t_db.add_user_role(user_id, 'radiologist')

        self.assertTrue(self.__user_has_role(t_db, user_id, 'radiologist'))
Exemplo n.º 3
0
    def test_get_user_roles(self):
        engine = temp_db.get_temp_db()
        t_db = TransactionDB(engine)
        user_id = t_db.add_user('Pere', 'pwd')
        t_db.add_role('radiologist', 'whatever', 130)
        t_db.add_role('mediaire_tester', 'whatever', 16)

        t_db.add_user_role(user_id, 'radiologist')
        t_db.add_user_role(user_id, 'mediaire_tester')

        user_service = UserService(t_db)
        role_ids = set([r.role_id for r in \
                        user_service.get_user_roles('Pere')])
        self.assertEqual(2, len(role_ids))
        self.assertTrue('radiologist' in role_ids)
        self.assertTrue('mediaire_tester' in role_ids)
Exemplo n.º 4
0
    def test_get_user_permissions(self):
        engine = temp_db.get_temp_db()
        t_db = TransactionDB(engine)
        user_id = t_db.add_user('Pere', 'pwd')
        t_db.add_role('radiologist', 'whatever', 130)
        t_db.add_role('mediaire_tester', 'whatever', 16)

        t_db.add_user_role(user_id, 'radiologist')
        t_db.add_user_role(user_id, 'mediaire_tester')

        user_service = UserService(t_db)
        p_mask = user_service.get_user_permissions('Pere')
        p_set = UserService.permission_mask_to_id_set(p_mask)

        self.assertEqual(3, len(p_set))
        self.assertTrue(1 in p_set)
        self.assertTrue(4 in p_set)
        self.assertTrue(7 in p_set)
    def test_add_user_role_fail_on_non_existing_user(self):
        engine = temp_db.get_temp_db()
        t_db = TransactionDB(engine)
        t_db.add_role('radiologist', 'whatever')

        t_db.add_user_role(1, 'radiologist')
    def test_add_user_role_fail_on_non_existing_role(self):
        engine = temp_db.get_temp_db()
        t_db = TransactionDB(engine)
        user_id = t_db.add_user('Pere', 'pwd')

        t_db.add_user_role(user_id, 'radiologist')