Permalink
Browse files

Added basic tests

  • Loading branch information...
1 parent 3a52a64 commit 8822c4267e23f6d0b5aa7df03352eeb81c2538d3 @codeinthehole committed Jun 19, 2012
Showing with 85 additions and 0 deletions.
  1. +45 −0 runtests.py
  2. 0 tests/__init__.py
  3. 0 tests/models.py
  4. +28 −0 tests/tests.py
  5. +5 −0 tests/urls.py
  6. +7 −0 tests/views.py
View
@@ -0,0 +1,45 @@
+#!/usr/bin/env python
+import sys
+import os
+
+from django.conf import settings, global_settings
+
+if not settings.configured:
+ settings.configure(
+ DATABASES={
+ 'default': {
+ 'ENGINE': 'django.db.backends.sqlite3',
+ }
+ },
+ INSTALLED_APPS=[
+ 'django.contrib.auth',
+ 'django.contrib.admin',
+ 'django.contrib.contenttypes',
+ 'django.contrib.sessions',
+ 'django.contrib.sites',
+ 'async_messages',
+ 'tests',
+ ],
+ MIDDLEWARE_CLASSES=global_settings.MIDDLEWARE_CLASSES + (
+ 'async_messages.middleware.AsyncMiddleware',
+ ),
+ ROOT_URLCONF='tests.urls',
+ DEBUG=False,
+ SITE_ID=1,
+ )
+
+from django.test.simple import DjangoTestSuiteRunner
+
+
+def run_tests():
+ # Modify path
+ parent = os.path.dirname(os.path.abspath(__file__))
+ sys.path.insert(0, parent)
+
+ # Run tests
+ test_runner = DjangoTestSuiteRunner(verbosity=2)
+ failures = test_runner.run_tests(['tests'])
+ sys.exit(failures)
+
+if __name__ == '__main__':
+ run_tests()
View
No changes.
View
No changes.
View
@@ -0,0 +1,28 @@
+from django.test import TestCase
+from django.test.client import Client
+from django.contrib.auth.models import User
+
+from async_messages import message_user
+
+
+class MiddlewareTests(TestCase):
+
+ def setUp(self):
+ username, password = 'david', 'password'
+ self.user = User.objects.create_user(username, None, password)
+ self.client = Client()
+ self.client.login(username=username, password=password)
+
+ def test_message_appears_for_user(self):
+ message_user(self.user, "Hello")
+ response = self.client.get('/')
+ messages = list(response.context['messages'])
+ self.assertEqual(1, len(messages))
+ self.assertEqual('Hello', str(messages[0]))
+
+ def test_message_appears_only_once_for_user(self):
+ message_user(self.user, "Hello")
+ response = self.client.get('/')
+ messages = list(response.context['messages'])
+ self.assertEqual(1, len(messages))
+ self.assertEqual('Hello', str(messages[0]))
View
@@ -0,0 +1,5 @@
+from django.conf.urls.defaults import patterns, url
+
+urlpatterns = patterns('',
+ url(r'^$', 'tests.views.index'),
+)
View
@@ -0,0 +1,7 @@
+from django.template.response import TemplateResponse
+from django.template import Template
+
+
+def index(request):
+ t = Template("")
+ return TemplateResponse(request, t, {'a': 1000})

0 comments on commit 8822c42

Please sign in to comment.