def testJsForDateQuestion(self): """Ensure js for date questions""" s1 = getattr(self.portal, 's1') s1.invokeFactory('Survey Date Question', 'sdq1') result = s1.survey_view(REQUEST=Request()) assert 'jscalendar/calendar_stripped.js' in result assert 'jscalendar/calendar-en.js' in result
def testRespondentsView(self): """Ensure template does not raise an error with a respondent""" s1 = getattr(self.portal, 's1') questions = s1.getQuestions() for question in questions: question.addAnswer('Answer') result = s1.respondents_view(REQUEST=Request()) self.assertEqual(result.find('Error Type') >= 0, False)
def testReadDoesNotWrite(self): s1 = getattr(self.portal, 's1') # commit, as we've added a question transaction.commit() original_size = s1._p_estimated_size respondent_size = s1.respondents._p_estimated_size assert s1.getRespondentsList() == [] logout() assert s1._p_changed is False assert s1.respondents._p_changed is False assert s1.stq1._p_changed is False # view the survey result = s1.survey_view(REQUEST=Request()) assert s1._p_changed is False assert s1.respondents._p_changed is False assert s1.stq1._p_changed is False transaction.commit() # XXX this should not cause an increase in the object size assert s1._p_estimated_size == original_size, \ "Survey size increased from %s to %s" % (original_size, s1._p_estimated_size) # submit a response self.layer['request'].form['stq1'] = 'An answer' dummy_controller_state = ControllerState( id='survey_view', context=s1, button='submit', status='success', errors={}, next_action=None, ) controller = self.portal.portal_form_controller controller_state = controller.validate( dummy_controller_state, self.layer['request'], ['validate_survey', ] ) assert controller_state.getErrors() == {}, controller_state.getErrors() assert len(s1.getRespondentsList()) == 1 assert s1._p_changed is False assert s1.respondents._p_changed is True assert s1.stq1._p_changed is False transaction.commit() # the survey itself should not increase in size assert s1._p_estimated_size == original_size, \ "Survey size increased from %s to %s" % (original_size, s1._p_estimated_size) # the respondents should increase in size assert s1.respondents._p_estimated_size > respondent_size, \ "Respondents size increased from %s to %s" % ( respondent_size, s1.respondents._p_estimated_size)
def testSurveyView(self): """Ensure survey view works""" logout() s1 = getattr(self.portal, 's1') result = s1.survey_view(REQUEST=Request()) self.assertEqual(result.find('Error Type') >= 0, False)
def testSurveyView(self): """Ensure survey view works for sub survey""" s1 = getattr(self.portal, 's1') result = s1.ss1.survey_view(REQUEST=Request()) # XXX this should test that page is redirected to first page self.assertEqual(result.find('Error Type') >= 0, False)
def testPage1(self): """Test that captcha is NOT included on the first page""" result = self.s1.survey_view(REQUEST=Request()) assert "Question 1" in result assert "recaptcha_response_field" not in result
def testIncludeReCaptcha(self): """Test if captcha is included in the page""" result = self.s1.survey_view(REQUEST=Request()) assert '<label for="recaptcha_response_field">Protection from spam</label>' in result
def testJsInSurveyReset(self): """Ensure reset js in reset view""" s1 = getattr(self.portal, 's1') result = s1.survey_reset_form(REQUEST=Request()) assert '++resource++Products.PloneSurvey.javascripts/survey_reset.js' \ in result
def testIncludeReCaptcha(self): """Test if captcha is included in the page""" result = self.s1.survey_view(REQUEST=Request()) assert "<input type='hidden' name='recaptcha_response_field' value='manual_challenge' />" in result