Commit 68d34438 authored by Daniel Klaffenbach's avatar Daniel Klaffenbach 🐍

Add testcases

parent 0749cc51
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<?eclipse-pydev version="1.0"?><pydev_project>
<pydev_property name="org.python.pydev.PYTHON_PROJECT_INTERPRETER">django18</pydev_property>
<pydev_property name="org.python.pydev.PYTHON_PROJECT_VERSION">python 2.7</pydev_property>
<pydev_pathproperty name="org.python.pydev.PROJECT_SOURCE_PATH">
<path>/${PROJECT_DIR_NAME}</path>
</pydev_pathproperty>
</pydev_project>
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
import os
import sys
import django
from django.conf import settings
from django.test.utils import get_runner
if __name__ == "__main__":
os.environ['DJANGO_SETTINGS_MODULE'] = 'tests.test_settings'
django.setup()
TestRunner = get_runner(settings)
test_runner = TestRunner()
failures = test_runner.run_tests(["tests"])
sys.exit(bool(failures))
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
AUTHENTICATION_BACKENDS = [
'django.contrib.auth.backends.RemoteUserBackend',
]
CACHES = {
'default': {
'BACKEND': 'django.core.cache.backends.dummy.DummyCache',
}
}
DATABASES = {
'default': {'ENGINE': 'django.db.backends.sqlite3'}
}
INSTALLED_APPS = (
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'fountain',
'tests'
)
MIDDLEWARE_CLASSES = (
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.auth.middleware.SessionAuthenticationMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.auth.middleware.RemoteUserMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
'django.middleware.security.SecurityMiddleware',
)
ROOT_URLCONF = 'tests.urls'
SECRET_KEY = 'fake-key'
STATIC_URL = '/static/'
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.core import management
from django.contrib.auth import get_user_model
from django.test import Client, TestCase
class LdapTestCase(TestCase):
def setUp(self):
self.USER_MODEL = get_user_model()
self.client = Client(REMOTE_USER='otto')
def test_sync_attributes(self):
"""
Testet, ob die Attribute des Nuters "otto" beim Anlegen
aus dem LDAP gelesen werden.
@attention: TUC-specific
"""
user = self.USER_MODEL.objects.create(username='otto')
self.assertEquals(user.first_name, 'Otto')
self.assertEquals(user.last_name, 'Normalverbraucher')
self.assertNotEqual(user.email, '')
user = self.USER_MODEL.objects.get(username='otto')
self.assertEquals(user.first_name, 'Otto')
self.assertEquals(user.last_name, 'Normalverbraucher')
self.assertNotEqual(user.email, '')
def test_autocreate(self):
response = self.client.get('/admin/')
self.assertEquals(response.status_code, 302)
user = self.USER_MODEL.objects.get(username='otto')
self.assertEquals(user.first_name, 'Otto')
self.assertEquals(user.last_name, 'Normalverbraucher')
self.assertNotEqual(user.email, '')
def test_management_command(self):
self.USER_MODEL.objects.create(username='otto')
# Clear user attributes for this test
self.USER_MODEL.objects.all().update(first_name='', last_name='', email='')
user = self.USER_MODEL.objects.get(username='otto')
self.assertEquals(user.first_name, '')
self.assertEquals(user.last_name, '')
self.assertEquals(user.email, '')
# Now run management command to test if sync is working
management.call_command('ldap_sync')
user = self.USER_MODEL.objects.get(username='otto')
self.assertEquals(user.first_name, 'Otto')
self.assertEquals(user.last_name, 'Normalverbraucher')
self.assertNotEqual(user.email, '')
\ No newline at end of file
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.conf.urls import include, url
from django.contrib import admin
urlpatterns = [
url(r'^admin/', include(admin.site.urls)),
]
\ No newline at end of file
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment