-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
220 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
# top-most EditorConfig file | ||
root = true | ||
|
||
[*] | ||
end_of_line = lf | ||
insert_final_newline = true | ||
charset = utf-8 | ||
trim_trailing_whitespace = true | ||
indent_style = space | ||
indent_size = 4 | ||
|
||
# HTML: 2 spaces | ||
[*.html] | ||
indent_size = 2 | ||
|
||
# SCSS: 2 spaces | ||
[*.scss] | ||
indent_size = 2 | ||
|
||
# JS : 2 spaces | ||
[*.js] | ||
indent_size = 2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,3 +9,5 @@ _build | |
build | ||
dist | ||
venv | ||
htmlcov | ||
.coverage |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,15 @@ | ||
language: python | ||
sudo: false | ||
python: | ||
- "3.4" | ||
- "2.7" | ||
- "3.5" | ||
env: | ||
- REQ="Django>=1.8,<1.9" | ||
- REQ="Django>=1.9,<1.10" | ||
- REQ="Django>=1.10,<1.11" | ||
- REQ="Django>=1.11,<2.0" | ||
# command to install dependencies, e.g. pip install -r requirements.txt --use-mirrors | ||
install: | ||
- pip install -q $REQ towel==0.8.0 --use-mirrors | ||
- python setup.py -q install | ||
- pip install $REQ pytz requests_oauthlib | ||
- python setup.py install | ||
# command to run tests, e.g. python setup.py test | ||
script: "cd tests && ./manage.py test testapp" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
#!/bin/sh | ||
venv/bin/coverage run --branch --include="*authlib/*" --omit="*tests*" ./manage.py test -v 2 testapp | ||
venv/bin/coverage html |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
#!/usr/bin/env python | ||
import os | ||
import sys | ||
from os.path import abspath, dirname | ||
|
||
|
||
if __name__ == "__main__": | ||
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "testapp.settings") | ||
|
||
sys.path.insert(0, dirname(dirname(abspath(__file__)))) | ||
|
||
from django.core.management import execute_from_command_line | ||
|
||
execute_from_command_line(sys.argv) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
Django | ||
pytz | ||
coverage | ||
requests_oauthlib |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
import os | ||
import warnings | ||
|
||
SITE_ID = 1 | ||
|
||
DATABASES = { | ||
'default': { | ||
'ENGINE': 'django.db.backends.sqlite3', | ||
'NAME': ':memory:', | ||
} | ||
} | ||
|
||
INSTALLED_APPS = [ | ||
'django.contrib.auth', | ||
'django.contrib.contenttypes', | ||
'django.contrib.sessions', | ||
'django.contrib.staticfiles', | ||
'django.contrib.messages', | ||
'testapp', | ||
'authlib', | ||
'authlib.admin_oauth', | ||
'authlib.little_auth', | ||
'django.contrib.admin', | ||
] | ||
|
||
MEDIA_ROOT = '/media/' | ||
STATIC_URL = '/static/' | ||
BASEDIR = os.path.dirname(__file__) | ||
MEDIA_ROOT = os.path.join(BASEDIR, 'media/') | ||
STATIC_ROOT = os.path.join(BASEDIR, 'static/') | ||
SECRET_KEY = 'supersikret' | ||
LOGIN_REDIRECT_URL = '/?login=1' | ||
|
||
ROOT_URLCONF = 'testapp.urls' | ||
LANGUAGES = (('en', 'English'),) | ||
|
||
TEMPLATES = [ | ||
{ | ||
'BACKEND': 'django.template.backends.django.DjangoTemplates', | ||
'DIRS': [], | ||
'APP_DIRS': True, | ||
'OPTIONS': { | ||
'context_processors': [ | ||
'django.template.context_processors.debug', | ||
'django.template.context_processors.request', | ||
'django.contrib.auth.context_processors.auth', | ||
'django.contrib.messages.context_processors.messages', | ||
], | ||
}, | ||
}, | ||
] | ||
|
||
MIDDLEWARE_CLASSES = MIDDLEWARE = [ | ||
'django.middleware.security.SecurityMiddleware', | ||
'django.contrib.sessions.middleware.SessionMiddleware', | ||
'django.middleware.common.CommonMiddleware', | ||
'django.middleware.locale.LocaleMiddleware', | ||
'django.middleware.csrf.CsrfViewMiddleware', | ||
'django.contrib.auth.middleware.AuthenticationMiddleware', | ||
'django.contrib.messages.middleware.MessageMiddleware', | ||
'django.middleware.clickjacking.XFrameOptionsMiddleware', | ||
] | ||
# Do not warn about MIDDLEWARE_CLASSES | ||
SILENCED_SYSTEM_CHECKS = ['1_10.W001'] | ||
|
||
try: | ||
# We do not yet care about those. | ||
from django.utils.deprecation import RemovedInDjango21Warning | ||
|
||
warnings.simplefilter('ignore', RemovedInDjango21Warning) | ||
except ImportError: # pragma: no cover | ||
pass | ||
|
||
AUTH_USER_MODEL = 'little_auth.User' | ||
GOOGLE_CLIENT_ID = 'empty' | ||
GOOGLE_CLIENT_SECRET = 'empty' | ||
TWITTER_CLIENT_ID = 'empty' | ||
TWITTER_CLIENT_SECRET = 'empty' | ||
FACEBOOK_CLIENT_ID = 'empty' | ||
FACEBOOK_CLIENT_SECRET = 'empty' | ||
ADMIN_OAUTH_PATTERNS = [ | ||
(r'@example\.com', 'admin@example.com'), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{% extends "base.html" %} | ||
|
||
{% block content %} | ||
<h1>Page not found</h1> | ||
{% endblock %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<!DOCTYPE HTML> | ||
<html> | ||
<head> | ||
<title>{% block title %}testapp{% endblock %}</title> | ||
</head> | ||
<body> | ||
{% if messages %} | ||
<ul class="messages"> | ||
{% for message in messages %} | ||
<li{% if message.tags %} class="{{ message.tags }}"{% endif %}>{{ message }}</li> | ||
{% endfor %} | ||
</ul> | ||
{% endif %} | ||
{% block content %}{% endblock %} | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
from django.test import Client, TestCase | ||
from django.utils.translation import deactivate_all | ||
|
||
from authlib.little_auth.models import User | ||
|
||
|
||
def zero_management_form_data(prefix): | ||
return { | ||
'%s-TOTAL_FORMS' % prefix: 0, | ||
'%s-INITIAL_FORMS' % prefix: 0, | ||
'%s-MIN_NUM_FORMS' % prefix: 0, | ||
'%s-MAX_NUM_FORMS' % prefix: 1000, | ||
} | ||
|
||
|
||
def merge_dicts(*dicts): | ||
res = {} | ||
for d in dicts: | ||
res.update(d) | ||
return res | ||
|
||
|
||
class Test(TestCase): | ||
def setUp(self): | ||
self.user = User.objects.create_superuser( | ||
'admin@example.com', 'blabla') | ||
deactivate_all() | ||
|
||
def login(self): | ||
client = Client() | ||
client.force_login(self.user) | ||
return client | ||
|
||
def test_admin_oauth(self): | ||
client = Client() | ||
|
||
response = client.get('/admin/login/?next=/admin/little_auth/') | ||
self.assertContains( | ||
response, | ||
'<a href="/admin/__oauth__/?next=/admin/little_auth/">' | ||
'Log in using SSO</a>' | ||
) | ||
|
||
response = client.get('/admin/__oauth__/?next=/admin/little_auth/') | ||
self.assertEqual(response.status_code, 302) | ||
self.assertIn( | ||
'https://accounts.google.com/o/oauth2/v2/auth?response_type=code' | ||
'&client_id=empty&redirect_uri=', | ||
response['Location'], | ||
) | ||
self.assertEqual( | ||
client.session['admin-oauth-next'], | ||
'/admin/little_auth/', | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
from django.conf.urls import include, url | ||
from django.contrib import admin | ||
from django.shortcuts import render | ||
|
||
|
||
urlpatterns = [ | ||
url(r'', include('authlib.admin_oauth.urls')), | ||
url(r'^admin/', admin.site.urls), | ||
url(r'^404/$', lambda request: render(request, '404.html')), | ||
] |