Skip to content

Commit

Permalink
Merge branch 'develop' into fix_pass_change_error
Browse files Browse the repository at this point in the history
  • Loading branch information
Anish9901 authored Apr 19, 2024
2 parents 15badf9 + dc1fc4d commit f06c44f
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 5 deletions.
10 changes: 5 additions & 5 deletions mathesar/tests/rpc/exceptions/test_error_codes.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
from http.client import CannotSendRequest
import pytest

from django.core.exceptions import FieldDoesNotExist
from psycopg.errors import BadCopyFileFormat
import pytest
from django.core.exceptions import FieldDoesNotExist
from mathesar.utils.connections import BadInstallationTarget
from db.functions.exceptions import UnknownDBFunctionID
from sqlalchemy.exc import IntegrityError
from http.client import CannotSendRequest

from db.functions.exceptions import UnknownDBFunctionID
from mathesar.utils.connections import BadInstallationTarget
import mathesar.rpc.exceptions.error_codes as err_codes


Expand Down
37 changes: 37 additions & 0 deletions mathesar/tests/rpc/exceptions/test_error_handler.py
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]

0 comments on commit f06c44f

Please sign in to comment.