def test_section_form_view_status_without_custom_canvas_course_id(self, log_replacement, render):
     """
     Create Section Form view should return error page if there was no
     lis_course_offering_sourcedid
     """
     request = self.request
     request.LTI["lis_course_offering_sourcedid"] = None
     create_section_form(request)
     render.assert_called_with(request, "manage_sections/error.html", status=500)
 def test_section_form_view_status_without_custom_canvas_course_id(
         self, log_replacement, render):
     """
     Create Section Form view should return error page if there was no
     lis_course_offering_sourcedid
     """
     request = self.request
     request.LTI['lis_course_offering_sourcedid'] = None
     create_section_form(request)
     render.assert_called_with(request,
                               'manage_sections/error.html',
                               status=500)
 def test_section_form_view_template_on_success_when_current_match(self, get_section_replacement, render):
     """ Create Section Form View should return success when current ci matches"""
     request = self.request
     get_section_replacement.return_value = self.sections_current_match
     response = create_section_form(request)
     render.assert_called_with(request, 'manage_sections/create_section_form.html', {
         'sections': [],
         'sisenrollmentsections': self.sections_current_match
     })
 def test_section_form_view_template_on_success_when_ci_match(self, get_section_replacement, render):
     """ Create Section Form View should return success when ci prefix"""
     request = self.request
     request.LTI['lis_course_offering_sourcedid'] = "ci:%s" % self.sis_section_id
     get_section_replacement.return_value = self.sections_current_prefix_match
     response = create_section_form(request)
     render.assert_called_with(request, 'manage_sections/create_section_form.html', {
         'sections': [],
         'sisenrollmentsections': self.sections_current_prefix_match
     })
 def test_manage_section_error_message(self):
     """
     Validate error message when when Create Section Form view returns  error
      page when there is no lis_course_offering_sourcedid
     """
     request = self.request
     request.LTI['lis_course_offering_sourcedid'] = None
     result = create_section_form(request)
     self.assertTrue('wiki.harvard.edu/confluence/display/canvas/'
                     'Local+School+Support+Contacts' in result.content)
 def test_manage_section_error_message(self):
     """
     Validate error message when when Create Section Form view returns  error
      page when there is no lis_course_offering_sourcedid
     """
     request = self.request
     request.LTI['lis_course_offering_sourcedid'] = None
     result = create_section_form(request)
     self.assertTrue('wiki.harvard.edu/confluence/display/canvas/'
                     'Local+School+Support+Contacts' in result.content)
    def test_section_form_view_when_not_permitted(self, lti_decorator, log_replacement, render):
        """
        When the user does not have the right permissions, verify that it
        redirects to unauthorized page
        """
        request = self.request
        request.LTI['lis_course_offering_sourcedid'] = "ci:%s" % self.sis_section_id

        response = create_section_form(request)
        self.assertEqual(response.status_code, 302)
        self.assertEqual(response.url, '/not_authorized')
 def test_section_form_view_template_on_success_when_current_match(
         self, get_section_replacement, render):
     """ Create Section Form View should return success when current ci matches"""
     request = self.request
     get_section_replacement.return_value = self.sections_current_match
     response = create_section_form(request)
     render.assert_called_with(
         request, 'manage_sections/create_section_form.html', {
             'sections': [],
             'sisenrollmentsections': self.sections_current_match
         })
 def test_section_form_view_template_on_success_when_primary_match(self, get_section_replacement, is_enrollment_section_mock,
                                                                   is_sis_mock, render):
     """ Create Section Form View should return success when numeric"""
     request = self.request
     get_section_replacement.return_value = self.sections
     is_enrollment_section_mock.return_value = True
     is_sis_mock.return_value = False
     response = create_section_form(request)
     render.assert_called_with(request, 'manage_sections/create_section_form.html', {
         'sections': [],
         'sisenrollmentsections': self.sections
     })
 def test_section_form_view_template_on_success(
     self, get_section_replacement, is_enrollment_section_mock, is_sis_mock, render
 ):
     """ Create Section Form View should render form page upon success"""
     request = self.request
     get_section_replacement.return_value = self.sections
     is_enrollment_section_mock.return_value = False
     is_sis_mock.return_value = False
     response = create_section_form(request)
     section_list = sorted(self.sections, key=lambda x: x[u"name"].lower())
     render.assert_called_with(
         request, "manage_sections/create_section_form.html", {"sections": section_list, "sisenrollmentsections": []}
     )
 def test_section_form_view_template_on_success_when_non_sis_match(self, get_section_replacement, is_enrollment_section_mock,
                                                                   is_sis_mock, render):
     """ Create Section Form View should return success when no sis"""
     request = self.request
     get_section_replacement.return_value = self.sections
     is_enrollment_section_mock.return_value = False
     is_sis_mock.return_value = False
     response = create_section_form(request)
     section_list = sorted(self.sections, key=lambda x: x[u'name'].lower())
     render.assert_called_with(request, 'manage_sections/create_section_form.html', {
         'sections': section_list,
         'sisenrollmentsections': []
     })
 def test_section_form_view_template_on_success_when_ci_match(
         self, get_section_replacement, render):
     """ Create Section Form View should return success when ci prefix"""
     request = self.request
     request.LTI[
         'lis_course_offering_sourcedid'] = "ci:%s" % self.sis_section_id
     get_section_replacement.return_value = self.sections_current_prefix_match
     response = create_section_form(request)
     render.assert_called_with(
         request, 'manage_sections/create_section_form.html', {
             'sections': [],
             'sisenrollmentsections': self.sections_current_prefix_match
         })
    def test_section_form_view_when_not_permitted(self, lti_decorator,
                                                  log_replacement, render):
        """
        When the user does not have the right permissions, verify that it
        redirects to unauthorized page
        """
        request = self.request
        request.LTI[
            'lis_course_offering_sourcedid'] = "ci:%s" % self.sis_section_id

        response = create_section_form(request)
        self.assertEqual(response.status_code, 302)
        self.assertEqual(response.url, '/not_authorized')
 def test_section_form_view_template_on_success_when_primary_match(
         self, get_section_replacement, is_enrollment_section_mock,
         is_sis_mock, render):
     """ Create Section Form View should return success when numeric"""
     request = self.request
     get_section_replacement.return_value = self.sections
     is_enrollment_section_mock.return_value = True
     is_sis_mock.return_value = False
     response = create_section_form(request)
     render.assert_called_with(request,
                               'manage_sections/create_section_form.html', {
                                   'sections': [],
                                   'sisenrollmentsections': self.sections
                               })
 def test_section_form_view_template_on_success_when_registrar_match(
     self, get_section_replacement, is_enrollment_section_mock, is_sis_mock, render
 ):
     """ Create Section Form View should return success when numeric"""
     request = self.request
     get_section_replacement.return_value = self.sections
     is_enrollment_section_mock.return_value = False
     is_sis_mock.return_value = True
     response = create_section_form(request)
     section_list = sorted(self.sections, key=lambda x: x[u"name"].lower())
     self.assertIn("registrar_section_flag", get_section_replacement.return_value[0])
     self.assertEqual(get_section_replacement.return_value[0]["registrar_section_flag"], True)
     render.assert_called_with(
         request, "manage_sections/create_section_form.html", {"sections": section_list, "sisenrollmentsections": []}
     )
 def test_section_form_view_template_on_success_when_non_sis_match(
         self, get_section_replacement, is_enrollment_section_mock,
         is_sis_mock, render):
     """ Create Section Form View should return success when no sis"""
     request = self.request
     get_section_replacement.return_value = self.sections
     is_enrollment_section_mock.return_value = False
     is_sis_mock.return_value = False
     response = create_section_form(request)
     section_list = sorted(self.sections, key=lambda x: x['name'].lower())
     render.assert_called_with(request,
                               'manage_sections/create_section_form.html', {
                                   'sections': section_list,
                                   'sisenrollmentsections': []
                               })