Skip to content

Commit

Permalink
Merge pull request #126 from divergentdave/test-checkbox-checked
Browse files Browse the repository at this point in the history
Verify check boxes and radio buttons
  • Loading branch information
Kelsey Gilmore-Innis authored Oct 24, 2016
2 parents 5140cf8 + 40b1acc commit 8704e35
Showing 1 changed file with 21 additions and 5 deletions.
26 changes: 21 additions & 5 deletions tests/callistocore/test_delivery.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import PyPDF2
import pytz
import six

from django.contrib.auth import get_user_model
from django.core import mail
Expand All @@ -28,7 +29,7 @@ def setUp(self):

def test_checkbox_rendered(self):
checkbox_question = '''[
{"answer": [0,1,2,3,4],
{"answer": [0,2,4],
"id": 1,
"section": 1,
"question_text": "A checkbox question?",
Expand All @@ -52,7 +53,13 @@ def test_checkbox_rendered(self):

self.assertIn('A checkbox question?', rendered_text)
for i in range(5):
self.assertIn('This is checkbox choice {}'.format(i), rendered_text)
if i in [0, 2, 4]:
# Zapf Dingbats "a23" or "BALLOT X" is encoded as 0x37 or "7"
regex = '7\\s+This is checkbox choice {}'.format(i)
else:
# Zapf Dingbats "a73" or "BALLOT SQUARE" is encoded as 0x6E or "n"
regex = 'n\\s+This is checkbox choice {}'.format(i)
six.assertRegex(self, rendered_text, regex)
self.assertIn('Extra text for choice 0', rendered_text)
self.assertIn('Extra checkbox answer text', rendered_text)

Expand Down Expand Up @@ -142,8 +149,11 @@ def test_single_formset_rendered(self):
self.assertNotIn('Formset 1', rendered_text)
self.assertIn('Formset', rendered_text)
self.assertIn('Checkbox question?', rendered_text)
for i in range(3):
self.assertIn('This is checkbox choice {}'.format(i), rendered_text)
# Zapf Dingbats "a23" or "BALLOT X" is encoded as 0x37 or "7"
six.assertRegex(self, rendered_text, '7\\s+This is checkbox choice 0')
# Zapf Dingbats "a73" or "BALLOT SQUARE" is encoded as 0x6E or "n"
six.assertRegex(self, rendered_text, 'n\\s+This is checkbox choice 1')
six.assertRegex(self, rendered_text, 'n\\s+This is checkbox choice 2')
self.assertIn('Extra text for choice 0', rendered_text)
self.assertIn('Extra checkbox answer text', rendered_text)

Expand Down Expand Up @@ -247,7 +257,13 @@ def test_radiobutton_rendered(self):
rendered_text = pdf_reader.getPage(1).extractText()
self.assertIn('A radiobutton question?', rendered_text)
for i in range(5):
self.assertIn('This is radiobutton choice {}'.format(i), rendered_text)
if i == 0:
# Zapf Dingbats "a23" or "BALLOT X" is encoded as 0x37 or "7"
regex = '7\\s+This is radiobutton choice {}'.format(i)
else:
# Zapf Dingbats "a73" or "BALLOT SQUARE" is encoded as 0x6E or "n"
regex = 'n\\s+This is radiobutton choice {}'.format(i)
six.assertRegex(self, rendered_text, regex)
self.assertIn('Extra text for choice 0', rendered_text)
self.assertIn('Extra radiobutton answer text', rendered_text)

Expand Down

0 comments on commit 8704e35

Please sign in to comment.