From 0ce43ecdeec3eb9031defe85c0dee71e9d0c478c Mon Sep 17 00:00:00 2001 From: Anton Agestam Date: Sat, 29 Jun 2019 21:20:59 +0200 Subject: [PATCH] rip moto --- .gitignore | 1 + .travis.yml | 5 ++++- README.rst | 10 ++++++++++ collectfast/tests/test_command.py | 9 +-------- collectfast/tests/utils.py | 12 ------------ runtests.py | 8 +++++++- setup.cfg | 9 +++++++++ tox.ini | 14 +++++--------- 8 files changed, 37 insertions(+), 31 deletions(-) create mode 100644 setup.cfg diff --git a/.gitignore b/.gitignore index 0b117ed..be7b777 100644 --- a/.gitignore +++ b/.gitignore @@ -8,3 +8,4 @@ /static_root/ build/ dist/ +aws-credentials diff --git a/.travis.yml b/.travis.yml index 17188bd..c155751 100644 --- a/.travis.yml +++ b/.travis.yml @@ -3,7 +3,10 @@ python: - '3.6' install: - pip install tox -script: tox +script: + # see https://github.com/travis-ci/travis-ci/issues/7940 + - sudo rm -f /etc/boto.cfg + - tox sudo: false env: matrix: diff --git a/README.rst b/README.rst index cacc4ce..cdf602f 100644 --- a/README.rst +++ b/README.rst @@ -129,6 +129,16 @@ open and welcome. **Testing** +The test suite is built to run against an S3 bucket. To be able to test locally +you need to provide AWS credentials for a bucket to test against. Add the +credentials to a file named `aws-credentials` in the root of the project +directory: + +.. code:: bash + + export AWS_ACCESS_KEY_ID='' + export AWS_SECRET_ACCESS_KEY='' + To run tests with tox, setup a virtualenv and install tox with ``pip install tox`` then run ``tox`` in the project directory. To only run tests for a certain environment run e.g. ``tox -e py35-django110``. diff --git a/collectfast/tests/test_command.py b/collectfast/tests/test_command.py index fd8bb09..b7f2621 100644 --- a/collectfast/tests/test_command.py +++ b/collectfast/tests/test_command.py @@ -5,7 +5,7 @@ from django.test import override_settings as override_django_settings from .utils import test, clean_static_dir, create_static_file, override_setting -from .utils import with_bucket, override_storage_attr +from .utils import override_storage_attr def call_collectstatic(*args, **kwargs): @@ -16,7 +16,6 @@ def call_collectstatic(*args, **kwargs): @test -@with_bucket def test_basics(case): clean_static_dir() create_static_file() @@ -29,7 +28,6 @@ def test_basics(case): @test @override_setting("threads", 5) -@with_bucket def test_threads(case): clean_static_dir() create_static_file() @@ -41,7 +39,6 @@ def test_threads(case): @test -@with_bucket @override_django_settings( STATICFILES_STORAGE="collectfast.tests.no_preload_metadata.NPM") def test_warn_preload_metadata(case): @@ -54,7 +51,6 @@ def test_warn_preload_metadata(case): @test -@with_bucket def test_collectfast_disabled(case): clean_static_dir() create_static_file() @@ -73,7 +69,6 @@ def test_collectfast_disabled_default_storage(case): @test -@with_bucket def test_disable_collectfast(case): clean_static_dir() create_static_file() @@ -82,7 +77,6 @@ def test_disable_collectfast(case): @test -@with_bucket def test_ignore_etag_deprecated(case): clean_static_dir() create_static_file() @@ -95,7 +89,6 @@ def test_ignore_etag_deprecated(case): @test @override_storage_attr("gzip", True) @override_setting("is_gzipped", True) -@with_bucket def test_is_gzipped(case): clean_static_dir() create_static_file() diff --git a/collectfast/tests/utils.py b/collectfast/tests/utils.py index 964bcda..444375e 100644 --- a/collectfast/tests/utils.py +++ b/collectfast/tests/utils.py @@ -7,9 +7,6 @@ from django.conf import settings as django_settings from django.utils.module_loading import import_string -import boto -import moto - from collectfast import settings @@ -26,15 +23,6 @@ def test(func): return type(func.__name__, (unittest.TestCase, ), {func.__name__: func}) -def with_bucket(func): - @functools.wraps(func) - @moto.mock_s3 - def wraps(*args, **kwargs): - boto.connect_s3().create_bucket(django_settings.AWS_STORAGE_BUCKET_NAME) - return func(*args, **kwargs) - return wraps - - def create_static_file(): filename = 'static/%s.txt' % uuid.uuid4() with open(filename, 'w+') as f: diff --git a/runtests.py b/runtests.py index e623b1f..cdd8dd0 100755 --- a/runtests.py +++ b/runtests.py @@ -75,7 +75,13 @@ def main(): "AWS_PRELOAD_METADATA": True, "AWS_STORAGE_BUCKET_NAME": "collectfast", "AWS_IS_GZIPPED": False, - "GZIP_CONTENT_TYPES": ('text/plain',), + "GZIP_CONTENT_TYPES": ('text/plain', ), + "AWS_ACCESS_KEY_ID": os.environ.get("AWS_ACCESS_KEY_ID").strip(), + "AWS_SECRET_ACCESS_KEY": os.environ.get("AWS_SECRET_ACCESS_KEY").strip(), + "AWS_S3_REGION_NAME": "eu-central-1", + "AWS_S3_SIGNATURE_VERSION": "s3v4", + "AWS_QUERYSTRING_AUTH": False, + "AWS_DEFAULT_ACL": None, }) if options.TEST_SUITE is not None: diff --git a/setup.cfg b/setup.cfg new file mode 100644 index 0000000..68117ec --- /dev/null +++ b/setup.cfg @@ -0,0 +1,9 @@ +[flake8] +exclude = appveyor, .idea, .git, .venv, .tox, __pycache__, *.egg-info +max-complexity = 8 +max-line-length = 88 +enable-extensions = + M511 # flake8-mutable +# see this discussion as to why we're ignoring E722: +# https://github.com/PyCQA/pycodestyle/issues/703 +extend-ignore = F403,E265,E722 diff --git a/tox.ini b/tox.ini index 5996489..d6fb2e4 100644 --- a/tox.ini +++ b/tox.ini @@ -5,7 +5,6 @@ deps = django111: Django>=1.11,<1.12 django200: Django>=2.0,<2.1 mock==1.3.0 - moto==0.4.31 coveralls django-storages boto3 @@ -13,13 +12,10 @@ deps = commands = coverage run --source=collectfast {toxinidir}/runtests.py - coveralls -passenv = TRAVIS TRAVIS_JOB_ID TRAVIS_BRANCH +passenv = TRAVIS TRAVIS_JOB_ID TRAVIS_BRANCH AWS_ACCESS_KEY_ID AWS_SECRET_ACCESS_KEY [testenv:flake8] basepython = python -deps = flake8 -commands = flake8 collectfast runtests.py setup.py -[flake8] -max-line-length = 80 -ignore = F403,E265,E722 -exclude = .git -max-complexity = 8 +deps = + flake8 + flake8-mutable +commands = flake8