Add pytest-warning to tests and correct some warnings, complete coverage (essentially branch)
This commit is contained in:
parent
b168e0a642
commit
6eea76d984
2
Makefile
2
Makefile
@ -62,7 +62,7 @@ run_server: test_project
|
||||
|
||||
run_tests: test_venv
|
||||
python setup.py check --restructuredtext --stric
|
||||
test_venv/bin/py.test --cov=cas_server --cov-report html
|
||||
test_venv/bin/py.test -rw -x --cov=cas_server --cov-report html
|
||||
rm htmlcov/coverage_html.js # I am really pissed off by those keybord shortcuts
|
||||
|
||||
test_venv/bin/sphinx-build: test_venv
|
||||
|
@ -32,7 +32,7 @@ class BootsrapForm(forms.Form):
|
||||
self[name].checkbox = True
|
||||
else:
|
||||
attrs['class'] = "form-control"
|
||||
if field.label:
|
||||
if field.label: # pragma: no branch (currently all field are hidden or labeled)
|
||||
attrs["placeholder"] = field.label
|
||||
if field.required:
|
||||
attrs["required"] = "required"
|
||||
|
@ -15,7 +15,7 @@
|
||||
<script src="{{settings.CAS_COMPONENT_URLS.respond}}"></script>
|
||||
<![endif]-->
|
||||
<link rel="shortcut icon" href="{% static "cas_server/favicon.ico?v=1" %}" />
|
||||
<link href="{% static "cas_server/login.css" %}" rel="stylesheet">
|
||||
<link href="{% static "cas_server/styles.css" %}" rel="stylesheet">
|
||||
</head>
|
||||
<body>
|
||||
<div class="container">
|
||||
@ -36,18 +36,17 @@
|
||||
{% for message in messages %}
|
||||
<div {% spaceless %}
|
||||
{% if message.level == message_levels.DEBUG %}
|
||||
class="alert alert-warning alert-dismissable"
|
||||
class="alert alert-warning"
|
||||
{% elif message.level == message_levels.INFO %}
|
||||
class="alert alert-info alert-dismissable"
|
||||
class="alert alert-info"
|
||||
{% elif message.level == message_levels.SUCCESS %}
|
||||
class="alert alert-success alert-dismissable"
|
||||
class="alert alert-success"
|
||||
{% elif message.level == message_levels.WARNING %}
|
||||
class="alert alert-warning alert-dismissable"
|
||||
class="alert alert-warning"
|
||||
{% else %}
|
||||
class="alert alert-danger alert-dismissable"
|
||||
class="alert alert-danger"
|
||||
{% endif %}
|
||||
{% endspaceless %}>
|
||||
<button type="button" class="close" data-dismiss="alert" aria-hidden="true">×</button>
|
||||
{{ message }}
|
||||
</div>
|
||||
{% endfor %}
|
||||
|
@ -51,6 +51,22 @@ MIDDLEWARE_CLASSES = [
|
||||
'django.middleware.locale.LocaleMiddleware',
|
||||
]
|
||||
|
||||
TEMPLATES = [
|
||||
{
|
||||
'APP_DIRS': True,
|
||||
'BACKEND': 'django.template.backends.django.DjangoTemplates',
|
||||
'DIRS': [],
|
||||
'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'
|
||||
]
|
||||
}
|
||||
}
|
||||
]
|
||||
|
||||
ROOT_URLCONF = 'cas_server.tests.urls'
|
||||
|
||||
# Database
|
||||
|
@ -60,6 +60,24 @@ class FederatedUserTestCase(TestCase, UserModels, FederatedIendityProviderModel)
|
||||
with self.assertRaises(models.FederatedUser.DoesNotExist):
|
||||
models.FederatedUser.objects.get(username="test2")
|
||||
|
||||
def test_json_attributes(self):
|
||||
"""test the json storage of ``atrributs`` in ``_attributs``"""
|
||||
provider = models.FederatedIendityProvider.objects.get(suffix="example.com")
|
||||
user = models.FederatedUser.objects.create(
|
||||
username=settings.CAS_TEST_USER,
|
||||
provider=provider,
|
||||
attributs=settings.CAS_TEST_ATTRIBUTES,
|
||||
ticket=""
|
||||
)
|
||||
self.assertEqual(utils.json_encode(settings.CAS_TEST_ATTRIBUTES), user._attributs)
|
||||
user.delete()
|
||||
user = models.FederatedUser.objects.create(
|
||||
username=settings.CAS_TEST_USER,
|
||||
provider=provider,
|
||||
ticket=""
|
||||
)
|
||||
self.assertIsNone(user._attributs)
|
||||
self.assertIsNone(user.attributs)
|
||||
|
||||
class FederateSLOTestCase(TestCase, UserModels):
|
||||
"""test for the federated SLO model"""
|
||||
@ -231,3 +249,25 @@ class TicketTestCase(TestCase, UserModels, BaseServicePattern):
|
||||
self.assertTrue(b'logoutRequest' in params and params[b'logoutRequest'])
|
||||
# only 1 ticket remain in the db
|
||||
self.assertEqual(len(models.ServiceTicket.objects.all()), 1)
|
||||
|
||||
def test_json_attributes(self):
|
||||
"""test the json storage of ``atrributs`` in ``_attributs``"""
|
||||
# ge an authenticated client
|
||||
client = get_auth_client()
|
||||
# get the user associated to the client
|
||||
user = self.get_user(client)
|
||||
ticket = models.ServiceTicket.objects.create(
|
||||
user=user,
|
||||
service=self.service,
|
||||
attributs=settings.CAS_TEST_ATTRIBUTES,
|
||||
service_pattern=self.service_pattern
|
||||
)
|
||||
self.assertEqual(utils.json_encode(settings.CAS_TEST_ATTRIBUTES), ticket._attributs)
|
||||
ticket.delete()
|
||||
ticket = models.ServiceTicket.objects.create(
|
||||
user=user,
|
||||
service=self.service,
|
||||
service_pattern=self.service_pattern
|
||||
)
|
||||
self.assertIsNone(ticket._attributs)
|
||||
self.assertIsNone(ticket.attributs)
|
||||
|
@ -12,16 +12,21 @@
|
||||
"""Some utils functions for tests"""
|
||||
from cas_server.default_settings import settings
|
||||
|
||||
import django
|
||||
from django.test import Client
|
||||
from django.template import loader, Context
|
||||
from django.template import loader
|
||||
from django.utils import timezone
|
||||
if django.VERSION < (1, 8):
|
||||
from django.template import Context
|
||||
else:
|
||||
Context = lambda x:x
|
||||
|
||||
import cgi
|
||||
import six
|
||||
from threading import Thread
|
||||
from lxml import etree
|
||||
from six.moves import BaseHTTPServer
|
||||
from six.moves.urllib.parse import urlparse, parse_qsl
|
||||
from six.moves.urllib.parse import urlparse, parse_qsl, parse_qs
|
||||
from datetime import timedelta
|
||||
|
||||
from cas_server import models
|
||||
@ -166,7 +171,7 @@ class HttpParamsHandler(BaseHTTPServer.BaseHTTPRequestHandler):
|
||||
postvars = cgi.parse_multipart(self.rfile, pdict)
|
||||
elif ctype == 'application/x-www-form-urlencoded':
|
||||
length = int(self.headers.get('content-length'))
|
||||
postvars = cgi.parse_qs(self.rfile.read(length), keep_blank_values=1)
|
||||
postvars = parse_qs(self.rfile.read(length), keep_blank_values=1)
|
||||
else:
|
||||
postvars = {}
|
||||
self.server.PARAMS = postvars
|
||||
|
@ -16,8 +16,10 @@ from django.views.decorators.debug import sensitive_post_parameters, sensitive_v
|
||||
|
||||
from cas_server import views
|
||||
|
||||
app_name = "cas_server"
|
||||
|
||||
urlpatterns = [
|
||||
url(r'^$', RedirectView.as_view(pattern_name="cas_server:login")),
|
||||
url(r'^$', RedirectView.as_view(pattern_name="cas_server:login", permanent=False)),
|
||||
url(
|
||||
'^login$',
|
||||
sensitive_post_parameters('password')(
|
||||
|
@ -3,6 +3,7 @@ tox>=1.8.1
|
||||
pytest>=2.6.4
|
||||
pytest-django>=2.8.0
|
||||
pytest-pythonpath>=0.3
|
||||
pytest-warnings
|
||||
pytest-cov>=2.2.1
|
||||
requests>=2.4
|
||||
requests_futures>=0.9.5
|
||||
|
2
setup.py
2
setup.py
@ -66,5 +66,5 @@ if __name__ == '__main__':
|
||||
download_url="https://github.com/nitmir/django-cas-server/releases",
|
||||
zip_safe=False,
|
||||
setup_requires=['pytest-runner'],
|
||||
tests_require=['pytest', 'pytest-django', 'pytest-pythonpath'],
|
||||
tests_require=['pytest', 'pytest-django', 'pytest-pythonpath', 'pytest-warnings', 'mock>=1'],
|
||||
)
|
||||
|
Loading…
Reference in New Issue
Block a user