Esempio n. 1
0
    def test_it_returns_None_if_all_schemas_fail(
        self,
        launch_params_auth_schema,
        bearer_token_schema,
        canvas_oauth_callback_schema,
        pyramid_request,
    ):
        launch_params_auth_schema.lti_user.side_effect = ValidationError(
            ["TEST_ERROR_MESSAGE"])
        bearer_token_schema.lti_user.side_effect = ValidationError(
            ["TEST_ERROR_MESSAGE"])
        canvas_oauth_callback_schema.lti_user.side_effect = ValidationError(
            ["TEST_ERROR_MESSAGE"])

        assert get_lti_user(pyramid_request) is None
Esempio n. 2
0
    def test_it_raises_CanvasAPIServerError_for_a_successful_but_invalid_response(
        self, canvas_api_invalid_response
    ):
        cause = ValidationError("The response was invalid.")
        cause.response = canvas_api_invalid_response
        cause.response.body = "x" * 1000  # pylint:disable=no-member

        raised_exception = self.assert_raises(cause, CanvasAPIServerError)

        assert raised_exception.__cause__ == cause
        assert raised_exception.response == canvas_api_invalid_response
        assert raised_exception.details == {
            "exception": "Unable to process the contained instructions",
            "response": {"body": "Invalid", "status": "200 OK"},
            "validation_errors": "The response was invalid.",
        }
Esempio n. 3
0
class TestValidationError(ExceptionViewTest):
    view = error.validation_error
    exception = ValidationError(mock.sentinel.messages)

    response_status = 422
    report_to_sentry = False
    expected_result = {"error": exception}
Esempio n. 4
0
 def test_it(self, pyramid_request):
     json_data = error.validation_error(ValidationError(messages="foobar"),
                                        pyramid_request)
     assert pyramid_request.response.status_code == 422
     assert json_data == {
         "error_message": "Unable to process the contained instructions",
         "details": "foobar",
     }
Esempio n. 5
0
    def test_if_LaunchParamsAuthSchema_and_BearerTokenSchema_fails_it_falls_back_on_CanvasOAuthCallbackSchema(
        self,
        launch_params_auth_schema,
        bearer_token_schema,
        CanvasOAuthCallbackSchema,
        canvas_oauth_callback_schema,
        pyramid_request,
    ):
        launch_params_auth_schema.lti_user.side_effect = ValidationError(
            ["TEST_ERROR_MESSAGE"])
        bearer_token_schema.lti_user.side_effect = ValidationError(
            ["TEST_ERROR_MESSAGE"])

        lti_user = get_lti_user(pyramid_request)

        CanvasOAuthCallbackSchema.assert_called_once_with(pyramid_request)
        canvas_oauth_callback_schema.lti_user.assert_called_once_with()
        assert lti_user == canvas_oauth_callback_schema.lti_user.return_value
Esempio n. 6
0
    def test_it_errors_if_validation_fails(
        self, context, info, Schema, pyramid_request, view
    ):
        Schema.return_value.parse.side_effect = ValidationError("error_messages")
        wrapper_view = _validated_view(view, info)

        with pytest.raises(ValidationError):
            wrapper_view(context, pyramid_request)

        view.assert_not_called()
Esempio n. 7
0
    def test_it_returns_the_LTIUser_from_LaunchParamsAuthSchema(
        self,
        bearer_token_schema,
        LaunchParamsAuthSchema,
        launch_params_auth_schema,
        pyramid_request,
    ):
        bearer_token_schema.lti_user.side_effect = ValidationError(
            ["TEST_ERROR_MESSAGE"])

        lti_user = get_lti_user(pyramid_request)

        LaunchParamsAuthSchema.assert_called_once_with(pyramid_request)
        launch_params_auth_schema.lti_user.assert_called_once_with()
        assert lti_user == launch_params_auth_schema.lti_user.return_value
Esempio n. 8
0
    def test(self):
        validation_error = ValidationError(mock.sentinel.messages)

        assert validation_error.messages == mock.sentinel.messages
        assert validation_error.status_code == 422
Esempio n. 9
0
    def test_it_raises_CanvasAPIError_for_validation_errors(
            self, base_client, Schema):
        Schema.return_value.parse.side_effect = ValidationError("Some error")

        with pytest.raises(CanvasAPIError):
            base_client._validated_response(sentinel.request, Schema)