]> git.openstreetmap.org Git - osqa.git/blob - forum/management/commands/test_ui.py
Pagination updates
[osqa.git] / forum / management / commands / test_ui.py
1 import os
2 import glob
3 import logging
4 import subprocess
5
6 from django.core.management.base import BaseCommand, CommandError
7 from django.conf import settings as django_settings
8
9 from forum import settings
10
11 class Command(BaseCommand):
12     args = '<test1 test2 test3 ...>'
13     help = 'Closes the specified poll for voting'
14
15     def handle(self, *args, **options):
16         # Try to load Selenium.
17         try:
18             import selenium
19             print "Selenium has been successfully loaded"
20         except ImportError:
21             logging.error("Couldn't load selenium")
22             exit("Python Selenium couldn't be loaded: pip install selenium")
23
24         # Tests folder
25         TEST_FOLDER = '%s/forum/skins/%s/tests' % (django_settings.SITE_SRC_ROOT, django_settings.OSQA_DEFAULT_SKIN)
26
27         # Check if the UI tests folder exists
28         if os.path.exists(TEST_FOLDER):
29             print 'Loading UI tests from %s' % TEST_FOLDER
30         else:
31             exit("UI tests folder couldn't be loaded")
32
33         # Loop through all args and try to get the python test files that match
34         print args
35         files = []
36         for arg in args:
37             matching_files = glob.glob('%s/%s.py' % (TEST_FOLDER, arg))
38             for matching_file in matching_files:
39                 files.append(matching_file)
40
41         # Loop through all test files
42         for file in files:
43             file_name = file.split('/')[-1]
44             print "Starting test %s" % file_name
45             child = subprocess.Popen('python %s' % file, shell=True)