Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- __author__ = 'markw'
- from multiprocessing import Process
- import os.path
- from subprocess import Popen, PIPE
- import sys
- from django.test import LiveServerTestCase
- import buildconstants
- from django_offline.startuphelpers import django_server_helper
- __all__ = ['PhantomTestCase']
- class PhantomTestCase(LiveServerTestCase):
- """LiveServerTestCase subclass that can invoke PhantomJS tests."""
- use_phantom_disk_cache = False
- def __init__(self, *args, **kwargs):
- self.interactive = False
- super(PhantomTestCase, self).__init__(*args, **kwargs)
- @classmethod
- def setUpClass(cls):
- cls.server = Process(
- target = django_server_helper,
- args = (None, cls.fixtures),
- )
- cls.server.start()
- super(PhantomTestCase, cls).setUpClass()
- def phantom(self, test_filename, **kwargs):
- """PhantomJS test invoker.
- Takes a test filename (.js) and optional arguments to pass to the
- phantom test.
- Returns True if the test(s) passed, and False if any test failed.
- """
- self.tests = kwargs.get('screenID', 'undefined')
- self.screens = kwargs.get('screens', 'enabled')
- self.port = kwargs.get('port', '46729')
- self.taxyear = kwargs.get('taxyear', 2014)
- cmd = [buildconstants.DEPS_PHANTOMJS]
- cmd.append(test_filename)
- cmd.append('--tests={}'.format(self.tests))
- cmd.append('--screens={}'.format(self.screens))
- cmd.append('--port={}'.format(self.port))
- cmd.append('--taxyear={}'.format(self.taxyear))
- p = Popen(cmd, stdout=PIPE, stderr=PIPE,
- cwd=os.path.dirname(test_filename)) # flake8: noqa
- out, err = p.communicate()
- if p.returncode != 0:
- sys.stdout.write(out)
- sys.stderr.write(err)
- return p.returncode == 0
- @classmethod
- def tearDownClass(cls):
- cls.server.terminate()
- super(PhantomTestCase, cls).tearDownClass()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement