Permalink
Browse files

Modify our test runner to not use a fancy runner if TEST_DISPLAY is not

set.

Add a django_tests folder for tests that don't need selenium

`make clitest` runs just the django_tests; make test runs selenium tests
in firefox as well.
  • Loading branch information...
1 parent bdb6fcb commit 5fc341a932c2ec098bb46dac4693b6016f1f277a @jamezpolley jamezpolley committed Feb 29, 2012
View
@@ -53,7 +53,12 @@ prepare-serve: install
$(ACTIVATE) && python manage.py collectstatic --noinput
$(ACTIVATE) && python manage.py syncdb
-test: install
+test: clitest firefoxtest
+
+clitest: install
+ $(ACTIVATE) && python manage.py test -v2 usergroup.django_tests
+
+firefoxtest: install
$(ACTIVATE) && TEST_DISPLAY=1 python manage.py test -v 2 usergroup.selenium_tests
chrometest: install
No changes.
@@ -0,0 +1,16 @@
+#!/usr/bin/env python
+from django.core import mail
+from django.test import TestCase
+
+class EmailTest(TestCase):
+ def test_send_email(self):
+ # Send message.
+ mail.send_mail('Subject here', 'Here is the message.',
+ 'from@example.com', ['to@example.com'],
+ fail_silently=False)
+
+ # Test that one message has been sent.
+ self.assertEqual(len(mail.outbox), 1)
+
+ # Verify that the subject of the first message is correct.
+ self.assertEqual(mail.outbox[0].subject, 'Subject here')
@@ -72,6 +72,18 @@ def testNewEventReadyToPublish(self):
submit_text = submit.get_attribute("value")
self.assertEqual(u"Publish event", submit_text, msg=submit)
+ def testPublishedEventReadyToAnnounce(self):
+ """Newly created events should be in the unpublished state."""
+ self.doLogin()
+ event_url = self.do_create_event()
+ event_id, _ = self.get_id_and_action_from_url(event_url)
+ self.browser.find_element_by_id("events_link").click()
+ submit = self.browser.find_element_by_id("submit_%s" % event_id)
+ submit.click()
+ submit = self.browser.find_element_by_id("submit_%s" % event_id)
+ submit_text = submit.get_attribute("value")
+ self.assertEqual(u"Announce event via email", submit_text, msg=submit)
+
def testUnpublishedEventInvisibleToAnonymousUsers(self):
"""Create two events; publish one; log out. Should only see one event."""
first_event_id, second_event_id = self.do_two_events()
@@ -25,8 +25,6 @@ def testLoginAndLogout(self):
self.doLogin()
self.assertEqual(1, len(self.browser.window_handles))
self.assertIn("Sydney Linux User Group", self.browser.title)
- logout_link = self.browser.find_element_by_id("logout_link")
- logout_link.click()
class TestInvalidUserLogin(SeleniumTestCase):
@@ -51,5 +49,3 @@ def testLoginAndLogout(self):
self.doLogin(username="existing", password="password")
self.assertEqual(1, len(self.browser.window_handles))
self.assertIn("Sydney Linux User Group", self.browser.title)
- logout_link = self.browser.find_element_by_id("logout_link")
- logout_link.click()
View
@@ -11,6 +11,8 @@
import subprocess
import sys
+import django.test.simple
+
from django_testing_fixes import suite as fix_suite
from django_testing_fixes import fix_finish_response, fix_finish_request
from django_testing_fixes import fix_fixtures
@@ -22,12 +24,17 @@ class UserGroupTestSuiteRunner(fix_suite.TestSuiteRunner):
"""A test suite runner which can use a display."""
def run_tests(self, *args, **kwargs):
- if os.environ.get('TEST_DISPLAY', '') in ('1', 'True'):
- server = display_servers.RealDisplay()
+ TEST_DISPLAY = os.environ.get('TEST_DISPLAY', '')
+ if TEST_DISPLAY:
+ if TEST_DISPLAY in ('1', 'True'):
+ server = display_servers.RealDisplay()
+ else:
+ server = display_servers.VNCDisplay()
+ with server:
+ return fix_suite.TestSuiteRunner.run_tests(self, *args, **kwargs)
else:
- server = display_servers.VNCDisplay()
-
- with server:
- return fix_suite.TestSuiteRunner.run_tests(self, *args, **kwargs)
+ #No display needed, just use the normal runner
+ return django.test.simple.DjangoTestSuiteRunner.run_tests(self,
+ *args, **kwargs)
suite = fix_suite.create_suite(os.path.dirname(__file__), 'usergroup')

0 comments on commit 5fc341a

Please sign in to comment.