-
Notifications
You must be signed in to change notification settings - Fork 4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Refactoring of sending information to sent_to_submission
- Loading branch information
1 parent
b1b18b5
commit 4575be5
Showing
12 changed files
with
231 additions
and
232 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
# errors.py | ||
""" | ||
Custom error handling for the XQueue submission interface. | ||
""" | ||
|
||
class XQueueSubmissionError(Exception): | ||
"""Base class for all XQueue submission errors.""" | ||
# No es necesario el `pass`, la clase ya hereda de Exception. | ||
|
||
class JSONParsingError(XQueueSubmissionError): | ||
"""Raised when JSON parsing fails.""" | ||
MESSAGE = "Error parsing {name}: {error}" | ||
|
||
def __init__(self, name, error): | ||
super().__init__(self.MESSAGE.format(name=name, error=error)) | ||
|
||
class MissingKeyError(XQueueSubmissionError): | ||
"""Raised when a required key is missing.""" | ||
MESSAGE = "Missing key: {key}" | ||
|
||
def __init__(self, key): | ||
super().__init__(self.MESSAGE.format(key=key)) | ||
|
||
class ValidationError(XQueueSubmissionError): | ||
"""Raised when a validation check fails.""" | ||
MESSAGE = "Validation error: {error}" | ||
|
||
def __init__(self, error): | ||
super().__init__(self.MESSAGE.format(error=error)) | ||
|
||
class TypeErrorSubmission(XQueueSubmissionError): | ||
"""Raised when an invalid type is encountered.""" | ||
MESSAGE = "Type error: {error}" | ||
|
||
def __init__(self, error): | ||
super().__init__(self.MESSAGE.format(error=error)) | ||
|
||
class RuntimeErrorSubmission(XQueueSubmissionError): | ||
"""Raised for runtime errors.""" | ||
MESSAGE = "Runtime error: {error}" | ||
|
||
def __init__(self, error): | ||
super().__init__(self.MESSAGE.format(error=error)) | ||
|
||
class GetSubmissionParamsError(XQueueSubmissionError): | ||
"""Raised when there is an issue getting submission parameters.""" | ||
MESSAGE = "Block instance is not defined!" | ||
|
||
def __init__(self): | ||
super().__init__(self.MESSAGE) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
""" | ||
Unit tests for custom error handling in the XQueue submission interface. | ||
""" | ||
|
||
import pytest | ||
from xmodule.capa.errors import ( | ||
JSONParsingError, | ||
MissingKeyError, | ||
ValidationError, | ||
TypeErrorSubmission, | ||
RuntimeErrorSubmission, | ||
GetSubmissionParamsError | ||
) | ||
|
||
def test_json_parsing_error(): | ||
with pytest.raises(JSONParsingError) as excinfo: | ||
raise JSONParsingError("test_name", "test_error") | ||
assert str(excinfo.value) == "Error parsing test_name: test_error" | ||
|
||
def test_missing_key_error(): | ||
with pytest.raises(MissingKeyError) as excinfo: | ||
raise MissingKeyError("test_key") | ||
assert str(excinfo.value) == "Missing key: test_key" | ||
|
||
def test_validation_error(): | ||
with pytest.raises(ValidationError) as excinfo: | ||
raise ValidationError("test_error") | ||
assert str(excinfo.value) == "Validation error: test_error" | ||
|
||
def test_type_error_submission(): | ||
with pytest.raises(TypeErrorSubmission) as excinfo: | ||
raise TypeErrorSubmission("test_error") | ||
assert str(excinfo.value) == "Type error: test_error" | ||
|
||
def test_runtime_error_submission(): | ||
with pytest.raises(RuntimeErrorSubmission) as excinfo: | ||
raise RuntimeErrorSubmission("test_error") | ||
assert str(excinfo.value) == "Runtime error: test_error" | ||
|
||
def test_get_submission_params_error(): | ||
with pytest.raises(GetSubmissionParamsError) as excinfo: | ||
raise GetSubmissionParamsError() | ||
assert str(excinfo.value) == "Block instance is not defined!" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.