def test_lti_rest_non_get(self): """tests that the endpoint returns 404 when hit with NON-get""" DISALLOWED_METHODS = ("POST", "PUT", "DELETE", "HEAD", "OPTIONS") # pylint: disable=invalid-name for method in DISALLOWED_METHODS: request = mock.Mock() request.method = method response = get_course_lti_endpoints(request, self.course.id.to_deprecated_string()) self.assertEqual(405, response.status_code)
def test_lti_rest_bad_course(self): """Tests what happens when the lti listing rest endpoint gets a bad course_id""" bad_ids = [u"sf", u"dne/dne/dne", u"fo/ey/\u5305"] request = mock.Mock() request.method = 'GET' for bad_course_id in bad_ids: response = get_course_lti_endpoints(request, bad_course_id) self.assertEqual(404, response.status_code)
def test_lti_rest_listing(self): """tests that the draft lti module is part of the endpoint response""" request = mock.Mock() request.method = 'GET' response = get_course_lti_endpoints(request, course_id=self.course.id.to_deprecated_string()) self.assertEqual(200, response.status_code) self.assertEqual('application/json', response['Content-Type']) expected = { "lti_1_1_result_service_xml_endpoint": self.expected_handler_url('grade_handler'), "lti_2_0_result_service_json_endpoint": self.expected_handler_url('lti_2_0_result_rest_handler') + "/user/{anon_user_id}", "display_name": self.lti_published.display_name, } self.assertEqual([expected], json.loads(response.content))
def test_lti_rest_listing(self): """tests that the draft lti module is not a part of the endpoint response, but the published one is""" request = mock.Mock() request.method = "GET" response = get_course_lti_endpoints(request, self.course.id) self.assertEqual(200, response.status_code) self.assertEqual("application/json", response["Content-Type"]) expected = { "lti_1_1_result_service_xml_endpoint": self.expected_handler_url("grade_handler"), "lti_2_0_result_service_json_endpoint": self.expected_handler_url("lti_2_0_result_rest_handler") + "/user/{anon_user_id}", "display_name": self.lti_published.display_name, } self.assertEqual([expected], json.loads(response.content))