6

I've written some casperjs tests to test my Django application. If the Django application is started (on port 8000 for example), casperjs can be run as a separate process and access my running Django app.

My other tests are written with Django's (web)testing framework that sets up the test database with fixtures, and are run with ./manage.py test. With Django webtest, you don't need to start a separate Django webserver (doing requests and url routing is proxied/simulated).

Is there a way to rung casperjs tests from within Django webtest? Without starting a different webserver and having yet another test database?

I've seen ghost.py exists, but haven't tried it yet.

blong
  • 2,815
  • 8
  • 44
  • 110
ivy
  • 5,539
  • 1
  • 34
  • 48

2 Answers2

3

I've managed to find a solution. After upgrading to Django 1.4 I can use LiveServerTestCase and fork casperjs in a subprocess:

from django.test.testcases import LiveServerTestCase
import os, subprocess
from subprocess import Popen, PIPE, STDOUT

class CasperTest(LiveServerTestCase):
    fixtures = ['test_initial_data', ]

    def test_my_testcase(self):
        p = Popen(['casperjs %s/caspertest.js' % os.path.dirname(__file__)], shell=True, stdout=PIPE, stderr=STDOUT, close_fds=True)
        output = p.stdout.read()
        print output
ivy
  • 5,539
  • 1
  • 34
  • 48
1

You should take a look at django-casper. I started to use it a few days ago and it is just awesome!