Example #1
0
    def test_dao_revoke_admin_role_to_myself(self):
        dao = AdminDAO()

        data = dict(user_id=1)

        dao_result = dao.revoke_admin_user(1, data)

        self.assertEqual((messages.USER_CANNOT_REVOKE_ADMIN_STATUS, 403), dao_result)
Example #2
0
    def test_dao_revoke_admin_role_to_non_existing_user(self):

        dao = AdminDAO()

        data = dict(user_id=123)

        dao_result = dao.revoke_admin_user(1, data)

        self.assertEqual((messages.USER_DOES_NOT_EXIST, 404), dao_result)
Example #3
0
    def post(cls):
        """
        Revoke admin status from another User Admin.

        An existing admin can use this endpoint to revoke admin status of another user.
        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.revoke_admin_user(user.id, data)

        else:
            return messages.USER_REVOKE_NOT_ADMIN, HTTPStatus.FORBIDDEN
Example #4
0
    def test_dao_revoke_admin_role_to_valid_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.revoke_admin_user(1, data)

        user = UserModel.query.filter_by(id=2).first()
        self.assertFalse(user.is_admin)
Example #5
0
    def test_dao_revoke_admin_role_to_non_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)

        data = dict(user_id=2)

        dao_result = dao.revoke_admin_user(1, data)

        self.assertEqual((messages.USER_IS_NOT_AN_ADMIN, 400), dao_result)