-
Notifications
You must be signed in to change notification settings - Fork 23
/
Copy pathsetup.py
212 lines (179 loc) · 7.44 KB
/
setup.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# Copyright 2016 The Johns Hopkins University Applied Physics Laboratory
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import os
import sys
from setuptools import setup, find_packages, Command
from setuptools.command.test import test as TestCommand
here = os.path.abspath(os.path.dirname(__file__))
def read(filename):
with open(os.path.join(here, filename), 'r') as fh:
return fh.read()
def test_suite():
"""Define the tests that should be run
Providing a custom test suite so that url.py is not imported,
as importing it makes django-oidc try to connect to Keycloak
Returns:
TestSuite
"""
import unittest
loader = unittest.TestLoader()
suite = loader.discover('tests', pattern='test_*.py')
return suite
class DjangoMixin(object):
"""Mixin that enables calling Django commands"""
def django_configure(self):
"""Provide Django a minimal configuration needed for running tests
This method doesn't set any bossoidc settings
"""
import django
from django.conf import settings
if not settings.configured:
settings.configure(
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': ':memory:',
}
},
INSTALLED_APPS = (
'django.contrib.contenttypes',
'django.contrib.auth',
'django.contrib.sites',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.admin.apps.SimpleAdminConfig',
'django.contrib.staticfiles',
'bossoidc',
'djangooidc',
),
MIDDLEWARE_CLASSES = (
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
),
ROOT_URLCONF = 'tests.urls',
ALLOWED_HOSTS = ['testserver'],
AUTHENTICATION_BACKENDS = [
'bossoidc.backend.OpenIdConnectBackend',
],
REST_FRAMEWORK = {
'DEFAULT_AUTHENTICATION_CLASSES': (
#'rest_framework.authentication.SessionAuthentication',
'oidc_auth.authentication.BearerTokenAuthentication',
),
},
)
django.setup()
def django_migrate(self):
"""Call the Django manage.py migrate command to populate the test database"""
from django.core.management import call_command
call_command('migrate', interactive=False)
def django_makemigrations(self):
"""Call the Django mange.py makemigrations bossoidc command to create
new migrations
"""
from django.core.management import call_command
# Called as interactive because making migrations may require the developer
# to make decisions (like a default value for a non-null field)
call_command('makemigrations', 'bossoidc')
# Inspired by the example at https://pytest.org/latest/goodpractises.html
class DjangoTestCommand(TestCommand, DjangoMixin):
def run_tests(self):
# Move into the current directory, so results are saved where we want
curdir = os.path.dirname(os.path.realpath(__file__))
os.chdir(curdir)
# Add current directory to path so imports work
sys.path.insert(0, curdir)
# Start coverage tracing
import coverage
cov = coverage.Coverage(source=["bossoidc"],
omit=["bossoidc/admin.py"])
# Since admin.py is used by the Django admin pages
# there are no tests written for it
cov.start()
# Configure Django to support the tests
# Called after starting coverage to track migration coverage
self.django_configure()
self.django_migrate()
# Run unit tests
super(DjangoTestCommand, self).run_tests()
# Stop coverage tracing
cov.stop()
#cov.save()
# Display the coverage report
cov.report()
class MakeMigrationsCommand(Command, DjangoMixin):
description = 'Run Django makemigrations'
user_options = [
# The format is (long option, short option, description).
]
def initialize_options(self):
"""Abstract method that is required to be overwritten"""
def finalize_options(self):
"""Abstract method that is required to be overwritten"""
def run(self):
self.django_configure()
self.django_makemigrations()
if __name__ == '__main__':
setup(
name='boss-oidc',
version='1.2.2',
packages=find_packages(),
url='https://github.com/jhuapl-boss/boss-oidc',
license="Apache Software License",
author='Derek Pryor',
author_email='[email protected]',
description='Django Authentication OpenID Connect plugin for the Boss SSO',
long_description=read('README.md'),
install_requires = [
'django<2.0',
'djangorestframework',
'oic==0.13.0', # Pinned due to issues with the library
'pyjwkest>=1.0.0',
#'django-oidc@http://github.com/jhuapl-boss/django-oidc/archive/master.zip',
#'drf-oidc-auth@http://github.com/jhuapl-boss/drf-oidc-auth/archive/master.zip'
],
# TODO pin versions of django-oidc / drf-oidc-auth
# Depdency Links are deprecated but full support for PEP 508 isn't expected
# until version 10. Commented links in install_requires are the PEP 508 format
dependency_links = [
'git+http://github.com/jhuapl-boss/django-oidc.git#egg=django-oidc',
'git+http://github.com/jhuapl-boss/drf-oidc-auth.git#egg=drf-oidc-auth',
],
tests_require = [
'coverage',
'requests_mock',
'pyjwt',
],
test_suite = 'setup.test_suite',
classifiers=[
'Environment :: Web Environment',
'Development Status :: 5 - Production',
'Framework :: Django',
'Intended Audience :: Developers',
'License :: OSI Approved :: Apache Software License',
'Operating System :: OS Independent',
'Natural Language :: English',
'Programming Language :: Python :: 3',
'Programming Language :: Python :: 3.5',
],
cmdclass = {
'test': DjangoTestCommand,
'makemigrations': MakeMigrationsCommand,
},
)