Beispiel #1
0
    def test_dao_assign_admin_role_to_admin_user(self):

        dao = AdminDAO()

        user = UserModel(
            name=user1["name"],
            username=user1["username"],
            email=user1["email"],
            password=user1["password"],
            terms_and_conditions_checked=user1["terms_and_conditions_checked"],
        )

        user.save_to_db()

        user = UserModel.query.filter_by(id=2).first()
        self.assertFalse(user.is_admin)
        user.is_admin = True
        user.save_to_db()
        self.assertTrue(user.is_admin)

        data = dict(user_id=2)

        dao_result = dao.assign_new_user(1, data)

        self.assertEqual((messages.USER_IS_ALREADY_AN_ADMIN, 400), dao_result)
Beispiel #2
0
    def test_dao_assign_admin_role_to_non_existing_user(self):

        dao = AdminDAO()

        data = dict(user_id=123)

        dao_result = dao.assign_new_user(1, data)

        self.assertEqual((messages.USER_DOES_NOT_EXIST, 404), dao_result)
Beispiel #3
0
    def test_dao_assign_new_admin_valid_user(self):

        dao = AdminDAO()

        user = UserModel(
            name="Joan",
            username="******",
            email="*****@*****.**",
            password="******",
            terms_and_conditions_checked=True,
        )
        db.session.add(user)
        db.session.commit()

        user = UserModel.query.filter_by(id=2).first()

        self.assertFalse(user.is_admin)

        data = dict(user_id=2)
        dao.assign_new_user(1, data)

        user = UserModel.query.filter_by(id=2).first()
        self.assertTrue(user.is_admin)
Beispiel #4
0
    def post(cls):
        """
        Assigns a User as a new Admin.

        An existing admin can use this endpoint to designate another user as an admin.
        This is done by passing "user_id" of that particular user.
        """
        user_id = get_jwt_identity()
        user = UserDAO.get_user(user_id)
        if user.is_admin:
            data = request.json
            return AdminDAO.assign_new_user(user.id, data)

        else:
            return messages.USER_ASSIGN_NOT_ADMIN, HTTPStatus.FORBIDDEN
Beispiel #5
0
    def test_dao_assign_new_admin_by_normal_user(self):

        dao = AdminDAO()

        user = UserModel(
            name=user1["name"],
            username=user1["username"],
            email=user1["email"],
            password=user1["password"],
            terms_and_conditions_checked=user1["terms_and_conditions_checked"],
        )
        user.is_email_verified = True
        user.save_to_db()

        user = UserModel.query.filter_by(id=2).first()

        self.assertFalse(user.is_admin)

        data = dict(user_id=1)
        dao_result = dao.assign_new_user(2, data)

        self.assertEqual((messages.USER_ASSIGN_NOT_ADMIN, 403), dao_result)