Skip to content
This repository has been archived by the owner on Jan 16, 2023. It is now read-only.

Commit

Permalink
rip moto
Browse files Browse the repository at this point in the history
  • Loading branch information
antonagestam committed Jun 29, 2019
1 parent fb9d797 commit 0ce43ec
Show file tree
Hide file tree
Showing 8 changed files with 37 additions and 31 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@
/static_root/
build/
dist/
aws-credentials
5 changes: 4 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
10 changes: 10 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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``.
Expand Down
9 changes: 1 addition & 8 deletions collectfast/tests/test_command.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -16,7 +16,6 @@ def call_collectstatic(*args, **kwargs):


@test
@with_bucket
def test_basics(case):
clean_static_dir()
create_static_file()
Expand All @@ -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()
Expand All @@ -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):
Expand All @@ -54,7 +51,6 @@ def test_warn_preload_metadata(case):


@test
@with_bucket
def test_collectfast_disabled(case):
clean_static_dir()
create_static_file()
Expand All @@ -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()
Expand All @@ -82,7 +77,6 @@ def test_disable_collectfast(case):


@test
@with_bucket
def test_ignore_etag_deprecated(case):
clean_static_dir()
create_static_file()
Expand All @@ -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()
Expand Down
12 changes: 0 additions & 12 deletions collectfast/tests/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand All @@ -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:
Expand Down
8 changes: 7 additions & 1 deletion runtests.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
9 changes: 9 additions & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
@@ -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
14 changes: 5 additions & 9 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,17 @@ 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
boto
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

0 comments on commit 0ce43ec

Please sign in to comment.