Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,9 @@ Then, create the Python part of your tests:
self.assertTrue(self.casper(
os.path.join(os.path.dirname(__file__),
'casper-tests/test.js')))

# or just simply
self.assertCasper('test.js')

Then, create the CasperJS part. Create a `casper-tests` directory somewhere
(eg. in your `tests` directory). Copy `djangocasper.js` helper JS module
Expand Down Expand Up @@ -120,6 +123,12 @@ in your Python tests:
'casper-tests/test.js')),
user=fixture_username,
pass=fixture_password)

# Or tersely
self.assertCasper('test.js',
user=fixture_username,
pass=fixture_password)


Then access these keyword arguments from the JS file:

Expand Down
16 changes: 16 additions & 0 deletions casper/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from subprocess import Popen, PIPE
import os
import sys
import inspect

from django.contrib.staticfiles.handlers import StaticFilesHandler
from django.contrib.staticfiles.views import serve
Expand All @@ -25,6 +26,7 @@ class CasperTestCase(LiveServerTestCase):
use_phantom_disk_cache = False
load_images = False
no_colors = True
casper_directory = None

def __init__(self, *args, **kwargs):
super(CasperTestCase, self).__init__(*args, **kwargs)
Expand Down Expand Up @@ -78,3 +80,17 @@ def casper(self, test_filename, **kwargs):
sys.stdout.write(out)
sys.stderr.write(err)
return p.returncode == 0

def get_casper_dir(self):
"""Get the directory containing casper files"""
if self.casper_directory:
return self.casper_directory
root = os.path.dirname(inspect.getfile(type(self)))
auto = os.path.join(root, 'casper-tests')
return auto if os.path.isdir(auto) else root

def assertCasper(self, casper_file, msg=None, **kwargs):
"""Automate the casper API into a single assert"""
if not os.path.isfile(casper_file) and casper_directory:
casper_file = os.path.join(self.casper_directory, casper_file)
self.assertTrue(self.casper(casper_file, **kwargs), msg)