def test_create_form_with_malformed_html(self):
     """
     Make sure that if a SurveyForm is saved with unparseable html
     an exception is thrown
     """
     with pytest.raises(ValidationError):
         SurveyForm.create('badform', '<input name="oops" /><<<>')
    def test_create_form_with_no_fields(self):
        """
        Make sure that if a SurveyForm is saved without any named fields
        an exception is thrown
        """
        with pytest.raises(ValidationError):
            SurveyForm.create('badform', '<p>no input fields here</p>')

        with pytest.raises(ValidationError):
            SurveyForm.create('badform', '<input id="input_without_name" />')
Esempio n. 3
0
    def setUp(self):
        """
        Set up the test data used in the specific tests
        """
        super(SurveyViewsTests, self).setUp()  # lint-amnesty, pylint: disable=super-with-arguments

        self.test_form = '<input name="field1"></input>'
        self.survey = SurveyForm.create(self.test_survey_name, self.test_form)

        self.student_answers = OrderedDict({
            u'field1': u'value1',
            u'field2': u'value2',
        })

        # Create student accounts and activate them.
        for i in range(len(self.STUDENT_INFO)):
            email, password = self.STUDENT_INFO[i]
            username = '******'.format(i)
            self.create_account(username, email, password)
            self.activate_user(email)

        email, password = self.STUDENT_INFO[0]
        self.login(email, password)
        self.enroll(self.course, True)
        self.enroll(self.course_without_survey, True)
        self.enroll(self.course_with_bogus_survey, True)

        self.user = User.objects.get(email=email)

        self.view_url = reverse('view_survey', args=[self.test_survey_name])
        self.postback_url = reverse('submit_answers',
                                    args=[self.test_survey_name])
    def test_create_form_update_existing(self):
        """
        Make sure we can update an existing form
        """
        survey = self._create_test_survey()
        assert survey is not None

        survey = SurveyForm.create(self.test_survey_name,
                                   self.test_form_update,
                                   update_if_exists=True)
        assert survey is not None

        survey = SurveyForm.get(self.test_survey_name)
        assert survey is not None
        assert survey.form == self.test_form_update
Esempio n. 5
0
    def test_create_form_update_existing(self):
        """
        Make sure we can update an existing form
        """
        survey = self._create_test_survey()
        self.assertIsNotNone(survey)

        survey = SurveyForm.create(self.test_survey_name,
                                   self.test_form_update,
                                   update_if_exists=True)
        self.assertIsNotNone(survey)

        survey = SurveyForm.get(self.test_survey_name)
        self.assertIsNotNone(survey)
        self.assertEqual(survey.form, self.test_form_update)
    def setUp(self):
        """
        Set up the test data used in the specific tests
        """
        super().setUp()

        self.client = Client()

        # Create two accounts
        self.password = '******'
        self.student = UserFactory.create(
            username='******',
            email='*****@*****.**',
            password=self.password,
        )
        self.student2 = UserFactory.create(
            username='******',
            email='*****@*****.**',
            password=self.password,
        )

        self.staff = UserFactory.create(
            username='******',
            email='*****@*****.**',
            password=self.password,
        )
        self.staff.is_staff = True
        self.staff.save()

        self.test_survey_name = 'TestSurvey'
        self.test_form = '<input name="foo"></input>'

        self.student_answers = OrderedDict({
            'field1': 'value1',
            'field2': 'value2',
        })

        self.student2_answers = OrderedDict({'field1': 'value3'})

        self.course = CourseFactory.create(
            course_survey_required=True,
            course_survey_name=self.test_survey_name)

        self.survey = SurveyForm.create(self.test_survey_name, self.test_form)
Esempio n. 7
0
    def setUp(self):
        """
        Set up the test data used in the specific tests
        """
        super().setUp()

        self.client = Client()

        # Create two accounts
        self.password = '******'
        self.student = UserFactory.create(username='******',
                                          email='*****@*****.**',
                                          password=self.password)

        self.test_survey_name = 'TestSurvey'
        self.test_form = '''
            <input name="field1" /><input name="field2" /><select name="ddl"><option>1</option></select>
            <textarea name="textarea" />
        '''

        self.student_answers = OrderedDict({
            'field1': 'value1',
            'field2': 'value2',
            'ddl': '1',
            'textarea': 'textarea'
        })

        self.course = CourseFactory.create(
            display_name='Test Course',
            course_survey_required=True,
            course_survey_name=self.test_survey_name)

        self.survey = SurveyForm.create(self.test_survey_name, self.test_form)

        self.view_url = reverse('view_survey', args=[self.test_survey_name])
        self.postback_url = reverse('submit_answers',
                                    args=[self.test_survey_name])

        self.client.login(username=self.student.username,
                          password=self.password)
Esempio n. 8
0
    def setUp(self):
        """
        Set up the test data used in the specific tests
        """
        super(SurveyModelsTests, self).setUp()  # lint-amnesty, pylint: disable=super-with-arguments

        self.client = Client()

        # Create two accounts
        self.password = '******'
        self.student = User.objects.create_user('student', '*****@*****.**',
                                                self.password)
        self.student2 = User.objects.create_user('student2',
                                                 '*****@*****.**',
                                                 self.password)

        self.staff = User.objects.create_user('staff', '*****@*****.**',
                                              self.password)
        self.staff.is_staff = True
        self.staff.save()

        self.test_survey_name = 'TestSurvey'
        self.test_form = '<input name="foo"></input>'

        self.student_answers = OrderedDict({
            'field1': 'value1',
            'field2': 'value2',
        })

        self.student2_answers = OrderedDict({'field1': 'value3'})

        self.course = CourseFactory.create(
            course_survey_required=True,
            course_survey_name=self.test_survey_name)

        self.survey = SurveyForm.create(self.test_survey_name, self.test_form)
 def _create_test_survey(self):
     """
     Helper method to set up test form
     """
     return SurveyForm.create(self.test_survey_name, self.test_form)