Skip to content
This repository has been archived by the owner on Jul 21, 2021. It is now read-only.

Commit

Permalink
Merge 7162d76 into 70d9cbd
Browse files Browse the repository at this point in the history
  • Loading branch information
lambdalisue committed Mar 25, 2017
2 parents 70d9cbd + 7162d76 commit 53bfbef
Show file tree
Hide file tree
Showing 38 changed files with 312 additions and 507 deletions.
8 changes: 6 additions & 2 deletions docs/conf.py
Expand Up @@ -20,7 +20,7 @@
BASE_DIR = os.path.dirname(os.path.dirname(__file__))
sys.path.insert(0, os.path.join(BASE_DIR, 'src'))
sys.path.insert(0, os.path.join(BASE_DIR, 'tests'))
os.environ['DJANGO_SETTINGS_MODULE'] = 'settings'
os.environ['DJANGO_SETTINGS_MODULE'] = 'tests.settings'


# -- General configuration -----------------------------------------------------
Expand All @@ -30,7 +30,11 @@

# Add any Sphinx extension module names here, as strings. They can be extensions
# coming with Sphinx (named 'sphinx.ext.*') or your custom ones.
extensions = ['sphinx.ext.autodoc', 'numpydoc', 'sphinx.ext.viewcode']
extensions = [
'sphinx.ext.autodoc',
'sphinc.ext.napoleon',
'sphinx.ext.viewcode',
]

# Add any paths that contain templates here, relative to this directory.
templates_path = ['_templates']
Expand Down
40 changes: 16 additions & 24 deletions manage.py
@@ -1,30 +1,22 @@
# coding=utf-8
"""
Django 1.2 - 1.6 compatible manage.py
Modify this script to make your own manage.py
"""
__author__ = 'Alisue <lambdalisue@hashnote.net>'
#!/usr/bin/env python
import os
import sys


if __name__ == '__main__':
# add extra sys.path
root = os.path.abspath(os.path.dirname(__file__))
extra_paths = (root, os.path.join(root, 'src'))
for extra_path in extra_paths:
if extra_path in sys.path:
sys.path.remove(extra_path)
sys.path.insert(0, extra_path)
# set DJANGO_SETTINGS_MODULE
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'tests.settings')

if __name__ == "__main__":
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "tests.settings")
try:
# django 1.4 and above
# https://docs.djangoproject.com/en/1.4/releases/1.4/
from django.core.management import execute_from_command_line
execute_from_command_line(sys.argv)
except ImportError:
from django.core.management import execute_manager
settings = __import__(os.environ['DJANGO_SETTINGS_MODULE'])
execute_manager(settings)
# 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
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)
2 changes: 0 additions & 2 deletions requirements-docs.txt
@@ -1,3 +1 @@
sphinx
numpydoc
sphinx_rtd_theme
3 changes: 1 addition & 2 deletions requirements-test.txt
@@ -1,2 +1 @@
django-override-settings
mock
mock; python_version < '3.3'
41 changes: 0 additions & 41 deletions runtests.py

This file was deleted.

31 changes: 14 additions & 17 deletions setup.py
@@ -1,9 +1,8 @@
# coding=utf-8
import sys
from setuptools import setup, find_packages

NAME = 'django-permission'
VERSION = '0.9.3'
VERSION = '1.0.0'


def read(filename):
Expand All @@ -19,21 +18,21 @@ def readlist(filename):
rows = [x.strip() for x in rows if x.strip()]
return list(rows)


setup(
name=NAME,
version=VERSION,
description=('A enhanced permission system which enable logical permission'
'systems to complex permissions'),
long_description = read('README.rst'),
classifiers = (
long_description=read('README.rst'),
classifiers=(
'Development Status :: 5 - Production/Stable',
'Environment :: Web Environment',
'Framework :: Django',
'Intended Audience :: Developers',
'License :: OSI Approved :: MIT License',
'Programming Language :: Python',
'Programming Language :: Python :: 2',
'Programming Language :: Python :: 2.6',
'Programming Language :: Python :: 2.7',
'Programming Language :: Python :: 3',
'Programming Language :: Python :: 3.3',
Expand All @@ -44,23 +43,21 @@ def readlist(filename):
'Topic :: Software Development :: Libraries :: Application Frameworks',
'Topic :: Software Development :: Libraries :: Python Modules',
),
keywords = 'django object logical permission auth authentication',
author = 'Alisue',
author_email = 'lambdalisue@hashnote.net',
url = 'https://github.com/lambdalisue/%s' % NAME,
download_url = 'https://github.com/lambdalisue/%s/tarball/master' % NAME,
license = 'MIT',
packages = find_packages('src'),
package_dir = {'': 'src'},
include_package_data = True,
package_data = {
keywords='django object logical permission auth authentication',
author='Alisue',
author_email='lambdalisue@hashnote.net',
url='https://github.com/lambdalisue/%s' % NAME,
download_url='https://github.com/lambdalisue/%s/tarball/master' % NAME,
license='MIT',
packages=find_packages('src'),
package_dir={'': 'src'},
include_package_data=True,
package_data={
'': ['README.rst',
'requirements.txt',
'requirements-test.txt',
'requirements-docs.txt'],
},
zip_safe=True,
install_requires=readlist('requirements.txt'),
test_suite='runtests.run_tests',
tests_require=readlist('requirements-test.txt'),
)
12 changes: 0 additions & 12 deletions src/permission/compat.py
@@ -1,16 +1,4 @@
# coding=utf-8
try:
import collections
def isiterable(x):
return isinstance(x, collections.Iterable)
except ImportError:
def isiterable(x):
try:
iter(x)
return True
except TypeError:
return False

import django
if django.VERSION >= (1, 9):
add_to_builtins = None
Expand Down
10 changes: 0 additions & 10 deletions src/permission/tests/__init__.py
@@ -1,10 +0,0 @@
import django
if django.VERSION < (1, 6):
# Django 1.5 and earlier use a different test method and the followings
# are required to be exposed
from permission.tests.test_backends import *
from permission.tests.test_handlers import *
from permission.tests.test_utils import *
from permission.tests.test_logics import *
from permission.tests.test_decorators import *
from permission.tests.test_templatetags import *
6 changes: 1 addition & 5 deletions src/permission/tests/compat.py
@@ -1,14 +1,10 @@
# coding=utf-8
try:
# Python 3 have mock in unittest
from unittest.mock import MagicMock
except ImportError:
from mock import MagicMock

try:
from django.test.utils import override_settings
except ImportError:
from override_settings import override_settings
from django.test import override_settings

try:
from unittest import skipIf
Expand Down
5 changes: 3 additions & 2 deletions src/permission/tests/models.py
@@ -1,11 +1,12 @@
# coding=utf-8
from __future__ import unicode_literals
from django.db import models
from django.conf import settings
from permission.tests.compat import python_2_unicode_compatible
from django.utils.encoding import python_2_unicode_compatible


AUTH_USER = getattr(settings, 'AUTH_USER_MODEL', 'auth.User')


@python_2_unicode_compatible
class Article(models.Model):
title = models.CharField('title', max_length=200)
Expand Down
15 changes: 6 additions & 9 deletions src/permission/tests/test_backends.py
@@ -1,13 +1,10 @@
# coding=utf-8
from django.test import TestCase
from django.test import TestCase, override_settings
from django.core.exceptions import ObjectDoesNotExist
from permission.backends import PermissionBackend
from permission.utils.handlers import registry
from permission.tests.utils import create_user
from permission.tests.utils import create_article
from permission.tests.models import Article
from permission.tests.compat import MagicMock
from permission.tests.compat import override_settings
from ..backends import PermissionBackend
from ..utils.handlers import registry
from .compat import MagicMock
from .utils import create_user, create_article
from .models import Article


@override_settings(
Expand Down
8 changes: 0 additions & 8 deletions src/permission/tests/test_decorators/__init__.py
@@ -1,8 +0,0 @@
import django
if django.VERSION < (1, 6):
# Django 1.5 and earlier use a different test method and the followings
# are required to be exposed
from permission.tests.test_decorators.test_functionbase import *
from permission.tests.test_decorators.test_methodbase import *
from permission.tests.test_decorators.test_classbase import *
from permission.tests.test_decorators.test_permission_required import *
41 changes: 17 additions & 24 deletions src/permission/tests/test_decorators/test_classbase.py
@@ -1,25 +1,18 @@
# coding=utf-8
"""
"""
__author__ = 'Alisue <lambdalisue@hashnote.net>'
import django
from django.test import TestCase
from django.core.exceptions import PermissionDenied
from permission.utils.handlers import registry
from permission.decorators.classbase import permission_required
from permission.tests.compat import skipIf
from permission.tests.compat import MagicMock
from permission.tests.test_decorators.utils import create_mock_handler
from permission.tests.test_decorators.utils import create_mock_request
from permission.tests.test_decorators.utils import create_mock_queryset
from permission.tests.test_decorators.utils import create_mock_model
from permission.tests.test_decorators.utils import create_mock_view_func
from permission.tests.test_decorators.utils import create_mock_view_class


@skipIf(
django.VERSION < (1, 3),
'Classbased generic view is not supported in this version')
from ...utils.handlers import registry
from ...decorators.classbase import permission_required
from ..compat import MagicMock
from .utils import (
create_mock_handler,
create_mock_request,
create_mock_queryset,
create_mock_model,
create_mock_view_func,
create_mock_view_class,
)


class PermissionClassDecoratorsTestCase(TestCase):
def setUp(self):
self.handler = create_mock_handler()
Expand Down Expand Up @@ -75,7 +68,7 @@ def test_with_object(self):

self.assertRaises(PermissionDenied,
self.view_class_exc.as_view(),
self.request,
self.request,
pk=1)
self.assertFalse(self.view_func.called)

Expand Down Expand Up @@ -113,7 +106,7 @@ def test_with_get_object(self):

self.assertRaises(PermissionDenied,
self.view_class_exc.as_view(),
self.request,
self.request,
pk=1)
self.assertFalse(self.view_func.called)

Expand Down Expand Up @@ -152,7 +145,7 @@ def test_with_queryset(self):

self.assertRaises(PermissionDenied,
self.view_class_exc.as_view(),
self.request,
self.request,
pk=1)
self.assertFalse(self.view_func.called)

Expand Down Expand Up @@ -193,7 +186,7 @@ def test_with_get_queryset(self):

self.assertRaises(PermissionDenied,
self.view_class_exc.as_view(),
self.request,
self.request,
pk=1)
self.assertFalse(self.view_func.called)

Expand Down

0 comments on commit 53bfbef

Please sign in to comment.