Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add test case for issue #825 #826

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

billyrrr
Copy link
Contributor

No description provided.

@wangxue666666
Copy link

    def test_abort_with_jsonify(self):

        class HelloBombAbort(flask_restful.Resource):
            def get(self):
                flask_restful.abort(
                    flask.jsonify(dict(code=401, msg="error message 1"))
                    # I know you should use Response if you want to modify the HTTP status code
                    # flask.Response(response=json.dumps(dict(code=401, msg="error message 1")), status=400)
                )
                # raise flask_restful.HTTPException(response=flask.jsonify(dict(code=401, msg="error message 1")))

        app = Flask(__name__)
        api = flask_restful.Api(app)
        api.add_resource(HelloBombAbort, '/bomb')

        app = app.test_client()
        resp = app.get('/bomb')

        resp_dict = json.loads(resp.data.decode())
        self.assertEquals(resp.status_code, 200)
        self.assertDictEqual(resp_dict,
                             {'code': 401, 'msg': 'error message 1'})
        self.assertEquals(resp.status_code, 400)

Hi, I think you're confusing the code in flask.jsonify(dict(code=401, msg="error message 1")) with HTTP status code,jsonify code is just a parameter. In 0.3.6 self.assertDictEqual is pass-test. but in 0.3.7 self.assertDictEqual is fail the test It just returns {'message': None}.Did you modify the operation to catch HTTP exceptions in version 0.3.7?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants