Sergey Maranchuk avatar Sergey Maranchuk committed cd81cae

tests refactoring, settings added. issue #8

Comments (0)

Files changed (6)

openauth/tests.py

-import re
-
-from django.core.urlresolvers import reverse
-from django.contrib.auth.models import User
-from django.test import Client, TestCase
-from django.conf import settings
-
-import notify
-import openauth
-from openauth import views
-from openauth import forms
-
-EMAIL_REGEX = re.compile(
-    r"(^[-!#$%&'*+/=?^_`{}|~0-9A-Z]+(\.[-!#$%&'*+/=?^_`{}|~0-9A-Z]+)*"  # dot-atom
-    r'|^"([\001-\010\013\014\016-\037!#-\[\]-\177]|\\[\001-011\013\014\016-\177])*"' # quoted-string
-    r')@(?:[A-Z0-9-]+\.)+[A-Z]{2,6}$', re.IGNORECASE)
-
-USER_REGEX = re.compile(r"[a-z0-9][_a-z0-9]*[a-z0-9]$", re.I)
-
-class RegistrationTest(TestCase):
-
-    def setUp(self):
-        openauth.settings.REGISTRATION_ALLOWED = True
-        openauth.settings.USERNAME_REGEX = USER_REGEX
-        openauth.settings.REGISTRATION_FORM = "openauth.forms.RegistrationForm"
-        self.client = Client()
-        self.registration_url = reverse('openauth-registration')
-
-    def test_registration(self):
-        response = self.client.post(self.registration_url, {'username': 'petya', 'email': 'admin@example.com', 'password': 'test', 'password_dup': 'test'}) 
-        user = User.objects.get(email='admin@example.com')
-        self.failUnlessEqual(user.username, 'petya')
-
-    def test_disabled_registration(self):
-        openauth.settings.REGISTRATION_ALLOWED = False
-        response = self.client.post(self.registration_url, {'username': 'petya', 'email': 'admin@example.com', 'password': 'test', 'password_dup': 'test'}) 
-        self.failUnlessRaises(User.DoesNotExist, User.objects.get, username='petya')
-
-
-class LoginTest(TestCase):
-
-    def setUp(self):
-        notify.settings.NOTIFY_TYPE = 'flashcookie'
-        openauth.settings.REGISTRATION_ALLOWED = True
-        openauth.settings.ACTIVATION_REQUIRED = True
-        openauth.settings.USERNAME_REGEX = USER_REGEX
-        openauth.settings.AUTHENTICATION_TYPES = ['username']
-        self.client = Client()
-        self.login_url = reverse('openauth-login')
-        self.active_user = User.objects.create_user('ivan', 'ivan@example.com', password='test')
-        self.inactive_user = User.objects.create_user('vova', 'vova@example.com', password='test')
-        self.inactive_user.is_active = False
-        self.inactive_user.save()
-
-    def tearDown(self):
-        self.active_user.delete()
-        self.inactive_user.delete()
-
-    def test_valid_active_user_activation_enabled(self):
-        response = self.client.post(self.login_url, {'username': self.active_user.username, 'password': 'test'})
-        self.assertRedirects(response, openauth.settings.LOGIN_REDIRECT_URL)
-
-    def test_invalid_active_user_activation_enabled(self):
-        response = self.client.post(self.login_url, {'username': self.active_user.username, 'password': 'INCORRECT'})
-        self.assertEqual(response.status_code, 200) #not redirect to LOGIN_REDIRECT_URL
-
-    def test_inactive_user_activation_enabled(self):
-        response = self.client.post(self.login_url, {'username': self.inactive_user.username, 'password': 'test'})
-        self.assertEqual(response.status_code, 200)
-
-    def test_inactive_user_activation_disabled(self):
-        openauth.settings.ACTIVATION_REQUIRED = False
-        response = self.client.post(self.login_url, {'username': self.inactive_user.username, 'password': 'test'})
-        self.assertRedirects(response, openauth.settings.LOGIN_REDIRECT_URL)
Add a comment to this file

openauth/tests/__init__.py

Empty file added.

Add a comment to this file

openauth/tests/models.py

Empty file added.

openauth/tests/settings.py

+DEBUG = True
+DATABASE_ENGINE = 'sqlite3'
+
+ROOT_URLCONF = 'openauth.urls'
+
+INSTALLED_APPS = (
+    'django.contrib.admin',
+    'django.contrib.auth',
+    'django.contrib.contenttypes',
+    'django.contrib.sessions',
+    'django.contrib.sites',
+    'confirmation',
+    'notify',
+    'openauth',
+    'openauth.tests'
+)
+SECRET_KEY = '-oy*asd55p(+&5-(=-z0aajy&sdfkjsdfjg723)$c^xom8-j))'
+
+SITE_ID = 1
+
+AUTHENTICATION_BACKENDS = (
+    'django.contrib.auth.backends.ModelBackend',
+    'openauth.backends.OpenIDBackend',
+)
+
+TEMPLATE_LOADERS = (
+    'django.template.loaders.filesystem.load_template_source',
+    'django.template.loaders.app_directories.load_template_source',
+    'django.template.loaders.eggs.load_template_source',
+)
+
+TEMPLATE_CONTEXT_PROCESSORS = (
+    'django.core.context_processors.auth',
+    'django.core.context_processors.request',
+    'flashcookie.flash_context',
+    )
+
+MIDDLEWARE_CLASSES = (
+    'django.middleware.common.CommonMiddleware',
+    'django.contrib.sessions.middleware.SessionMiddleware',
+    'flashcookie.FlashMiddleware',
+    'django.contrib.auth.middleware.AuthenticationMiddleware',
+)

openauth/tests/templates/base.html

+{% block content %}
+{% endblock %}

openauth/tests/tests.py

+import re
+
+from django.core.urlresolvers import reverse
+from django.contrib.auth.models import User
+from django.test import Client, TestCase
+from django.conf import settings
+
+import notify
+import openauth
+from openauth import views
+from openauth import forms
+
+EMAIL_REGEX = re.compile(
+    r"(^[-!#$%&'*+/=?^_`{}|~0-9A-Z]+(\.[-!#$%&'*+/=?^_`{}|~0-9A-Z]+)*"  # dot-atom
+    r'|^"([\001-\010\013\014\016-\037!#-\[\]-\177]|\\[\001-011\013\014\016-\177])*"' # quoted-string
+    r')@(?:[A-Z0-9-]+\.)+[A-Z]{2,6}$', re.IGNORECASE)
+
+USER_REGEX = re.compile(r"[a-z0-9][_a-z0-9]*[a-z0-9]$", re.I)
+
+class RegistrationTest(TestCase):
+
+    def setUp(self):
+        openauth.settings.REGISTRATION_ALLOWED = True
+        openauth.settings.USERNAME_REGEX = USER_REGEX
+        openauth.settings.REGISTRATION_FORM = "openauth.forms.RegistrationForm"
+        self.client = Client()
+        self.registration_url = reverse('openauth-registration')
+
+    def test_registration(self):
+        response = self.client.post(self.registration_url, {'username': 'petya', 'email': 'admin@example.com', 'password': 'test', 'password_dup': 'test'}) 
+        user = User.objects.get(email='admin@example.com')
+        self.failUnlessEqual(user.username, 'petya')
+
+    def test_disabled_registration(self):
+        openauth.settings.REGISTRATION_ALLOWED = False
+        response = self.client.post(self.registration_url, {'username': 'petya', 'email': 'admin@example.com', 'password': 'test', 'password_dup': 'test'}) 
+        self.failUnlessRaises(User.DoesNotExist, User.objects.get, username='petya')
+
+
+class LoginTest(TestCase):
+
+    def setUp(self):
+        notify.settings.NOTIFY_TYPE = 'flashcookie'
+        openauth.settings.REGISTRATION_ALLOWED = True
+        openauth.settings.ACTIVATION_REQUIRED = True
+        openauth.settings.USERNAME_REGEX = USER_REGEX
+        openauth.settings.AUTHENTICATION_TYPES = ['username']
+        self.client = Client()
+        self.login_url = reverse('openauth-login')
+        self.active_user = User.objects.create_user('ivan', 'ivan@example.com', password='test')
+        self.inactive_user = User.objects.create_user('vova', 'vova@example.com', password='test')
+        self.inactive_user.is_active = False
+        self.inactive_user.save()
+
+    def tearDown(self):
+        self.active_user.delete()
+        self.inactive_user.delete()
+
+    def test_valid_active_user_activation_enabled(self):
+        response = self.client.post(self.login_url, {'username': self.active_user.username, 'password': 'test'})
+        self.assertRedirects(response, openauth.settings.LOGIN_REDIRECT_URL)
+
+    def test_invalid_active_user_activation_enabled(self):
+        response = self.client.post(self.login_url, {'username': self.active_user.username, 'password': 'INCORRECT'})
+        self.assertEqual(response.status_code, 200) #not redirect to LOGIN_REDIRECT_URL
+
+    def test_inactive_user_activation_enabled(self):
+        response = self.client.post(self.login_url, {'username': self.inactive_user.username, 'password': 'test'})
+        self.assertEqual(response.status_code, 200)
+
+    def test_inactive_user_activation_disabled(self):
+        openauth.settings.ACTIVATION_REQUIRED = False
+        response = self.client.post(self.login_url, {'username': self.inactive_user.username, 'password': 'test'})
+        self.assertRedirects(response, openauth.settings.LOGIN_REDIRECT_URL)
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.