diff --git a/docs/_themes/flask_theme_support.py b/docs/_themes/flask_theme_support.py
index 33f4744..5cd088b 100755
--- a/docs/_themes/flask_theme_support.py
+++ b/docs/_themes/flask_theme_support.py
@@ -1,3 +1,4 @@
+# flake8: noqa
# flasky extensions. flasky pygments style based on tango style
from pygments.style import Style
from pygments.token import Keyword, Name, Comment, String, Error, \
diff --git a/docs/conf.py b/docs/conf.py
index 524d58b..45dfd50 100644
--- a/docs/conf.py
+++ b/docs/conf.py
@@ -1,4 +1,5 @@
# -*- coding: utf-8 -*-
+# flake8: noqa
#
# Flask Classy documentation build configuration file, created by
# sphinx-quickstart on Tue Oct 30 13:14:07 2012.
diff --git a/flask_classful.py b/flask_classful.py
index 7ac9bc7..8ecb8c4 100644
--- a/flask_classful.py
+++ b/flask_classful.py
@@ -9,9 +9,6 @@
:license: BSD, see LICENSE for more details.
"""
-__version__ = "0.14.0-dev0"
-
-
import sys
import functools
import inspect
@@ -23,6 +20,8 @@
_py2 = sys.version_info[0] == 2
+__version__ = "0.14.0-dev0"
+
def route(rule, **options):
"""A decorator that is used to define custom routes for methods in
@@ -34,7 +33,7 @@ def decorator(f):
# Put the rule cache on the method itself instead of globally
if not hasattr(f, '_rule_cache') or f._rule_cache is None:
f._rule_cache = {f.__name__: [(rule, options)]}
- elif not f.__name__ in f._rule_cache:
+ elif f.__name__ not in f._rule_cache:
f._rule_cache[f.__name__] = [(rule, options)]
else:
f._rule_cache[f.__name__].append((rule, options))
@@ -54,7 +53,9 @@ class FlaskView(object):
route_base = None
route_prefix = None
trailing_slash = True
- method_dashified = False # TODO(hoatle): make True as default instead, this is not a compatible change
+ # TODO(hoatle): make method_dashified=True as default instead,
+ # this is not a compatible change
+ method_dashified = False
special_methods = {
"get": ["GET"],
"put": ["PUT"],
@@ -91,14 +92,16 @@ def register(cls, app, route_base=None, subdomain=None, route_prefix=None,
:param route_prefix: A prefix to be applied to all routes registered
for this class. Precedes route_base. Overrides
the class' route_prefix if it has been set.
- :param trailing_slash: An option to put trailing slashes at the end of routes
- without parameters.
- :param method_dashified: An option to dashify method name from some_route to /some-route/
- route instead of default /some_route/
+ :param trailing_slash: An option to put trailing slashes at the end of
+ routes without parameters.
+ :param method_dashified: An option to dashify method name from
+ some_route to /some-route/ route instead of
+ default /some_route/
"""
if cls is FlaskView:
- raise TypeError("cls must be a subclass of FlaskView, not FlaskView itself")
+ raise TypeError(
+ "cls must be a subclass of FlaskView, not FlaskView itself")
if route_base:
cls.orig_route_base = cls.route_base
@@ -144,7 +147,9 @@ def register(cls, app, route_base=None, subdomain=None, route_prefix=None,
else:
endpoint = "{0!s}_{1:d}".format(route_name, idx)
- app.add_url_rule(rule, endpoint, proxy, subdomain=subdomain, **options)
+ app.add_url_rule(
+ rule, endpoint, proxy,
+ subdomain=subdomain, **options)
elif name in cls.special_methods:
methods = cls.special_methods[name]
@@ -152,7 +157,9 @@ def register(cls, app, route_base=None, subdomain=None, route_prefix=None,
rule = cls.build_rule("/", value)
if not cls.trailing_slash and rule != '/':
rule = rule.rstrip("/")
- app.add_url_rule(rule, route_name, proxy, methods=methods, subdomain=subdomain)
+ app.add_url_rule(
+ rule, route_name, proxy,
+ methods=methods, subdomain=subdomain)
else:
if cls.method_dashified is True:
@@ -161,9 +168,12 @@ def register(cls, app, route_base=None, subdomain=None, route_prefix=None,
if not cls.trailing_slash:
route_str = route_str.rstrip('/')
rule = cls.build_rule(route_str, value)
- app.add_url_rule(rule, route_name, proxy, subdomain=subdomain)
+ app.add_url_rule(
+ rule, route_name, proxy, subdomain=subdomain)
except DecoratorCompatibilityError:
- raise DecoratorCompatibilityError("Incompatible decorator detected on {0!s} in class {1!s}".format(name, cls.__name__))
+ raise DecoratorCompatibilityError(
+ "Incompatible decorator detected on {0!s} in class {1!s}"
+ .format(name, cls.__name__))
if hasattr(cls, "orig_route_base"):
cls.route_base = cls.orig_route_base
@@ -203,7 +213,8 @@ def make_proxy_method(cls, name):
i = cls()
view = getattr(i, name)
- # Since the view is a bound instance method, first make it an actual function
+ # Since the view is a bound instance method,
+ # first make it an actual function
# So function attributes work correctly
def make_func(fn):
@functools.wraps(fn)
@@ -246,23 +257,26 @@ def proxy(**forgettable_view_args):
if not isinstance(response, ResponseBase):
if not cls.representations:
- # No representations defined, then the default is to just output
- # what the view function returned as a response
+ # No representations defined, then the default is to just
+ # output what the view function returned as a response
response = make_response(response, code, headers)
else:
- # Return the representation that best matches the representations
- # in the Accept header
+ # Return the representation that best matches the
+ # representations in the Accept header
resp_representation = request.accept_mimetypes.best_match(
cls.representations.keys())
if resp_representation:
- response = cls.representations[resp_representation](response, code, headers)
+ response = cls.representations[
+ resp_representation
+ ](response, code, headers)
else:
- # Nothing adequate found, make the response any one of the representations
- # defined
+ # Nothing adequate found, make the response any one of
+ # the representations defined
# TODO(hoatle): or just make_response?
- response = cls.representations[list(cls.representations.keys())[0]](
- response, code, headers)
+ response = cls.representations[
+ list(cls.representations.keys())[0]
+ ](response, code, headers)
# If the header or code is set, regenerate the response
elif any(x is not None for x in (code, headers)):
@@ -280,7 +294,6 @@ def proxy(**forgettable_view_args):
return response
-
return proxy
@classmethod
@@ -313,12 +326,12 @@ def build_rule(cls, rule, method=None):
if method:
argspec = get_true_argspec(method)
args = argspec[0]
- query_params = argspec[3] # All default args that should be ignored
+ query_params = argspec[3] # All default args should be ignored
annotations = getattr(argspec, 'annotations', {})
for i, arg in enumerate(args):
if arg not in ignored_rule_args:
if not query_params or len(args) - i > len(query_params):
- # This is not optional param, so it's not query argument
+ # This isn't optional param, so it's not query argument
rule_part = "<{0!s}>".format(arg)
if not _py2:
# in py3, try to determine url variable converters
@@ -330,7 +343,6 @@ def build_rule(cls, rule, method=None):
result = "/{0!s}".format("/".join(rule_parts))
return re.sub(r'(/)\1+', r'\1', result)
-
@classmethod
def get_route_base(cls):
"""Returns the route base to use for the current class."""
@@ -354,7 +366,6 @@ def default_route_base(cls):
return route_base
-
@classmethod
def build_route_name(cls, method_name):
"""Creates a unique route name based on the combination of the class
@@ -367,11 +378,12 @@ def build_route_name(cls, method_name):
def _dashify_uppercase(name):
"""convert somethingWithUppercase into something-with-uppercase"""
- first_cap_re = re.compile('(.)([A-Z][a-z]+)') # better to define this once
+ first_cap_re = re.compile('(.)([A-Z][a-z]+)') # better to define this once
all_cap_re = re.compile('([a-z0-9])([A-Z])')
s1 = first_cap_re.sub(r'\1-\2', name)
return all_cap_re.sub(r'\1-\2', s1).lower()
+
def _dashify_underscore(name):
"""convert something_with_underscore into something-with-underscore"""
return '-'.join(re.split('_', name))
@@ -385,14 +397,21 @@ def get_interesting_members(base_class, cls):
all_members = inspect.getmembers(cls, predicate=predicate)
return [member for member in all_members
if not member[0] in base_members
- and ((hasattr(member[1], "__self__") and not member[1].__self__ in inspect.getmro(cls)) if _py2 else True)
+ and (
+ (hasattr(member[1], "__self__")
+ and not member[1].__self__ in inspect.getmro(cls))
+ if _py2 else True
+ )
and not member[0].startswith("_")
and not member[0].startswith("before_")
and not member[0].startswith("after_")]
def get_true_argspec(method):
- """Drills through layers of decorators attempting to locate the actual argspec for the method."""
+ """
+ Drills through layers of decorators attempting to locate the actual argspec
+ for the method.
+ """
try:
argspec = inspect.getargspec(method)
@@ -412,8 +431,8 @@ def get_true_argspec(method):
inner_method = cell.cell_contents
if inner_method is method:
continue
- if not inspect.isfunction(inner_method) \
- and not inspect.ismethod(inner_method):
+ if not inspect.isfunction(inner_method)\
+ and not inspect.ismethod(inner_method):
continue
true_argspec = get_true_argspec(inner_method)
if true_argspec:
diff --git a/setup.py b/setup.py
index 2d2443e..edb3b0d 100644
--- a/setup.py
+++ b/setup.py
@@ -6,7 +6,7 @@
"""
import os
import re
-from setuptools import setup, find_packages
+from setuptools import setup
def get_file(*parts):
diff --git a/test_classful/test_blueprints.py b/test_classful/test_blueprints.py
index fe9c136..ea6d156 100644
--- a/test_classful/test_blueprints.py
+++ b/test_classful/test_blueprints.py
@@ -2,7 +2,7 @@
from flask import Flask, Blueprint
from .view_classes import BasicView, IndexView, JSONifyTestView
-from nose.tools import *
+from nose.tools import eq_
app = Flask("blueprints")
bp = Blueprint("bptest", "bptest")
@@ -13,42 +13,52 @@
client = app.test_client()
+
def test_bp_index():
resp = client.get("/basic/")
eq_(b"Index", resp.data)
+
def test_bp_get():
resp = client.get("/basic/1234")
eq_(b"Get 1234", resp.data)
+
def test_bp_put():
resp = client.put("/basic/1234")
eq_(b"Put 1234", resp.data)
+
def test_bp_patch():
resp = client.patch("/basic/1234")
eq_(b"Patch 1234", resp.data)
+
def test_bp_post():
resp = client.post("/basic/")
eq_(b"Post", resp.data)
+
def test_bp_delete():
resp = client.delete("/basic/1234")
eq_(b"Delete 1234", resp.data)
+
def test_bp_custom_method():
resp = client.get("/basic/custom_method/")
eq_(b"Custom Method", resp.data)
+
def test_bp_custom_method_with_params():
resp = client.get("/basic/custom_method_with_params/1234/abcd")
eq_(b"Custom Method 1234 abcd", resp.data)
+
def test_bp_routed_method():
resp = client.get("/basic/routed/")
eq_(b"Routed Method", resp.data)
+
def test_bp_multi_routed_method():
resp = client.get("/basic/route1/")
eq_(b"Multi Routed Method", resp.data)
@@ -56,18 +66,22 @@ def test_bp_multi_routed_method():
resp = client.get("/basic/route2/")
eq_(b"Multi Routed Method", resp.data)
+
def test_bp_no_slash():
resp = client.get("/basic/noslash")
eq_(b"No Slash Method", resp.data)
+
def test_bp_index_view_index():
resp = client.get("/")
eq_(b"Index", resp.data)
+
def test_bp_custom_http_method():
resp = client.post("/basic/route3/")
eq_(b"Custom HTTP Method", resp.data)
+
def test_bp_url_prefix():
foo = Blueprint('foo', __name__)
BasicView.register(foo, route_base="/")
diff --git a/test_classful/test_bp_subdomains.py b/test_classful/test_bp_subdomains.py
index 040ab0b..9331dc0 100644
--- a/test_classful/test_bp_subdomains.py
+++ b/test_classful/test_bp_subdomains.py
@@ -1,6 +1,6 @@
from flask import Flask, Blueprint
from .view_classes import BasicView, SubdomainAttributeView, SubdomainRouteView
-from nose.tools import *
+from nose.tools import eq_
app = Flask("blueprints")
app.config["SERVER_NAME"] = "test.test"
@@ -18,21 +18,23 @@
client = app.test_client()
+
def test_bp_attr_subdomain():
- resp = client.get("/subdomain-attribute/", base_url="http://sub1.test.test")
+ resp = client.get(
+ "/subdomain-attribute/", base_url="http://sub1.test.test")
eq_(b"Index", resp.data)
+
def test_bp_route_subdomain():
resp = client.get("/subdomain-route/", base_url="http://sub2.test.test")
eq_(b"Index", resp.data)
+
def test_bp_register_subdomain():
resp = client.get("/basic/", base_url="http://sub3.test.test")
eq_(b"Index", resp.data)
+
def test_bp_bp_subdomain():
resp = client.get("/basic/", base_url="http://sub4.test.test")
eq_(b"Index", resp.data)
-
-
-
diff --git a/test_classful/test_common.py b/test_classful/test_common.py
index 6d560b1..79a06c5 100644
--- a/test_classful/test_common.py
+++ b/test_classful/test_common.py
@@ -1,6 +1,6 @@
-from flask import Flask, url_for
+from flask import Flask
from .view_classes import BasicView, IndexView
-from nose.tools import *
+from nose.tools import eq_
app = Flask("common")
BasicView.register(app)
@@ -8,45 +8,55 @@
client = app.test_client()
+
def test_index():
resp = client.get("/basic/")
eq_(b"Index", resp.data)
+
def test_get():
resp = client.get("/basic/1234")
eq_(resp.status_code, 404)
eq_(b"Get 1234", resp.data)
+
def test_put():
resp = client.put("/basic/1234")
eq_(resp.status_code, 403)
eq_(resp.headers['say'], 'hello')
eq_(b"Put 1234", resp.data)
+
def test_patch():
resp = client.patch("/basic/1234")
eq_(b"Patch 1234", resp.data)
+
def test_post():
resp = client.post("/basic/")
eq_(b"Post", resp.data)
+
def test_delete():
resp = client.delete("/basic/1234")
eq_(b"Delete 1234", resp.data)
+
def test_custom_method():
resp = client.get("/basic/custom_method/")
eq_(b"Custom Method", resp.data)
+
def test_custom_method_with_params():
resp = client.get("/basic/custom_method_with_params/1234/abcd")
eq_(b"Custom Method 1234 abcd", resp.data)
+
def test_routed_method():
resp = client.get("/basic/routed/")
eq_(b"Routed Method", resp.data)
+
def test_multi_routed_method():
resp = client.get("/basic/route1/")
eq_(b"Multi Routed Method", resp.data)
@@ -54,27 +64,22 @@ def test_multi_routed_method():
resp = client.get("/basic/route2/")
eq_(b"Multi Routed Method", resp.data)
+
def test_no_slash():
resp = client.get("/basic/noslash")
eq_(b"No Slash Method", resp.data)
+
def test_index_view_index():
resp = client.get("/")
eq_(b"Index", resp.data)
+
def test_custom_http_method():
resp = client.post("/basic/route3/")
eq_(b"Custom HTTP Method", resp.data)
+
def test_docstrings():
proxy_func = app.view_functions["BasicView:index"]
eq_(proxy_func.__doc__, BasicView.index.__doc__)
-
-
-
-
-
-
-
-
-
diff --git a/test_classful/test_decorators.py b/test_classful/test_decorators.py
index 6897a9f..045afa0 100644
--- a/test_classful/test_decorators.py
+++ b/test_classful/test_decorators.py
@@ -1,11 +1,11 @@
-from flask import Flask, url_for
+from flask import Flask
from .view_classes import DecoratedView
from .view_classes import DecoratedBoldListView
from .view_classes import DecoratedBoldItalicsListView
from .view_classes import DecoratedListMemberView
from .view_classes import DecoratedListFunctionAttributesView
from .view_classes import DecoratedListMemberFunctionAttributesView
-from nose.tools import *
+from nose.tools import eq_
app = Flask("decorated")
DecoratedView.register(app)
@@ -131,21 +131,33 @@ def test_decorator_list_member_get():
def test_decorator_list_function_attributes_get():
- """Verify list of decorators with attributes modify all functions in FlaskView"""
+ """
+ Verify list of decorators with attributes modify all functions in FlaskView
+ """
resp = client.get('/decorated_list_function_attributes_view/1234')
eq_(b'Get 1234' in resp.data, True)
eq_(b'Get 1234', resp.data)
- eq_(hasattr(app.view_functions['DecoratedListFunctionAttributesView:get'], 'eggs'), True)
- eq_('scrambled', app.view_functions['DecoratedListFunctionAttributesView:get'].eggs)
+ eq_(hasattr(
+ app.view_functions['DecoratedListFunctionAttributesView:get'],
+ 'eggs'),
+ True)
+ eq_('scrambled',
+ app.view_functions['DecoratedListFunctionAttributesView:get'].eggs)
def test_decorator_list_function_attributes_index():
- """Verify list of decorators with attributes modify all functions in FlaskView"""
+ """
+ Verify list of decorators with attributes modify all functions in FlaskView
+ """
resp = client.get('/decorated_list_function_attributes_view/')
eq_(b'Index' in resp.data, True)
eq_(b'Index', resp.data)
- eq_(hasattr(app.view_functions['DecoratedListFunctionAttributesView:index'], 'eggs'), True)
- eq_('scrambled', app.view_functions['DecoratedListFunctionAttributesView:index'].eggs)
+ eq_(hasattr(
+ app.view_functions['DecoratedListFunctionAttributesView:index'],
+ 'eggs'),
+ True)
+ eq_('scrambled',
+ app.view_functions['DecoratedListFunctionAttributesView:index'].eggs)
def test_decorator_list_member_function_attributes_get():
@@ -153,7 +165,12 @@ def test_decorator_list_member_function_attributes_get():
resp = client.get('/decorated_list_member_function_attributes_view/4321')
eq_(b'Get 4321' in resp.data, True)
eq_(b'Get 4321', resp.data)
- eq_(hasattr(app.view_functions['DecoratedListMemberFunctionAttributesView:get'], 'eggs'), False)
+ eq_(
+ hasattr(
+ app.view_functions[
+ 'DecoratedListMemberFunctionAttributesView:get'
+ ], 'eggs'),
+ False)
def test_decorator_list_member_function_attributes_index():
@@ -161,5 +178,12 @@ def test_decorator_list_member_function_attributes_index():
resp = client.get('/decorated_list_member_function_attributes_view/')
eq_(b'Index' in resp.data, True)
eq_(b'Index', resp.data)
- eq_(hasattr(app.view_functions['DecoratedListMemberFunctionAttributesView:index'], 'eggs'), True)
- eq_('scrambled', app.view_functions['DecoratedListMemberFunctionAttributesView:index'].eggs)
+ eq_(hasattr(
+ app.view_functions[
+ 'DecoratedListMemberFunctionAttributesView:index'
+ ], 'eggs'),
+ True)
+ eq_('scrambled',
+ app.view_functions[
+ 'DecoratedListMemberFunctionAttributesView:index'
+ ].eggs)
diff --git a/test_classful/test_endpoints.py b/test_classful/test_endpoints.py
index b02eecd..1e7b894 100644
--- a/test_classful/test_endpoints.py
+++ b/test_classful/test_endpoints.py
@@ -1,6 +1,6 @@
from flask import Flask, url_for
from .view_classes import BasicView, IndexView, RouteBaseView, VarBaseView
-from nose.tools import *
+from nose.tools import eq_
app = Flask("common")
BasicView.register(app)
@@ -10,31 +10,37 @@
client = app.test_client()
+
def test_index_url():
with app.test_request_context():
url = url_for("IndexView:index")
eq_("/", url)
+
def test_basic_index_url():
with app.test_request_context():
url = url_for("BasicView:index")
eq_("/basic/", url)
+
def test_custom_endpoint_url():
with app.test_request_context():
url = url_for("basic_endpoint")
eq_("/basic/endpoint/", url)
+
def test_custom_route_base():
with app.test_request_context():
url = url_for('RouteBaseView:index')
eq_("/base-routed/", url)
+
def test_variable_route_popped_base():
with app.test_request_context():
url = url_for('VarBaseView:index', route='bar')
eq_('/var-base-route/bar/', url)
+
def test_variable_route_base():
with app.test_request_context():
url = url_for('VarBaseView:with_base_arg', route='bar')
@@ -45,4 +51,3 @@ def test_variable_route_base_with_local_route_var():
client = app.test_client()
resp = client.get('/var-base-route/bar/local/baz')
eq_(resp.data, b"bar baz")
-
diff --git a/test_classful/test_inheritance.py b/test_classful/test_inheritance.py
index 6544161..d64b52b 100644
--- a/test_classful/test_inheritance.py
+++ b/test_classful/test_inheritance.py
@@ -1,6 +1,6 @@
from flask import Flask
from .view_classes import InheritanceView, DecoratedInheritanceView
-from nose.tools import *
+from nose.tools import eq_
app = Flask('inheritance')
InheritanceView.register(app)
diff --git a/test_classful/test_method_dashified.py b/test_classful/test_method_dashified.py
index 4c0a17d..240ce12 100644
--- a/test_classful/test_method_dashified.py
+++ b/test_classful/test_method_dashified.py
@@ -1,6 +1,5 @@
-import json
from flask import Flask
-from flask_classful import FlaskView, route
+from flask_classful import FlaskView
from nose.tools import eq_
@@ -16,6 +15,7 @@ class DashifiedAttributeView(FlaskView):
def another_route(self):
return "another route"
+
class DashifiedAttributeOverrideView(FlaskView):
method_dashified = True
diff --git a/test_classful/test_method_detection.py b/test_classful/test_method_detection.py
index 523fe6c..cdc58b9 100644
--- a/test_classful/test_method_detection.py
+++ b/test_classful/test_method_detection.py
@@ -1,20 +1,27 @@
from flask_classful import get_interesting_members, FlaskView
from .view_classes import VariedMethodsView, SubVariedMethodsView
-from nose.tools import *
+
def test_special_method_detected():
- members = [m[1] for m in get_interesting_members(FlaskView, VariedMethodsView)]
+ members = [m[1] for m
+ in get_interesting_members(FlaskView, VariedMethodsView)]
assert VariedMethodsView.index in members
+
def test_routed_method_detected():
- members = [m[1] for m in get_interesting_members(FlaskView, VariedMethodsView)]
+ members = [m[1] for m
+ in get_interesting_members(FlaskView, VariedMethodsView)]
assert VariedMethodsView.routed_method in members
+
def test_classmethod_ignored():
- members = [m[1] for m in get_interesting_members(FlaskView, VariedMethodsView)]
+ members = [m[1] for m
+ in get_interesting_members(FlaskView, VariedMethodsView)]
assert VariedMethodsView.class_method not in members
+
def test_subclass_classmethod_ignored():
- members = [m[1] for m in get_interesting_members(FlaskView, SubVariedMethodsView)]
+ members = [m[1] for m
+ in get_interesting_members(FlaskView, SubVariedMethodsView)]
assert SubVariedMethodsView.class_method not in members
assert VariedMethodsView.class_method not in members
diff --git a/test_classful/test_representations.py b/test_classful/test_representations.py
index 60959d9..62e33e6 100644
--- a/test_classful/test_representations.py
+++ b/test_classful/test_representations.py
@@ -1,7 +1,7 @@
from flask import Flask, make_response, redirect
from flask_classful import FlaskView
import json
-from nose.tools import *
+from nose.tools import eq_
def output_json(data, code, headers=None):
@@ -17,37 +17,37 @@ def output_json(data, code, headers=None):
# Test Responses
response_1 = {
- 'internal_string':"just a string",
+ 'internal_string': "just a string",
'integer': 5,
'validate_int': 1,
'input_required': 'just another string'
}
response_2 = {
- 'internal_string':"What is going on",
+ 'internal_string': "What is going on",
'integer': 3,
'validate_int': 1,
'input_required': 'Nothing'
}
response_get = {
- 'internal_string':"What is going on",
+ 'internal_string': "What is going on",
'integer': 3,
'validate_int': 1,
'input_required': 'GET'
}
response_put = {
- 'internal_string':"What is going on",
+ 'internal_string': "What is going on",
'integer': 3,
'validate_int': 1,
'input_required': 'PUT'
}
response_post = {
- 'internal_string':"What is going on",
+ 'internal_string': "What is going on",
'integer': 3,
'validate_int': 1,
'input_required': 'POST'
}
response_delete = {
- 'internal_string':"What is going on",
+ 'internal_string': "What is going on",
'integer': 3,
'validate_int': 1,
'input_required': 'DELETE'
@@ -61,7 +61,6 @@ class RepresentationView(FlaskView):
representations = {'application/json': output_json}
base_args = ['fields']
-
def index(self):
return [response_1, response_2]
@@ -85,29 +84,39 @@ def redirect(self):
client = app.test_client()
+
def test_index_representation():
resp = client.get("/representation/")
eq_(json.dumps([response_1, response_2]), resp.data.decode('ascii'))
+
def test_get_representation():
resp = client.get("/representation/1")
eq_(json.dumps(response_get), resp.data.decode('ascii'))
+
def test_post_representation():
- resp = client.post("/representation/", headers=input_headers, data=json.dumps(input_data))
+ resp = client.post("/representation/",
+ headers=input_headers,
+ data=json.dumps(input_data))
eq_(resp.status_code, 404, 'should return 404 status code')
eq_(resp.headers['say'], 'hello')
eq_(json.dumps(response_post), resp.data.decode('ascii'))
+
def test_put_representation():
- resp = client.put("/representation/1", headers=input_headers, data=json.dumps(input_data))
+ resp = client.put("/representation/1",
+ headers=input_headers,
+ data=json.dumps(input_data))
eq_(resp.status_code, 403, 'should return 403 status code')
eq_(json.dumps(response_put), resp.data.decode('ascii'))
+
def test_delete_representation():
resp = client.delete("/representation/1")
eq_(json.dumps(response_delete), resp.data.decode('ascii'))
+
def test_skip_representation_matching_if_response_is_returned():
resp = client.get("/representation/redirect/")
assert resp.status_code == 302
diff --git a/test_classful/test_route_base.py b/test_classful/test_route_base.py
index 158028c..428c386 100644
--- a/test_classful/test_route_base.py
+++ b/test_classful/test_route_base.py
@@ -1,6 +1,6 @@
from flask import Flask
-from .view_classes import BasicView, RouteBaseView
-from nose.tools import *
+from .view_classes import RouteBaseView
+from nose.tools import eq_
app = Flask('route_base')
RouteBaseView.register(app, route_base="/rb_test2/")
diff --git a/test_classful/test_route_prefix.py b/test_classful/test_route_prefix.py
index f7ddbd1..03fe399 100644
--- a/test_classful/test_route_prefix.py
+++ b/test_classful/test_route_prefix.py
@@ -1,6 +1,6 @@
from flask import Flask
from .view_classes import BasicView, RoutePrefixView, RouteBaseView
-from nose.tools import *
+from nose.tools import eq_
app = Flask('route_base')
@@ -25,4 +25,3 @@ def test_route_prefix_with_route_base():
client = app.test_client()
resp = client.get('/prefix/base-routed/')
eq_(b"Index", resp.data)
-
diff --git a/test_classful/test_subdomains.py b/test_classful/test_subdomains.py
index b894e56..892bd01 100644
--- a/test_classful/test_subdomains.py
+++ b/test_classful/test_subdomains.py
@@ -1,6 +1,6 @@
-from flask import Flask, url_for
-from .view_classes import BasicView, IndexView
-from nose.tools import *
+from flask import Flask
+from .view_classes import BasicView
+from nose.tools import eq_
app = Flask("common")
app.config["SERVER_NAME"] = "test.test"
@@ -8,42 +8,54 @@
client = app.test_client()
+
def test_index_subdomain():
resp = client.get("/basic/", base_url="http://basic.test.test")
eq_(b"Index", resp.data)
+
def test_get():
resp = client.get("/basic/1234", base_url="http://basic.test.test")
eq_(b"Get 1234", resp.data)
+
def test_put():
resp = client.put("/basic/1234", base_url="http://basic.test.test")
eq_(b"Put 1234", resp.data)
+
def test_patch():
resp = client.patch("/basic/1234", base_url="http://basic.test.test")
eq_(b"Patch 1234", resp.data)
+
def test_post():
resp = client.post("/basic/", base_url="http://basic.test.test")
eq_(b"Post", resp.data)
+
def test_delete():
resp = client.delete("/basic/1234", base_url="http://basic.test.test")
eq_(b"Delete 1234", resp.data)
+
def test_custom_method():
- resp = client.get("/basic/custom_method/", base_url="http://basic.test.test")
+ resp = client.get("/basic/custom_method/",
+ base_url="http://basic.test.test")
eq_(b"Custom Method", resp.data)
+
def test_custom_method_with_params():
- resp = client.get("/basic/custom_method_with_params/1234/abcd", base_url="http://basic.test.test")
+ resp = client.get("/basic/custom_method_with_params/1234/abcd",
+ base_url="http://basic.test.test")
eq_(b"Custom Method 1234 abcd", resp.data)
+
def test_routed_method():
resp = client.get("/basic/routed/", base_url="http://basic.test.test")
eq_(b"Routed Method", resp.data)
+
def test_multi_routed_method():
resp = client.get("/basic/route1/", base_url="http://basic.test.test")
eq_(b"Multi Routed Method", resp.data)
@@ -51,6 +63,7 @@ def test_multi_routed_method():
resp = client.get("/basic/route2/", base_url="http://basic.test.test")
eq_(b"Multi Routed Method", resp.data)
+
def test_no_slash():
resp = client.get("/basic/noslash", base_url="http://basic.test.test")
- eq_(b"No Slash Method", resp.data)
\ No newline at end of file
+ eq_(b"No Slash Method", resp.data)
diff --git a/test_classful/test_trailing_slash.py b/test_classful/test_trailing_slash.py
index 40ce5aa..fad0cd0 100644
--- a/test_classful/test_trailing_slash.py
+++ b/test_classful/test_trailing_slash.py
@@ -1,6 +1,12 @@
from flask import Flask
-from .view_classes import BasicView, TrailingSlashView, InheritedTrailingSlashView, OverrideInheritedTrailingSlashView, IndexView
-from nose.tools import *
+from .view_classes import (
+ BasicView,
+ TrailingSlashView,
+ InheritedTrailingSlashView,
+ OverrideInheritedTrailingSlashView,
+ IndexView
+)
+from nose.tools import eq_
app = Flask('trailing_slash')
BasicView.register(app, trailing_slash=False)
@@ -11,102 +17,116 @@
client = app.test_client()
+
def test_index():
resp = client.get("/basic")
eq_(b"Index", resp.data)
+
def test_get():
resp = client.get("/basic/1234")
eq_(b"Get 1234", resp.data)
+
def test_put():
resp = client.put("/basic/1234")
eq_(b"Put 1234", resp.data)
+
def test_patch():
resp = client.patch("/basic/1234")
eq_(b"Patch 1234", resp.data)
+
def test_post():
resp = client.post("/basic")
eq_(b"Post", resp.data)
+
def test_delete():
resp = client.delete("/basic/1234")
eq_(b"Delete 1234", resp.data)
+
def test_custom_method():
resp = client.get("/basic/custom_method")
eq_(b"Custom Method", resp.data)
+
def test_custom_method_with_params():
resp = client.get("/basic/custom_method_with_params/1234/abcd")
eq_(b"Custom Method 1234 abcd", resp.data)
+
def test_routed_method():
resp = client.get("/basic/routed/")
eq_(b"Routed Method", resp.data)
# TrailingSlashView
-
def test_trailing_index():
resp = client.get("/trailing")
eq_(b"Index", resp.data)
+
def test_trailing_get():
resp = client.get("/trailing/1234")
eq_(b"Get 1234", resp.data)
+
def test_trailing_put():
resp = client.put("/trailing/1234")
eq_(b"Put 1234", resp.data)
+
def test_trailing_patch():
resp = client.patch("/trailing/1234")
eq_(b"Patch 1234", resp.data)
+
def test_trailing_post():
resp = client.post("/trailing")
eq_(b"Post", resp.data)
+
def test_trailing_delete():
resp = client.delete("/trailing/1234")
eq_(b"Delete 1234", resp.data)
+
def test_trailing_custom_method():
resp = client.get("/trailing/custom_method")
eq_(b"Custom Method", resp.data)
+
def test_trailing_custom_method_with_params():
resp = client.get("/trailing/custom_method_with_params/1234/abcd")
eq_(b"Custom Method 1234 abcd", resp.data)
+
def test_trailing_routed_method():
resp = client.get("/trailing/routed/")
eq_(b"Routed Method", resp.data)
+
def test_trailing_routed_method2():
resp = client.get("/trailing/routed2")
eq_(b"Routed Method 2", resp.data)
# InheritedTrailingSlashView
-
def test_inherited_trailing_slash():
resp = client.get("/inherited/trailing")
eq_(b"Index", resp.data)
# OverrideInheritedTrailingSlashView
-
def test_inherited_trailing_slash_override():
resp = client.get("/override/trailing/")
eq_(b"Index", resp.data)
# IndexView route_base '/' and trailing slash False
-
def test_index_trailing_slash():
resp = client.get("/")
eq_(b"Index", resp.data)
diff --git a/test_classful/test_view_wrappers.py b/test_classful/test_view_wrappers.py
index 3ead3bf..d672d06 100644
--- a/test_classful/test_view_wrappers.py
+++ b/test_classful/test_view_wrappers.py
@@ -1,7 +1,14 @@
from flask import Flask
-from .view_classes import (BeforeRequestView, BeforeViewView, AfterRequestView, AfterViewView, DecoratedView,
- BeforeRequestReturnsView, BeforeViewReturnsView)
-from nose.tools import *
+from .view_classes import (
+ BeforeRequestView,
+ BeforeViewView,
+ AfterRequestView,
+ AfterViewView,
+ DecoratedView,
+ BeforeRequestReturnsView,
+ BeforeViewReturnsView
+)
+from nose.tools import eq_
app = Flask("wrappers")
BeforeRequestView.register(app)
@@ -14,22 +21,27 @@
client = app.test_client()
+
def test_before_request():
resp = client.get("/before-request/")
eq_(b"Before Request", resp.data)
+
def test_before_view():
resp = client.get("/before-view/")
eq_(b"Before View", resp.data)
+
def test_after_view():
resp = client.get("/after-view/")
eq_(b"After View", resp.data)
+
def test_after_request():
resp = client.get("/after-request/")
eq_(b"After Request", resp.data)
+
def test_decorated_view():
resp = client.get("/decorated/")
eq_(b"Index", resp.data)
@@ -42,6 +54,7 @@ def test_before_request_returns():
resp = client.get("/before-request-returns/")
eq_(b"BEFORE", resp.data)
+
def test_before_view_returns():
resp = client.get("/before-view-returns/")
eq_(b"BEFORE", resp.data)
diff --git a/test_classful/view_classes.py b/test_classful/view_classes.py
index 2ca27d4..d71f355 100644
--- a/test_classful/view_classes.py
+++ b/test_classful/view_classes.py
@@ -191,12 +191,13 @@ def decorated_view(*args, **kwargs):
def params_decorator(p_1, p_2):
def decorator(f):
- @wraps(f)
- def decorated_function(*args, **kwargs):
- return f(*args, **kwargs)
- return decorated_function
+ @wraps(f)
+ def decorated_function(*args, **kwargs):
+ return f(*args, **kwargs)
+ return decorated_function
return decorator
+
def recursive_decorator(f):
@wraps(f)
def decorated_view(*args, **kwargs):
@@ -216,6 +217,7 @@ def _recursive(*args, **kw):
return _recursive
return _inner
+
class DecoratedView(FlaskView):
@func_decorator
def index(self):
diff --git a/test_classful_py3/test_type_hints.py b/test_classful_py3/test_type_hints.py
index 7009695..d8bd8fb 100644
--- a/test_classful_py3/test_type_hints.py
+++ b/test_classful_py3/test_type_hints.py
@@ -1,7 +1,7 @@
from uuid import UUID
from flask import Flask
from flask_classful import FlaskView, route
-from nose.tools import *
+from nose.tools import eq_
# python3 only