def test_add_user_already_exists(self):
     """test that we can't add duplicate users by user name"""
     engine = temp_db.get_temp_db()
     t_db = TransactionDB(engine)
     user_id = t_db.add_user('Pere', 'pwd')
     self.assertTrue(user_id >= 0)
     t_db.add_user('Pere', 'pwd')
    def test_user_preferences_invalid_keys(self):
        """test that upon providing an invalid preference key for the
        preferences system, a TransactionDBException is thrown"""
        engine = temp_db.get_temp_db()
        t_db = TransactionDB(engine)
        user_id_1 = t_db.add_user('Pere1', 'pwd')

        t_db.set_user_preferences(user_id_1, {'foo': 'bar'})
 def test_add_user_ok(self):
     """test that we can add User entity"""
     engine = temp_db.get_temp_db()
     t_db = TransactionDB(engine)
     user_id = t_db.add_user('Pere', 'pwd')
     user = t_db.session.query(User).get(user_id)
     self.assertEqual('Pere', user.name)
     self.assertTrue(user.hashed_password)
    def test_revoke_user_role_didnt_exist(self):
        """test that an Exception is thrown if we want to revoke an
        already revoked role from 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.revoke_user_role(user_id, 'radiologist')
    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'))
 def test_remove_user_ok(self):
     """test that we can remove an existing user from the database"""
     engine = temp_db.get_temp_db()
     t_db = TransactionDB(engine)
     user_id = t_db.add_user('Pere', 'pwd')
     user = t_db.session.query(User).get(user_id)
     self.assertEqual('Pere', user.name)
     t_db.remove_user(user_id)
     user = t_db.session.query(User).get(user_id)
     self.assertFalse(user)
Пример #8
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)
Пример #9
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_transaction_with_user_id(self):
        engine = temp_db.get_temp_db()
        tr_1 = self._get_test_transaction()

        t_db = TransactionDB(engine)
        user_id = t_db.add_user('Pere', 'pwd')
        t_id = t_db.create_transaction(tr_1, user_id)

        t = t_db.get_transaction(t_id)
        self.assertNotEqual(None, t)

        ut = t_db.session.query(UserTransaction) \
            .filter_by(transaction_id=t.transaction_id) \
            .filter_by(user_id=user_id).first()

        self.assertEqual(ut.user_id, user_id)
        self.assertEqual(t.transaction_id, ut.transaction_id)

        t_db.close()
    def test_user_preferences(self):
        """test that the preferences saving and retrieving system works"""
        engine = temp_db.get_temp_db()
        t_db = TransactionDB(engine)
        user_id_1 = t_db.add_user('Pere1', 'pwd')
        user_id_2 = t_db.add_user('Pere2', 'pwd')

        self.assertTrue(t_db.get_user_preferences(user_id_1) is None)
        self.assertTrue(t_db.get_user_preferences(user_id_2) is None)

        preferences = {'report_language': 'en'}
        t_db.set_user_preferences(user_id_1, preferences)
        preferences = {'report_language': 'de'}
        t_db.set_user_preferences(user_id_2, preferences)

        prefs = t_db.get_user_preferences(user_id_1)
        self.assertEqual(user_id_1, prefs['user_id'])
        self.assertEqual('en', prefs['report_language'])

        prefs = t_db.get_user_preferences(user_id_2)
        self.assertEqual(user_id_2, prefs['user_id'])
        self.assertEqual('de', prefs['report_language'])
    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')