/
functional_tests.py
executable file
·74 lines (51 loc) · 1.79 KB
/
functional_tests.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#!/usr/bin/env python
try: import unittest2 as unittest #for Python <= 2.6
except: import unittest
from selenium import webdriver
import subprocess
import sys
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://localhost:8001'
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)
def tearDown(self):
self.browser.close()
self.django.kill()
def run_syncdb():
call_command('syncdb', interactive=False)
def start_django_server():
#noreload ensures single process
return subprocess.Popen([
'python', 'manage.py', 'runserver',
ROOT.replace('http://', ''), '--noreload', '--settings=settings_for_fts'
])
def reset_database():
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_functional_tests(pattern=None):
print 'running tests'
if pattern is None:
tests = unittest.defaultTestLoader.discover('fts')
else:
pattern_with_globs = '*%s*' % (pattern,)
tests = unittest.defaultTestLoader.discover('fts', pattern=pattern_with_globs)
runner = unittest.TextTestRunner()
runner.run(tests)
if __name__ == '__main__':
run_syncdb()
if len(sys.argv) == 1:
run_functional_tests()
else:
run_functional_tests(pattern=sys.argv[1])