Unverified Commit d96d0761 by Brian Mesick Committed by GitHub

Merge pull request #2 from edx/bmedx/update_to_spec

Upgrading to django cookiecutter spec in preparation for PyPI deployment
parents b45a36f4 2692307a
[run]
branch = True
data_file = .coverage
source=splash
omit =
test_settings
*migrations*
*admin.py
*static*
*templates*
*.pyc
*~
*.py[cod]
__pycache__
# C extensions
*.so
# Packages
*.egg
*.egg-info
dist
build
eggs
parts
bin
var
sdist
develop-eggs
.installed.cfg
lib
lib64
# Installer logs
pip-log.txt
# Unit test / coverage reports
.pytest_cache/
.cache/
.coverage
.coverage.*
.tox
coverage.xml
htmlcov/
# Translations
*.mo
# IDEs and text editors
*~
*.swp
.idea/
.project
.pycharm_helpers/
.pydevproject
# The Silver Searcher
.agignore
# OS X artifacts
*.DS_Store
# Logging
log/
logs/
chromedriver.log
ghostdriver.log
# Complexity
output/*.html
output/*/index.html
# Private requirements
requirements/private.in
requirements/private.txt
# tox environment temporary artifacts
tests/__init__.py
# Development task artifacts
default.db
# Config file for automatic testing at travis-ci.org
language: python
python:
- 2.7
- 3.6
env:
- TOXENV=django18
- TOXENV=django111
matrix:
include:
- python: 3.6
env: TOXENV=quality
cache:
- pip
before_install:
- pip install --upgrade pip
install:
- pip install -r requirements/travis.txt
script:
- tox
after_success:
- codecov
# Set password via "travis encrypt --add deploy.password"; for details, see
# https://docs.travis-ci.com/user/deployment/pypi
deploy:
provider: pypi
user: edx
distributions: sdist bdist_wheel
on:
tags: true
condition: '$TOXENV = quality'
Brian Mesick <bmesick@edx.org>
Change Log
----------
..
All enhancements and patches to django-splash will be documented
in this file. It adheres to the structure of http://keepachangelog.com/ ,
but in reStructuredText instead of Markdown (for ease of incorporation into
Sphinx documentation and the PyPI description).
This project adheres to Semantic Versioning (http://semver.org/).
.. There should always be an "Unreleased" section for changes pending release.
Unreleased
~~~~~~~~~~
*
[0.2.1] - 2018-02-07
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Added
_____
* First release on PyPI.
This diff is collapsed. Click to expand it.
include AUTHORS
include CHANGELOG.rst
include CONTRIBUTING.rst
include LICENSE.txt
include README.rst
recursive-include splash *.html *.png *.gif *js *.css *jpg *jpeg *svg *py
.PHONY: clean compile_translations coverage dummy_translations \
extract_translations fake_translations help pull_translations push_translations \
quality requirements selfcheck test test-all upgrade validate
.DEFAULT_GOAL := help
define BROWSER_PYSCRIPT
import os, webbrowser, sys
try:
from urllib import pathname2url
except:
from urllib.request import pathname2url
webbrowser.open("file://" + pathname2url(os.path.abspath(sys.argv[1])))
endef
export BROWSER_PYSCRIPT
BROWSER := python -c "$$BROWSER_PYSCRIPT"
help: ## display this help message
@echo "Please use \`make <target>' where <target> is one of"
@perl -nle'print $& if m{^[a-zA-Z_-]+:.*?## .*$$}' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m %-25s\033[0m %s\n", $$1, $$2}'
clean: ## remove generated byte code, coverage reports, and build artifacts
find . -name '__pycache__' -exec rm -rf {} +
find . -name '*.pyc' -exec rm -f {} +
find . -name '*.pyo' -exec rm -f {} +
find . -name '*~' -exec rm -f {} +
coverage erase
rm -fr build/
rm -fr dist/
rm -fr *.egg-info
coverage: clean ## generate and view HTML coverage report
py.test --cov-report html
$(BROWSER) htmlcov/index.html
upgrade: ## update the requirements/*.txt files with the latest packages satisfying requirements/*.in
pip install -q pip-tools
pip-compile --upgrade -o requirements/dev.txt requirements/base.in requirements/dev.in requirements/quality.in
pip-compile --upgrade -o requirements/quality.txt requirements/quality.in
pip-compile --upgrade -o requirements/test.txt requirements/base.in requirements/test.in
pip-compile --upgrade -o requirements/travis.txt requirements/travis.in
# Let tox control the Django version for tests
sed '/Django==/d' requirements/test.txt > requirements/test.tmp
mv requirements/test.tmp requirements/test.txt
quality: ## check coding style with pycodestyle and pylint
tox -e quality
requirements: ## install development environment requirements
pip install -qr requirements/dev.txt --exists-action w
pip-sync requirements/dev.txt requirements/private.* requirements/test.txt
test: clean ## run tests in the current virtualenv
py.test
diff_cover: test
diff-cover coverage.xml
test-all: ## run tests on every supported Python/Django combination
tox -e quality
tox
validate: quality test ## run tests and quality checks
selfcheck: ## check that the Makefile is well-formed
@echo "The Makefile is well-formed."
Splash screen middleware for Django apps
========================================
Checks incoming requests, to redirect users to a configured splash screen URL
if they don't have the proper cookie set. This can be used to display a small
marketing landing page, protect an alpha website from the public eye, make an
announcement, etc.
Meant to be used with https://github.com/edx/edx-platform/ -- or you will need
to import the config_models application to your Django application:
https://github.com/edx/edx-platform/tree/master/common/djangoapps/config_models
### Installation
Add the application to the `INSTALLED_APPS`:
```python
INSTALLED_APPS = (
...
# Splash screen
'splash',
)
```
Add the middleware to the configuration:
```python
MIDDLEWARE_CLASSES = (
...
'splash.middleware.SplashMiddleware',
)
```
Run the migrations:
```
$ ./manage.py migrate splash
```
Then go to your Django admin, in http://yourserver/admin/splash/splashconfig/add/
and configure the following variables:
* `enabled`: To activate the feature
* `cookie_name`: The name of the cookie
* `cookie_allowed_values`: The user cookie value must match one of the values to not be redirected to the splash screen URL
* `unaffected_users`: Users which should never be redirected (usernames)
* `redirect_url`: The URL the users should be redirected to when they don't have the right cookie
django-splash
=============
|pypi-badge| |travis-badge| |codecov-badge| |pyversions-badge|
|license-badge|
Splash screen middleware for Django apps
Overview
--------
Checks incoming requests, to redirect users to a configured splash screen URL
if they don't have the proper cookie set. This can be used to display a small
marketing landing page, protect an alpha website from the public eye, make an
announcement, etc.
Meant to be used with https://github.com/edx/edx-platform/ -- or you will need
to import the config_models application to your Django application:
https://github.com/edx/django-config-models
Installation
------------
Add the application to the `INSTALLED_APPS`:
::
python
INSTALLED_APPS = (
...
# Splash screen
'splash',
)
Add the middleware to the configuration:
::
python
MIDDLEWARE_CLASSES = (
...
'splash.middleware.SplashMiddleware',
)
Run the migrations:
``$ ./manage.py migrate splash``
Then go to your Django admin, in http://yourserver/admin/splash/splashconfig/add/
and configure the following variables:
* `enabled`: To activate the feature
* `cookie_name`: The name of the cookie
* `cookie_allowed_values`: The user cookie value must match one of the values to not be redirected to the splash screen URL
* `unaffected_users`: Users which should never be redirected (usernames)
* `redirect_url`: The URL the users should be redirected to when they don't have the right cookie
License
-------
The code in this repository is licensed under the Apache Software License 2.0 unless
otherwise noted.
Please see ``LICENSE.txt`` for details.
How To Contribute
-----------------
Contributions are very welcome.
Please read `How To Contribute <https://github.com/edx/edx-platform/blob/master/CONTRIBUTING.rst>`_ for details.
Even though they were written with ``edx-platform`` in mind, the guidelines
should be followed for Open edX code in general.
Reporting Security Issues
-------------------------
Please do not report security issues in public. Please email security@edx.org.
Getting Help
------------
Have a question about this repository, or about Open edX in general? Please
refer to this `list of resources`_ if you need any assistance.
.. _list of resources: https://open.edx.org/getting-help
.. |pypi-badge| image:: https://img.shields.io/pypi/v/django-splash.svg
:target: https://pypi.python.org/pypi/django-splash/
:alt: PyPI
.. |travis-badge| image:: https://travis-ci.org/edx/django-splash.svg?branch=master
:target: https://travis-ci.org/edx/django-splash
:alt: Travis
.. |codecov-badge| image:: http://codecov.io/github/edx/django-splash/coverage.svg?branch=master
:target: http://codecov.io/github/edx/django-splash?branch=master
:alt: Codecov
.. |pyversions-badge| image:: https://img.shields.io/pypi/pyversions/django-splash.svg
:target: https://pypi.python.org/pypi/django-splash/
:alt: Supported Python versions
.. |license-badge| image:: https://img.shields.io/github/license/edx/django-splash.svg
:target: https://github.com/edx/django-splash/blob/master/LICENSE.txt
:alt: License
coverage:
status:
project:
default:
enabled: yes
target: auto
patch:
default:
enabled: yes
target: 97%
comment: false
#!/usr/bin/env python
"""
Django administration utility.
"""
from __future__ import absolute_import, unicode_literals
import os
import sys
PWD = os.path.abspath(os.path.dirname(__file__))
if __name__ == '__main__':
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'test_settings')
sys.path.append(PWD)
try:
from django.core.management import execute_from_command_line # pylint: disable=wrong-import-position
except ImportError:
# The above import may fail for some other reason. Ensure that the
# issue is really that Django is missing to avoid masking other
# exceptions on Python 2.
try:
import django # pylint: disable=unused-import, wrong-import-position
except ImportError:
raise ImportError(
"Couldn't import Django. Are you sure it's installed and "
"available on your PYTHONPATH environment variable? Did you "
"forget to activate a virtual environment?"
)
raise
execute_from_command_line(sys.argv)
# openedx.yaml
---
owner: edx/platform-team
nick: django-splash
tags:
- tools
oeps:
oep-2: True
oep-3:
state: False
reason: TODO - Implement for this application if appropriate
oep-5:
state: False
reason: TODO - Implement for this application if appropriate
# ***************************
# ** DO NOT EDIT THIS FILE **
# ***************************
#
# This file was generated by edx-lint: http://github.com/edx.edx-lint
#
# If you want to change this file, you have two choices, depending on whether
# you want to make a local change that applies only to this repo, or whether
# you want to make a central change that applies to all repos using edx-lint.
#
# LOCAL CHANGE:
#
# 1. Edit the local pylintrc_tweaks file to add changes just to this
# repo's file.
#
# 2. Run:
#
# $ edx_lint write pylintrc
#
# 3. This will modify the local file. Submit a pull request to get it
# checked in so that others will benefit.
#
#
# CENTRAL CHANGE:
#
# 1. Edit the pylintrc file in the edx-lint repo at
# https://github.com/edx/edx-lint/blob/master/edx_lint/files/pylintrc
#
# 2. Make a new version of edx_lint, which involves the usual steps of
# incrementing the version number, submitting and reviewing a pull
# request, and updating the edx-lint version reference in this repo.
#
# 3. Install the newer version of edx-lint.
#
# 4. Run:
#
# $ edx_lint write pylintrc
#
# 5. This will modify the local file. Submit a pull request to get it
# checked in so that others will benefit.
#
#
#
#
#
# STAY AWAY FROM THIS FILE!
#
#
#
#
#
# SERIOUSLY.
#
# ------------------------------
[MASTER]
ignore = migrations
persistent = yes
load-plugins = caniusepython3.pylint_checker,edx_lint.pylint,pylint_django,pylint_celery
[MESSAGES CONTROL]
disable =
locally-disabled,
locally-enabled,
too-few-public-methods,
bad-builtin,
star-args,
abstract-class-not-used,
abstract-class-little-used,
no-init,
fixme,
logging-format-interpolation,
too-many-lines,
no-self-use,
too-many-ancestors,
too-many-instance-attributes,
too-few-public-methods,
too-many-public-methods,
too-many-return-statements,
too-many-branches,
too-many-arguments,
too-many-locals,
unused-wildcard-import,
duplicate-code
[REPORTS]
output-format = text
files-output = no
reports = no
evaluation = 10.0 - ((float(5 * error + warning + refactor + convention) / statement) * 10)
[BASIC]
bad-functions = map,filter,apply,input
module-rgx = (([a-z_][a-z0-9_]*)|([A-Z][a-zA-Z0-9]+))$
const-rgx = (([A-Z_][A-Z0-9_]*)|(__.*__)|log|urlpatterns)$
class-rgx = [A-Z_][a-zA-Z0-9]+$
function-rgx = ([a-z_][a-z0-9_]{2,40}|test_[a-z0-9_]+)$
method-rgx = ([a-z_][a-z0-9_]{2,40}|setUp|set[Uu]pClass|tearDown|tear[Dd]ownClass|assert[A-Z]\w*|maxDiff|test_[a-z0-9_]+)$
attr-rgx = [a-z_][a-z0-9_]{2,30}$
argument-rgx = [a-z_][a-z0-9_]{2,30}$
variable-rgx = [a-z_][a-z0-9_]{2,30}$
class-attribute-rgx = ([A-Za-z_][A-Za-z0-9_]{2,30}|(__.*__))$
inlinevar-rgx = [A-Za-z_][A-Za-z0-9_]*$
good-names = f,i,j,k,db,ex,Run,_,__
bad-names = foo,bar,baz,toto,tutu,tata
no-docstring-rgx = __.*__$|test_.+|setUp$|setUpClass$|tearDown$|tearDownClass$|Meta$
docstring-min-length = -1
[FORMAT]
max-line-length = 120
ignore-long-lines = ^\s*(# )?<?https?://\S+>?$
single-line-if-stmt = no
no-space-check = trailing-comma,dict-separator
max-module-lines = 1000
indent-string = ' '
[MISCELLANEOUS]
notes = FIXME,XXX,TODO
[SIMILARITIES]
min-similarity-lines = 4
ignore-comments = yes
ignore-docstrings = yes
ignore-imports = no
[TYPECHECK]
ignore-mixin-members = yes
ignored-classes = SQLObject
unsafe-load-any-extension = yes
generated-members =
REQUEST,
acl_users,
aq_parent,
objects,
DoesNotExist,
can_read,
can_write,
get_url,
size,
content,
status_code,
create,
build,
fields,
tag,
org,
course,
category,
name,
revision,
_meta,
[VARIABLES]
init-import = no
dummy-variables-rgx = _|dummy|unused|.*_unused
additional-builtins =
[CLASSES]
defining-attr-methods = __init__,__new__,setUp
valid-classmethod-first-arg = cls
valid-metaclass-classmethod-first-arg = mcs
[DESIGN]
max-args = 5
ignored-argument-names = _.*
max-locals = 15
max-returns = 6
max-branches = 12
max-statements = 50
max-parents = 7
max-attributes = 7
min-public-methods = 2
max-public-methods = 20
[IMPORTS]
deprecated-modules = regsub,TERMIOS,Bastion,rexec
import-graph =
ext-import-graph =
int-import-graph =
[EXCEPTIONS]
overgeneral-exceptions = Exception
# 1a67033d4799199101eddf63b8ed0bef3e61bda7
# pylintrc tweaks for use with edx_lint.
[MASTER]
ignore = migrations
load-plugins = caniusepython3.pylint_checker,edx_lint.pylint,pylint_django,pylint_celery
# Core requirements for using this application
Django # Web application framework
django-config-models>=0.1.8
# Additional requirements for development of this application
diff-cover # Changeset diff test coverage
edx-lint # For updating pylintrc
edx-i18n-tools # For i18n_tool dummy
pip-tools # Requirements file management
tox # virtualenv management for tests
tox-battery # Makes tox aware of requirements file changes
twine # Utility for PyPI package uploads
wheel # For generation of wheels for PyPI
#
# This file is autogenerated by pip-compile
# To update, run:
#
# pip-compile --output-file requirements/dev.txt requirements/base.in requirements/dev.in requirements/quality.in
#
argparse==1.4.0 # via caniusepython3
astroid==1.5.2 # via edx-lint, pylint, pylint-celery, pylint-plugin-utils
backports.functools-lru-cache==1.5 # via caniusepython3
caniusepython3==6.0.0
certifi==2018.1.18 # via requests
chardet==3.0.4 # via requests
click-log==0.1.8 # via edx-lint
click==6.7 # via click-log, edx-lint, pip-tools
diff-cover==1.0.2
distlib==0.2.6 # via caniusepython3
django-config-models==0.1.9
Django==1.11.10 # via django-config-models, edx-i18n-tools
djangorestframework==3.6.4 # via django-config-models
edx-i18n-tools==0.4.3
edx-lint==0.5.5
first==2.0.1 # via pip-tools
futures==3.1.1 # via caniusepython3
idna==2.6 # via requests
inflect==0.2.5 # via jinja2-pluralize
isort==4.3.3
jinja2-pluralize==0.3.0 # via diff-cover
jinja2==2.10 # via diff-cover, jinja2-pluralize
lazy-object-proxy==1.3.1 # via astroid
MarkupSafe==1.0 # via jinja2
mccabe==0.6.1 # via pylint
packaging==16.8 # via caniusepython3
path.py==10.5 # via edx-i18n-tools
pip-tools==1.11.0
pkginfo==1.4.1 # via twine
pluggy==0.6.0 # via tox
polib==1.1.0 # via edx-i18n-tools
py==1.5.2 # via tox
pycodestyle==2.3.1
pydocstyle==2.1.1
pygments==2.2.0 # via diff-cover
pylint-celery==0.3 # via edx-lint
pylint-django==0.7.2 # via edx-lint
pylint-plugin-utils==0.2.6 # via pylint-celery, pylint-django
pylint==1.7.1 # via edx-lint, pylint-celery, pylint-django, pylint-plugin-utils
pyparsing==2.2.0 # via packaging
pytz==2017.3 # via django
pyYaml==3.12 # via edx-i18n-tools
requests-toolbelt==0.8.0 # via twine
requests==2.18.4 # via caniusepython3, requests-toolbelt, twine
six==1.11.0 # via astroid, diff-cover, edx-i18n-tools, edx-lint, packaging, pip-tools, pydocstyle, pylint, tox
snowballstemmer==1.2.1 # via pydocstyle
tox-battery==0.5
tox==2.9.1
tqdm==4.19.5 # via twine
twine==1.9.1
urllib3==1.22 # via requests
virtualenv==15.1.0 # via tox
wheel==0.30.0
wrapt==1.10.11 # via astroid
# The following packages are considered to be unsafe in a requirements file:
# setuptools # via caniusepython3, pip-tools, twine
# If there are any Python packages you want to keep in your virtualenv beyond
# those listed in the official requirements files, create a "private.in" file
# and list them there. Generate the corresponding "private.txt" file pinning
# all of their indirect dependencies to specific versions as follows:
# pip-compile private.in
# This allows you to use "pip-sync" without removing these packages:
# pip-sync requirements/*.txt
# "private.in" and "private.txt" aren't checked into git to avoid merge
# conflicts, and the presence of this file allows "private.*" to be
# included in scripted pip-sync usage without requiring that those files be
# created first.
# Requirements for code quality checks
caniusepython3 # Additional Python 3 compatibility pylint checks
edx-lint # edX pylint rules and plugins
isort # to standardize order of imports
pycodestyle # PEP 8 compliance validation
pydocstyle # PEP 257 compliance validation
#
# This file is autogenerated by pip-compile
# To update, run:
#
# pip-compile --output-file requirements/quality.txt requirements/quality.in
#
argparse==1.4.0 # via caniusepython3
astroid==1.5.2 # via edx-lint, pylint, pylint-celery, pylint-plugin-utils
backports.functools-lru-cache==1.5 # via caniusepython3
caniusepython3==6.0.0
certifi==2018.1.18 # via requests
chardet==3.0.4 # via requests
click-log==0.1.8 # via edx-lint
click==6.7 # via click-log, edx-lint
distlib==0.2.6 # via caniusepython3
edx-lint==0.5.5
futures==3.1.1 # via caniusepython3
idna==2.6 # via requests
isort==4.3.3
lazy-object-proxy==1.3.1 # via astroid
mccabe==0.6.1 # via pylint
packaging==16.8 # via caniusepython3
pycodestyle==2.3.1
pydocstyle==2.1.1
pylint-celery==0.3 # via edx-lint
pylint-django==0.7.2 # via edx-lint
pylint-plugin-utils==0.2.6 # via pylint-celery, pylint-django
pylint==1.7.1 # via edx-lint, pylint-celery, pylint-django, pylint-plugin-utils
pyparsing==2.2.0 # via packaging
requests==2.18.4 # via caniusepython3
six==1.11.0 # via astroid, edx-lint, packaging, pydocstyle, pylint
snowballstemmer==1.2.1 # via pydocstyle
urllib3==1.22 # via requests
wrapt==1.10.11 # via astroid
# The following packages are considered to be unsafe in a requirements file:
# setuptools # via caniusepython3
# Requirements for test runs.
pytest-cov # pytest extension for code coverage statistics
pytest-django # pytest extension for better Django support
#
# This file is autogenerated by pip-compile
# To update, run:
#
# pip-compile --output-file requirements/test.txt requirements/base.in requirements/test.in
#
attrs==17.4.0 # via pytest
coverage==4.5 # via pytest-cov
django-config-models==0.1.9
djangorestframework==3.6.4 # via django-config-models
pluggy==0.6.0 # via pytest
py==1.5.2 # via pytest
pytest-cov==2.5.1
pytest-django==3.1.2
pytest==3.4.0 # via pytest-cov, pytest-django
pytz==2017.3 # via django
six==1.11.0 # via pytest
# The following packages are considered to be unsafe in a requirements file:
# setuptools # via pytest
# Requirements for running tests in Travis
codecov # Code coverage reporting
tox # Virtualenv management for tests
tox-battery # Makes tox aware of requirements file changes
#
# This file is autogenerated by pip-compile
# To update, run:
#
# pip-compile --output-file requirements/travis.txt requirements/travis.in
#
certifi==2018.1.18 # via requests
chardet==3.0.4 # via requests
codecov==2.0.15
coverage==4.5 # via codecov
idna==2.6 # via requests
pluggy==0.6.0 # via tox
py==1.5.2 # via tox
requests==2.18.4 # via codecov
six==1.11.0 # via tox
tox-battery==0.5
tox==2.9.1
urllib3==1.22 # via requests
virtualenv==15.1.0 # via tox
[isort]
line_length = 120
skip = migrations
known_edx =
known_django = django
known_djangoapp = config_models
known_first_party = splash
sections = FUTURE,STDLIB,THIRDPARTY,DJANGO,DJANGOAPP,EDX,FIRSTPARTY,LOCALFOLDER
[wheel]
universal = 1
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# pylint: disable=C0111,W6005,W6100
from __future__ import absolute_import, print_function
# Imports ###########################################################
import os
import re
import sys
from setuptools import setup
# Main ##############################################################
def get_version(*file_paths):
"""
Extract the version string from the file at the given relative path fragments.
"""
filename = os.path.join(os.path.dirname(__file__), *file_paths)
version_file = open(filename).read()
version_match = re.search(r"^__version__ = ['\"]([^'\"]*)['\"]",
version_file, re.M)
if version_match:
return version_match.group(1)
raise RuntimeError('Unable to find version string.')
VERSION = get_version('splash', '__init__.py')
if sys.argv[-1] == 'tag':
print("Tagging the version on github:")
os.system("git tag -a %s -m 'version %s'" % (VERSION, VERSION))
os.system("git push --tags")
sys.exit()
README = open(os.path.join(os.path.dirname(__file__), 'README.rst')).read()
CHANGELOG = open(os.path.join(os.path.dirname(__file__), 'CHANGELOG.rst')).read()
setup(
name='django-splash',
version='0.2',
description='Splash screen middleware for Django apps',
packages=['splash'],
version=VERSION,
description="""Splash screen middleware for Django apps""",
long_description=README + '\n\n' + CHANGELOG,
author='edX',
author_email='oscm@edx.org',
url='https://github.com/edx/django-splash',
packages=[
'splash',
],
include_package_data=True,
install_requires=[
"Django>=1.8,<2.0"
],
license="Apache Software License 2.0",
zip_safe=False,
keywords='Django edx',
classifiers=[
'Development Status :: 3 - Alpha',
'Framework :: Django',
'Framework :: Django :: 1.8',
'Framework :: Django :: 1.11',
'Intended Audience :: Developers',
'License :: OSI Approved :: Apache Software License',
'Natural Language :: English',
'Programming Language :: Python :: 2',
'Programming Language :: Python :: 2.7',
'Programming Language :: Python :: 3',
'Programming Language :: Python :: 3.6',
],
)
"""
Splash screen middleware for Django apps.
"""
__version__ = '0.2.1'
......@@ -2,9 +2,11 @@
Admin site bindings for splash screen
"""
from django.contrib import admin
from config_models.admin import ConfigurationModelAdmin
from splash.models import SplashConfig
admin.site.register(SplashConfig, ConfigurationModelAdmin)
......@@ -6,7 +6,7 @@ import re
from django.shortcuts import redirect
from models import SplashConfig
from .models import SplashConfig
log = logging.getLogger(__name__)
......
"""
Models for the splash screen application
"""
from django.db import models
from config_models.models import ConfigurationModel
......@@ -43,7 +44,7 @@ class SplashConfig(ConfigurationModel):
return []
return [val.strip() for val in self.cookie_allowed_values.split(',')] # pylint: disable=no-member
@property
def unaffected_usernames_list(self):
"""
......@@ -64,7 +65,7 @@ class SplashConfig(ConfigurationModel):
return [url.strip() for url in self.unaffected_url_paths.split(',')] # pylint: disable=no-member
def save(self, *args, **kwargs):
def save(self, *args, **kwargs): # pylint: disable=arguments-differ
"""Call `full_clean` before saving to ensure proper validation of configuration values"""
self.full_clean()
super(SplashConfig, self).save(*args, **kwargs)
"""
These settings are here to use during tests, because django requires them.
In a real-world use case, apps in this project are installed into other
Django applications, so these settings will not be used.
"""
from __future__ import absolute_import, unicode_literals
from os.path import abspath, dirname, join
def root(*args):
"""
Get the absolute path of the given path relative to the project root.
"""
return join(abspath(dirname(__file__)), *args)
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': 'default.db',
'USER': '',
'PASSWORD': '',
'HOST': '',
'PORT': '',
}
}
INSTALLED_APPS = [
'django.contrib.auth',
'django.contrib.contenttypes',
'splash',
]
ALLOWED_HOSTS = [
'example.org',
]
ROOT_URLCONF = 'test_urls'
SECRET_KEY = 'insecure-secret-key'
# -*- coding: utf-8 -*-
"""
Test URLs, we don't use any.
"""
from __future__ import absolute_import, unicode_literals
urlpatterns = [
]
"""
Test utilities.
Since py.test discourages putting __init__.py into test directory (i.e. making tests a package)
one cannot import from anywhere under tests folder. However, some utility classes/methods might be useful
in multiple test modules (i.e. factoryboy factories, base test classes). So this package is the place to put them.
"""
......@@ -2,6 +2,8 @@
Splash - Tests
"""
import logging
from django.contrib.auth.models import AnonymousUser, User
from django.core.exceptions import ValidationError
from django.test import TestCase
......@@ -10,9 +12,9 @@ from django.test.client import RequestFactory
from splash.middleware import SplashMiddleware
from splash.models import SplashConfig
import logging
log = logging.getLogger(__name__)
class SplashMiddlewareTestCase(TestCase):
"""
Tests for the splash screen app middleware
......@@ -47,9 +49,9 @@ class SplashMiddlewareTestCase(TestCase):
Check that the response redirects to `redirect_url`, without requiring client
interface on the response object
"""
self.assertTrue(response)
self.assertEquals(response.status_code, 302)
self.assertEquals(response['Location'], redirect_url)
assert response
assert response.status_code == 302
assert response['Location'] == redirect_url
def test_feature_disabled(self):
"""
......@@ -57,7 +59,7 @@ class SplashMiddlewareTestCase(TestCase):
"""
request = self.build_request()
response = self.splash_middleware.process_request(request)
self.assertEquals(response, None)
assert response is None
def test_no_cookie(self):
"""
......@@ -97,7 +99,7 @@ class SplashMiddlewareTestCase(TestCase):
request = self.build_request(cookies={'edx_splash_screen': 'ok2'})
response = self.splash_middleware.process_request(request)
self.assertEquals(response, None)
assert response is None
def test_wrong_cookie_different_cookie_name(self):
"""
......@@ -125,7 +127,7 @@ class SplashMiddlewareTestCase(TestCase):
request = self.build_request(cookies={'othername': 'seen'})
response = self.splash_middleware.process_request(request)
self.assertEquals(response, None)
assert response is None
def test_not_unaffected_user(self):
"""
......@@ -151,7 +153,7 @@ class SplashMiddlewareTestCase(TestCase):
request = self.build_request(username='user1')
response = self.splash_middleware.process_request(request)
self.assertEquals(response, None)
assert response is None
def test_redirect_to_current_url(self):
"""
......@@ -165,7 +167,7 @@ class SplashMiddlewareTestCase(TestCase):
request = self.build_request()
response = self.splash_middleware.process_request(request)
self.assertEquals(response, None)
assert response is None
def test_set_non_absolute_url(self):
"""
......@@ -187,7 +189,7 @@ class SplashMiddlewareTestCase(TestCase):
request = self.build_request(url_path='/my/url/')
response = self.splash_middleware.process_request(request)
self.assertEquals(response, None)
assert response is None
def test_unaffected_wildcard_path(self):
"""
......@@ -201,19 +203,19 @@ class SplashMiddlewareTestCase(TestCase):
# These paths match and should NOT redirect.
request = self.build_request(url_path='/test1/')
response = self.splash_middleware.process_request(request)
self.assertEquals(response, None)
assert response is None
request = self.build_request(url_path='/test1/something')
response = self.splash_middleware.process_request(request)
self.assertEquals(response, None)
assert response is None
request = self.build_request(url_path='/test1/something/else')
response = self.splash_middleware.process_request(request)
self.assertEquals(response, None)
assert response is None
request = self.build_request(url_path='/test2/something/after')
response = self.splash_middleware.process_request(request)
self.assertEquals(response, None)
assert response is None
request = self.build_request(url_path='/test3/something/before/something/else/after')
response = self.splash_middleware.process_request(request)
self.assertEquals(response, None)
assert response is None
# These paths don't match and should redirect.
request = self.build_request(url_path='/test2/')
......
[tox]
envlist = {py27,py36}-django{18,111}
[doc8]
max-line-length = 120
[pycodestyle]
exclude = .git,.tox,migrations
max-line-length = 120
[pytest]
DJANGO_SETTINGS_MODULE = test_settings
addopts = --cov splash --cov-report term-missing --cov-report xml
norecursedirs = .* docs requirements
[testenv]
deps =
django18: Django>=1.8,<1.9
django111: Django>=1.11,<2.0
-r{toxinidir}/requirements/test.txt
commands =
py.test {posargs}
[testenv:quality]
whitelist_externals =
make
rm
touch
deps =
-r{toxinidir}/requirements/quality.txt
-r{toxinidir}/requirements/test.txt
commands =
touch tests/__init__.py
pylint splash tests test_utils
pylint --py3k splash tests test_utils
rm tests/__init__.py
isort --check-only --recursive tests test_utils splash manage.py setup.py test_settings.py
make selfcheck
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment