Skip to content

Commit

Permalink
!chg: Remove Flask-Testing dependency and drop Python 3.4 support. (p…
Browse files Browse the repository at this point in the history
…langrid#173)

* Remove Flask-Testing dependency.
* Added JsonResponseMixin from Flask-Testing which we need as long as we continue to test flask<1.0
* Pinned Werkzueg in travis. Should be able to drop if we drop flask<0.12 support.
* Dropped support for python 3.4 in order to test support for Werkzeug 1.0.0
  • Loading branch information
airstandley authored Feb 13, 2020
1 parent 58c7023 commit 20076f6
Show file tree
Hide file tree
Showing 6 changed files with 59 additions and 23 deletions.
25 changes: 11 additions & 14 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,23 @@ sudo: required
dist: xenial
python:
- '2.7'
- '3.4'
- '3.5'
- '3.6'
- '3.7'
env:
- MARSHMALLOW_VERSION='2.13.*' FLASK_VERSION='0.10.*'
- MARSHMALLOW_VERSION='2.14.*' FLASK_VERSION='0.11.*'
- MARSHMALLOW_VERSION='2.15.*' FLASK_VERSION='0.12.*'
- MARSHMALLOW_VERSION='2.15.*' FLASK_VERSION='1.0.*'
- MARSHMALLOW_VERSION='2.15.*' FLASK_VERSION='1.0.*'
- MARSHMALLOW_VERSION='2.16.*' FLASK_VERSION='1.0.*'
- MARSHMALLOW_VERSION='2.17.*' FLASK_VERSION='1.0.*'
- MARSHMALLOW_VERSION='2.18.*' FLASK_VERSION='1.0.*'
- MARSHMALLOW_VERSION='2.19.*' FLASK_VERSION='1.0.*'
- MARSHMALLOW_VERSION='2.20.*' FLASK_VERSION='1.0.*'
- MARSHMALLOW_VERSION='3.0.0rc5' FLASK_VERSION='1.0.*'
- MARSHMALLOW_VERSION='2.13.*' FLASK_VERSION='0.10.*' WERKZEUG_VERSION='0.16.1'
- MARSHMALLOW_VERSION='2.14.*' FLASK_VERSION='0.11.*' WERKZEUG_VERSION='0.16.1'
- MARSHMALLOW_VERSION='2.15.*' FLASK_VERSION='0.12.*' WERKZEUG_VERSION='0.16.1'
- MARSHMALLOW_VERSION='2.15.*' FLASK_VERSION='1.0.*' WERKZEUG_VERSION='0.*'
- MARSHMALLOW_VERSION='2.16.*' FLASK_VERSION='1.0.*' WERKZEUG_VERSION='0.*'
- MARSHMALLOW_VERSION='2.17.*' FLASK_VERSION='1.0.*' WERKZEUG_VERSION='0.*'
- MARSHMALLOW_VERSION='2.18.*' FLASK_VERSION='1.0.*' WERKZEUG_VERSION='0.*'
- MARSHMALLOW_VERSION='2.19.*' FLASK_VERSION='1.0.*' WERKZEUG_VERSION='0.*'
- MARSHMALLOW_VERSION='2.20.*' FLASK_VERSION='1.*' WERKZEUG_VERSION='1.*'
- MARSHMALLOW_VERSION='3.0.0rc5' FLASK_VERSION='1.*' WERKZEUG_VERSION='1.*'
install:
- pip install -U pip
- pip install Flask==$FLASK_VERSION
- pip install marshmallow==$MARSHMALLOW_VERSION
- pip install Flask==$FLASK_VERSION werkzeug==$WERKZEUG_VERSION marshmallow==$MARSHMALLOW_VERSION
# Updating black? Run pre-commit autoupdate to ref latest version in .pre-commit-config.yaml and keep in sync
- if [[ $TRAVIS_PYTHON_VERSION == '3.7' ]]; then pip install black==19.3b0; fi
- pip install '.[dev]'
Expand Down
1 change: 0 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
# packages required for local development and testing
development = [
"pytest==4.6.8",
"Flask-Testing==0.6.2",
"mock==2.0.0",
"jsonschema==3.0.2",
"Sphinx==1.7.0",
Expand Down
7 changes: 5 additions & 2 deletions tests/examples/test_todo.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,20 @@
"""
import json

from flask_testing import TestCase
import unittest

from examples.todo.todo import create_app


class TestTodoApp(TestCase):
class TestTodoApp(unittest.TestCase):
"""
Just some super basic tests to make sure our example app appears to still
be working.
"""

def setUp(self):
self.app = self.create_app()

def create_app(self):
return create_app(__name__)

Expand Down
20 changes: 20 additions & 0 deletions tests/helpers.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,30 @@
import unittest
from flask_rebar.compat import MARSHMALLOW_V2, MARSHMALLOW_V3
from flask import json_available

if json_available:
from flask import json
from werkzeug.utils import cached_property

skip_if_marshmallow_not_v2 = unittest.skipIf(
not MARSHMALLOW_V2, reason="Only applicable for Marshmallow version 2"
)
skip_if_marshmallow_not_v3 = unittest.skipIf(
not MARSHMALLOW_V3, reason="Only applicable for Marshmallow version 3"
)


class JsonResponseMixin(object):
"""
Mixin with testing helper methods
"""

@cached_property
def json(self):
if not json_available: # pragma: no cover
raise NotImplementedError
return json.loads(self.data)


def make_test_response(response_class):
return type("TestResponse", (response_class, JsonResponseMixin), {})
21 changes: 17 additions & 4 deletions tests/test_errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,14 @@
from __future__ import unicode_literals

import json
import unittest

from flask import Flask
from flask_testing import TestCase
from marshmallow import fields
from werkzeug.exceptions import BadRequest
from mock import ANY
from mock import patch
from tests.helpers import make_test_response

from flask_rebar import messages, validation, response, Rebar
from flask_rebar.compat import MARSHMALLOW_V2
Expand All @@ -25,9 +26,13 @@
from flask_rebar.utils.request_utils import get_query_string_params_or_400


class TestErrors(TestCase):
class TestErrors(unittest.TestCase):
ERROR_MSG = "Bamboozled!"

def setUp(self):
self.app = self.create_app()
self.app.response_class = make_test_response(self.app.response_class)

def create_app(self):
app = Flask(__name__)

Expand Down Expand Up @@ -111,7 +116,11 @@ def test_timeouts_log_exceptions(self):
)


class TestJsonBodyValidation(TestCase):
class TestJsonBodyValidation(unittest.TestCase):
def setUp(self):
self.app = self.create_app()
self.app.response_class = make_test_response(self.app.response_class)

def post_json(self, path, data):
return self.app.test_client().post(
path=path,
Expand Down Expand Up @@ -290,7 +299,11 @@ def test_invalid_json_error(self):
self.assertEqual(resp.json, {"message": messages.invalid_json})


class TestQueryStringValidation(TestCase):
class TestQueryStringValidation(unittest.TestCase):
def setUp(self):
self.app = self.create_app()
self.app.response_class = make_test_response(self.app.response_class)

def create_app(self):
app = Flask(__name__)
Rebar().init_app(app=app)
Expand Down
8 changes: 6 additions & 2 deletions tests/test_request_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,19 @@
:license: MIT, see LICENSE for details.
"""
import unittest
from tests.helpers import make_test_response

from flask import Flask
from flask_testing import TestCase
from marshmallow import fields, ValidationError

from flask_rebar import validation, response, marshal


class TestResponseFormatting(TestCase):
class TestResponseFormatting(unittest.TestCase):
def setUp(self):
self.app = self.create_app()
self.app.response_class = make_test_response(self.app.response_class)

def create_app(self):
app = Flask(__name__)

Expand Down

0 comments on commit 20076f6

Please sign in to comment.