Skip to content

Commit

Permalink
fix accept header in test (fixes flask-restful#392)
Browse files Browse the repository at this point in the history
  • Loading branch information
Josh Friend committed Feb 25, 2015
1 parent 231da4b commit a915d9d
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 25 deletions.
17 changes: 17 additions & 0 deletions tests/__init__.py
Original file line number Diff line number Diff line change
@@ -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
33 changes: 9 additions & 24 deletions tests/test_accept.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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:
Expand All @@ -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:
Expand All @@ -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:
Expand All @@ -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:
Expand All @@ -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:
Expand All @@ -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:
Expand All @@ -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,
Expand All @@ -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:
Expand All @@ -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))
Expand All @@ -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):
Expand Down
2 changes: 1 addition & 1 deletion tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'])
Expand Down

0 comments on commit a915d9d

Please sign in to comment.