From a915d9d23bdc29ad9dbaeb9a030e86a51d437d9b Mon Sep 17 00:00:00 2001 From: Josh Friend Date: Wed, 25 Feb 2015 14:39:34 -0500 Subject: [PATCH] fix accept header in test (fixes #392) --- tests/__init__.py | 17 +++++++++++++++++ tests/test_accept.py | 33 +++++++++------------------------ tests/test_api.py | 2 +- 3 files changed, 27 insertions(+), 25 deletions(-) diff --git a/tests/__init__.py b/tests/__init__.py index e69de29b..0364a5fb 100644 --- a/tests/__init__.py +++ b/tests/__init__.py @@ -0,0 +1,17 @@ +#!/usr/bin/env python + +import functools + +from nose import SkipTest + + +def expected_failure(test): + @functools.wraps(test) + def inner(*args, **kwargs): + try: + test(*args, **kwargs) + except Exception: + raise SkipTest + else: + raise AssertionError('Failure expected') + return inner diff --git a/tests/test_accept.py b/tests/test_accept.py index e5651108..7d78118c 100644 --- a/tests/test_accept.py +++ b/tests/test_accept.py @@ -3,20 +3,6 @@ import flask_restful from werkzeug import exceptions from nose.tools import assert_equals -from nose import SkipTest -import functools - - -def expected_failure(test): - @functools.wraps(test) - def inner(*args, **kwargs): - try: - test(*args, **kwargs) - except Exception: - raise SkipTest - else: - raise AssertionError('Failure expected') - return inner class AcceptTestCase(unittest.TestCase): @@ -29,7 +15,7 @@ def get(self): app = Flask(__name__) api = flask_restful.Api(app) - + api.add_resource(Foo, '/') with app.test_client() as client: @@ -46,7 +32,7 @@ def get(self): app = Flask(__name__) api = flask_restful.Api(app, default_mediatype=None) - + api.add_resource(Foo, '/') with app.test_client() as client: @@ -63,7 +49,7 @@ def get(self): app = Flask(__name__) api = flask_restful.Api(app) - + api.add_resource(Foo, '/') with app.test_client() as client: @@ -80,7 +66,7 @@ def get(self): app = Flask(__name__) api = flask_restful.Api(app, default_mediatype=None) - + api.add_resource(Foo, '/') with app.test_client() as client: @@ -103,7 +89,7 @@ def get(self): def text_rep(data, status_code, headers=None): resp = app.make_response((str(data), status_code, headers)) return resp - + api.add_resource(Foo, '/') with app.test_client() as client: @@ -126,7 +112,7 @@ def get(self): def text_rep(data, status_code, headers=None): resp = app.make_response((str(data), status_code, headers)) return resp - + api.add_resource(Foo, '/') with app.test_client() as client: @@ -135,7 +121,6 @@ def text_rep(data, status_code, headers=None): assert_equals(res.content_type, 'text/plain') - @expected_failure def test_accept_no_default_match_q0_not_acceptable(self): """ q=0 should be considered NotAcceptable, @@ -148,7 +133,7 @@ def get(self): app = Flask(__name__) api = flask_restful.Api(app, default_mediatype=None) - + api.add_resource(Foo, '/') with app.test_client() as client: @@ -163,7 +148,7 @@ def get(self): app = Flask(__name__) api = flask_restful.Api(app, default_mediatype=None) - + @api.representation('text/plain') def text_rep(data, status_code, headers=None): resp = app.make_response((str(data), status_code, headers)) @@ -184,7 +169,7 @@ def get(self): app = Flask(__name__) api = flask_restful.Api(app, default_mediatype=None) - + @api.representation('text/html') @api.representation('text/plain') def text_rep(data, status_code, headers=None): diff --git a/tests/test_api.py b/tests/test_api.py index 2adebf4d..e9e3b5d0 100644 --- a/tests/test_api.py +++ b/tests/test_api.py @@ -519,7 +519,7 @@ def test_media_types_q(self): api = flask_restful.Api(app) with app.test_request_context("/foo", headers={ - 'Accept': 'application/json; q=1; application/xml; q=.5' + 'Accept': 'application/json; q=1, application/xml; q=.5' }): self.assertEquals(api.mediatypes(), ['application/json', 'application/xml'])