-
-
Notifications
You must be signed in to change notification settings - Fork 363
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'develop' into fix_pass_change_error
- Loading branch information
Showing
2 changed files
with
42 additions
and
5 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,37 @@ | ||
import pytest | ||
|
||
from modernrpc.exceptions import RPCException | ||
from psycopg.errors import BadCopyFileFormat | ||
from django.core.exceptions import FieldDoesNotExist | ||
from mathesar.utils.connections import BadInstallationTarget | ||
from db.functions.exceptions import UnknownDBFunctionID | ||
from http.client import CannotSendRequest | ||
|
||
from mathesar.rpc.exceptions.handlers import handle_rpc_exceptions | ||
|
||
|
||
@handle_rpc_exceptions | ||
def fake_func(exception): | ||
raise exception | ||
|
||
|
||
@pytest.mark.parametrize( | ||
"example_err,expect_code", [ | ||
(AssertionError, -31002), | ||
(BadCopyFileFormat, -30009), | ||
(FieldDoesNotExist, -29030), | ||
(BadInstallationTarget, -28002), | ||
(UnknownDBFunctionID, -27024), | ||
(CannotSendRequest, -25031), | ||
] | ||
) | ||
def test_handle_rpc_exceptions(example_err, expect_code): | ||
""" | ||
Tests whether a function wrapped by `handle_rpc_exceptions` always raises a `RPCException` | ||
for any given exception raised inside the function. | ||
""" | ||
with pytest.raises(RPCException) as rpc_exception: | ||
fake_func(example_err) | ||
assert hasattr(fake_func, '__wrapped__') | ||
assert example_err.__name__ in rpc_exception.value.args[0] | ||
assert str(expect_code) in rpc_exception.value.args[0] |