Skip to content

Commit

Permalink
Update test matrix and dependencies (#17)
Browse files Browse the repository at this point in the history
- Bump test dependencies
- README formatting
- Use twine and 3-suffixed commands in make distribute
- Move test requirements into setup.py
  • Loading branch information
antonagestam committed Feb 2, 2020
1 parent 1649615 commit ebe7746
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 29 deletions.
13 changes: 4 additions & 9 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
language: python
install:
- pip install -r test-requirements.txt
- pip install -q Django==$DJANGO_VERSION
- pip install .[test]
script:
- make lint
- make test-coverage
Expand All @@ -12,14 +12,9 @@ dist: xenial
notifications:
email: false
python:
- "3.4"
- "3.5"
- "3.6"
- "3.7"
- "3.8"
env:
- DJANGO_VERSION=2.0
- DJANGO_VERSION=2.1
matrix:
exclude:
- python: "3.4"
env: DJANGO_VERSION=2.1
- DJANGO_VERSION=2.2
- DJANGO_VERSION=3.0
15 changes: 12 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
.PHONY: test lint test-coverage coveralls
.PHONY: test lint test-coverage coveralls install-test-requirements distribute
SHELL := /usr/bin/env bash

test:
python runtests.py
python3 runtests.py

install-test-requirements:
python3 -m pip install -e .[test]

lint:
flake8 .
Expand All @@ -12,5 +16,10 @@ test-coverage:
coveralls:
coveralls

clean:
rm -rf django_access_tools.egg-info __pycache__ build dist

distribute:
python setup.py sdist bdist_wheel upload
python3 -m pip install --upgrade wheel twine setuptools
python3 setup.py sdist bdist_wheel
twine upload dist/*
29 changes: 18 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
[![Build Status](https://travis-ci.org/antonagestam/django-access-tools.svg?branch=master)](https://travis-ci.org/antonagestam/django-access-tools)
[![Coverage Status](https://coveralls.io/repos/antonagestam/django-access-tools/badge.svg?service=github)](https://coveralls.io/github/antonagestam/django-access-tools?branch=coverage)

A tidy and extendable way of defining access requirements for views. Because mixins and decorators gets messy.
A tidy and extendable way of defining access requirements for views. Because
mixins and decorators gets messy.

## Installation

Expand Down Expand Up @@ -44,9 +45,11 @@ class LoggedIn(Requirement):

__`Requirement.request`:__ Request object. Gets set by `Requirement.setup`.

__`Requirement.args`:__ Request arguments passed to the view. Gets set by `Requirement.setup`.
__`Requirement.args`:__ Request arguments passed to the view. Gets set by
`Requirement.setup`.

__`Requirement.kwargs`:__ Request keyword arguments passed to the view. Gets set by `Requirement.setup`.
__`Requirement.kwargs`:__ Request keyword arguments passed to the view. Gets set
by `Requirement.setup`.


### Views
Expand All @@ -63,7 +66,8 @@ events before the view is executed:

#### Class-based Views

Extend your views with `ManagedAccessViewMixin` and specify `access_requirements`:
Extend your views with `ManagedAccessViewMixin` and specify
`access_requirements`:

```python
from django.views.generic import TemplateView
Expand Down Expand Up @@ -107,15 +111,18 @@ __`PageNotFoundRequirement(Requirement)`:__ Raises `Http404()` if unfulfilled.

__`Staff(PageNotFoundRequirement)`:__ Raises `Http404()` if user is not staff.

__`SuperUser(PageNotFoundRequirement)`:__ Raises `Http404()` if user is not superuser.
__`SuperUser(PageNotFoundRequirement)`:__ Raises `Http404()` if user is not
superuser.

__`Active(PageNotFoundRequirement)`:__ Raises `Http404()` if user is not active.

__`RedirectRequirement(Requirement)`:__ Returns `Http307(self.get_url())` if not fulfilled.
Specify `url_name` or override `get_url` to set URL to redirect to. Appends the current URL
as ?next=current_url by default, set `append_next = False` to prevent this.
__`RedirectRequirement(Requirement)`:__ Returns `Http307(self.get_url())` if not
fulfilled. Specify `url_name` or override `get_url` to set URL to redirect to.
Appends the current URL as ?next=current_url by default, set `append_next =
False` to prevent this.

__`LoggedIn(RedirectRequirement)`:__ Returns `Http307('login')` if user is not authenticated.
__`LoggedIn(RedirectRequirement)`:__ Returns `Http307('login')` if user is not
authenticated.


### More Advanced Usage Example
Expand Down Expand Up @@ -159,15 +166,15 @@ class ConfirmedEmail(ProfileFieldRequirement):
url_name = 'prompt_email'
profile_field_name = 'confirmed_email'

# in your views.py:
# ... in your views.py:

from access.views import ManagedAccessViewMixin


class MyView(ManagedAccessViewMixin, View):
access_requirements = [AcceptedTerms, ConfirmedEmail]

# view code
# ... view code

```

Expand Down
7 changes: 4 additions & 3 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,10 @@
author='Anton Agestam',
author_email="msn@antonagestam.se",
url='http://antonagestam.github.io/django-access-tools',
install_requires=[
'Django>=2.0',
],
install_requires=['Django>=2.0'],
extras_require={
"test": ["factory-boy<3", "flake8<4", "coveralls<2"],
},
description='An abstract access manager for Django.',
packages=find_packages(),
include_package_data=True,
Expand Down
3 changes: 0 additions & 3 deletions test-requirements.txt

This file was deleted.

0 comments on commit ebe7746

Please sign in to comment.