From cbd2140644641649f641cbe6201f731a7d01084c Mon Sep 17 00:00:00 2001 From: SunDwarf Date: Fri, 28 Aug 2015 19:52:41 +0100 Subject: [PATCH] Prevent url_for from building when app.testing is True/existing. Closes #23. --- .travis.yml | 6 +++++- docs/requirements.txt | 8 +++----- flask_s3.py | 2 ++ requirements.txt | 3 +++ test_flask_static.py | 6 +++++- 5 files changed, 18 insertions(+), 7 deletions(-) create mode 100644 requirements.txt diff --git a/.travis.yml b/.travis.yml index 102e309..8b61183 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,7 +1,11 @@ language: python python: - "2.7" + - "3.2" + - "3.3" + - "3.4" # command to install dependencies, e.g. pip install -r requirements.txt --use-mirrors -install: pip install -r docs/requirements.txt --use-mirrors +install: pip install -r requirements.txt --use-mirrors # command to run tests, e.g. python setup.py test script: nosetests +sudo: false diff --git a/docs/requirements.txt b/docs/requirements.txt index 216a6f4..869cff6 100644 --- a/docs/requirements.txt +++ b/docs/requirements.txt @@ -1,5 +1,3 @@ -Flask==0.9 -Jinja2==2.6 -Werkzeug==0.8.3 -boto3==1.1.1 -wsgiref==0.1.2 +Flask2 +boto3 + diff --git a/flask_s3.py b/flask_s3.py index 68c4267..65f4f72 100644 --- a/flask_s3.py +++ b/flask_s3.py @@ -44,6 +44,8 @@ def url_for(endpoint, **values): of your templates. """ app = current_app + if app.config.get('TESTING', False) and not app.config.get('S3_OVERRIDE_TESTING', True): + return flask_url_for(endpoint, **values) if 'S3_BUCKET_NAME' not in app.config: raise ValueError("S3_BUCKET_NAME not found in app configuration.") diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..1c3fe21 --- /dev/null +++ b/requirements.txt @@ -0,0 +1,3 @@ +Flask +boto3 +six diff --git a/test_flask_static.py b/test_flask_static.py index 76836cc..843ecbd 100644 --- a/test_flask_static.py +++ b/test_flask_static.py @@ -2,6 +2,7 @@ import unittest import ntpath import tempfile import os +import sys try: from unittest.mock import Mock, patch, call, mock_open @@ -51,6 +52,7 @@ class UrlTests(unittest.TestCase): self.app.config['S3_USE_HTTPS'] = True self.app.config['S3_BUCKET_DOMAIN'] = 's3.amazonaws.com' self.app.config['S3_CDN_DOMAIN'] = '' + self.app.config['S3_OVERRIDE_TESTING'] = True @self.app.route('/') def a(url_for_string): @@ -242,8 +244,10 @@ class S3Tests(unittest.TestCase): actual = flask_s3._path_to_relative_url(in_) self.assertEquals(exp, actual) + @unittest.skipIf(sys.version_info < (3, 0), + "not supported in this version") @patch('flask_s3.boto3') - @patch("{}.open".format("builtins" if six.PY3 else "__builtins__"), mock_open(read_data='test')) + @patch("{}.open".format("builtins"), mock_open(read_data='test')) def test__write_files(self, key_mock): """ Tests _write_files """ static_url_loc = '/foo/static'