Browse files

use setup_environ and call_command for flush, adding admin user.

functional test runner works again!
  • Loading branch information...
1 parent e2214c0 commit 7e410dce03606d55cdbdd9fe2730d10e1534b468 Harry Percival committed Oct 14, 2011
Showing with 14 additions and 41 deletions.
  1. +14 −41 mysite/functional_tests.py
View
55 mysite/functional_tests.py
@@ -1,25 +1,13 @@
#!/usr/bin/python
try: import unittest2 as unittest #for Python <= 2.6
except: import unittest
-import json
from selenium import webdriver
import subprocess
-from tempfile import NamedTemporaryFile
-
-
-ADMIN_USER_DICT = {
- "pk": 1,
- "model": "auth.user",
- "fields": {
- "username": "admin",
- "is_active": True,
- "is_superuser": True,
- "is_staff": True,
- "password": r"sha1$c6584$b8a0656080944eed8e0db23e3aa6e690f255aa52",
- "email": "admin@example.com",
- "date_joined": "2011-10-13 09:13:23"
- }
-}
+import settings_for_fts
+from django.core.management import call_command, setup_environ
+setup_environ(settings_for_fts)
+from django.contrib.auth.models import User
+
ROOT = 'http://127.0.0.1:8000'
@@ -28,6 +16,8 @@ class FunctionalTest(unittest.TestCase):
def setUp(self):
reset_database()
+ # restart django server each test, because otherwise it doesn't see the
+ # effects of resetting the db
self.django = start_django_server()
self.browser = webdriver.Firefox()
self.browser.implicitly_wait(5)
@@ -40,39 +30,22 @@ def tearDown(self):
def run_syncdb():
- print 'running syncdb'
- subprocess.Popen(
- ['python', 'manage.py', 'syncdb', '--noinput', '--settings=settings_for_fts']
- ).communicate()
+ call_command('syncdb', interactive=False)
def start_django_server():
- print '(re) starting django test server'
#noreload ensures single process
- django_server = subprocess.Popen(
+ return subprocess.Popen(
['python', 'manage.py', 'runserver', '--noreload', '--settings=settings_for_fts']
)
- #dev server starts quickly, no need to check it's running
- return django_server
def reset_database():
- print 'flushing database'
- subprocess.Popen(
- ['python', 'manage.py', 'flush', '--noinput', '--settings=settings_for_fts']
- ).communicate()
- print 'loading fixtures'
- with NamedTemporaryFile(delete=False) as temp:
- fixture_json = json.dumps([ADMIN_USER_DICT])
- temp.write(fixture_json)
- temp.seek(0)
- print temp.read()
- temp.seek(0)
- subprocess.Popen(
- ['python', 'manage.py', 'loaddata', temp.name, '--settings=settings_for_fts']
- ).communicate()
-
- print 'fixtures loaded from', temp.name
+ call_command('flush', interactive=False)
+ admin = User(username='admin',is_staff=True, is_superuser=True, email='admin@example.com')
+ admin.save()
+ admin.set_password('adm1n')
+ admin.save()
def run_all_functional_tests():

0 comments on commit 7e410dc

Please sign in to comment.