Exemple #1
0
 def test_survey_ajax_success(self):
     """Ensures that /survey_ajax/ succeeds"""
     data = {
         'course_id': self.course_id,
         'unit_id': self.unit_id,
         'survey_name': self.survey_name,
         'survey_answer': self.survey_answer,
     }
     req = self.request_factory.post('/survey_ajax/', data)
     req.user = self.user
     resp = survey_ajax(req)
     self.assertEquals(resp.status_code, 200)
     obj = json.loads(resp.content)
     self.assertEquals(obj, {
         'success': True,
     })
     # assert that SurveySubmission record is created
     submissions = SurveySubmission.objects.filter(
         course_id=self.course_id,
         unit_id=self.unit_id,
         user=self.user
     )
     self.assertEquals(len(submissions), 1)
     self.assertEquals(submissions[0].survey_name, self.survey_name)
     self.assertEquals(submissions[0].survey_answer, self.survey_answer)
Exemple #2
0
    def test_survey_ajax_fail_when_already_submitted(self):
        """Ensures that /survey_ajax/ fails when survey_submission already exists"""
        submission = SurveySubmissionFactory.create()

        data = {
            'course_id': submission.course_id,
            'unit_id': submission.unit_id,
            'survey_name': self.survey_name,
            'survey_answer': self.survey_answer,
        }
        req = self.request_factory.post('/survey_ajax/', data)
        req.user = submission.user
        resp = survey_ajax(req)
        self.assertEquals(resp.status_code, 200)
        obj = json.loads(resp.content)
        self.assertEquals(obj, {
            'success': False,
            'survey_answer': submission.get_survey_answer(),
        })
Exemple #3
0
    def test_survey_ajax_fail_when_already_submitted(self):
        """Ensures that /survey_ajax/ fails when survey_submission already exists"""
        submission = SurveySubmissionFactory.create()

        data = {
            'course_id': submission.course_id,
            'unit_id': submission.unit_id,
            'survey_name': self.survey_name,
            'survey_answer': self.survey_answer,
        }
        req = self.request_factory.post('/survey_ajax/', data)
        req.user = submission.user
        resp = survey_ajax(req)
        self.assertEquals(resp.status_code, 200)
        obj = json.loads(resp.content)
        self.assertEquals(obj, {
            'success': False,
            'survey_answer': submission.get_survey_answer(),
        })
Exemple #4
0
 def test_survey_ajax_success(self):
     """Ensures that /survey_ajax/ succeeds"""
     data = {
         'course_id': self.course_id,
         'unit_id': self.unit_id,
         'survey_name': self.survey_name,
         'survey_answer': self.survey_answer,
     }
     req = self.request_factory.post('/survey_ajax/', data)
     req.user = self.user
     resp = survey_ajax(req)
     self.assertEquals(resp.status_code, 200)
     obj = json.loads(resp.content)
     self.assertEquals(obj, {
         'success': True,
     })
     # assert that SurveySubmission record is created
     submissions = SurveySubmission.objects.filter(course_id=self.course_id,
                                                   unit_id=self.unit_id,
                                                   user=self.user)
     self.assertEquals(len(submissions), 1)
     self.assertEquals(submissions[0].survey_name, self.survey_name)
     self.assertEquals(submissions[0].survey_answer, self.survey_answer)
Exemple #5
0
 def test_survey_ajax_get_method_not_allowed(self):
     """Ensures that get request to /survey_ajax/ is not allowed"""
     req = self.request_factory.get('/survey_ajax/')
     resp = survey_ajax(req)
     self.assertIsInstance(resp, HttpResponseNotAllowed)
Exemple #6
0
 def test_survey_ajax_get_method_not_allowed(self):
     """Ensures that get request to /survey_ajax/ is not allowed"""
     req = self.request_factory.get('/survey_ajax/')
     resp = survey_ajax(req)
     self.assertIsInstance(resp, HttpResponseNotAllowed)