Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Exception handler tests #3547

Merged
merged 2 commits into from
Apr 18, 2024
Merged

Exception handler tests #3547

merged 2 commits into from
Apr 18, 2024

Conversation

Anish9901
Copy link
Member

Related to #3524

This adds tests for the error handling decorator handle_rpc_exceptions, and verifies a function wrapped always raises a RPCException

Checklist

  • My pull request has a descriptive title (not a vague title like Update index.md).
  • My pull request targets the develop branch of the repository
  • My commit messages follow best practices.
  • My code follows the established code style of the repository.
  • I added tests for the changes I made (if applicable).
  • I added or updated documentation (if applicable).
  • I tried running the project locally and verified that there are no
    visible errors.

Developer Certificate of Origin

Developer Certificate of Origin
Developer Certificate of Origin
Version 1.1

Copyright (C) 2004, 2006 The Linux Foundation and its contributors.
1 Letterman Drive
Suite D4700
San Francisco, CA, 94129

Everyone is permitted to copy and distribute verbatim copies of this
license document, but changing it is not allowed.


Developer's Certificate of Origin 1.1

By making a contribution to this project, I certify that:

(a) The contribution was created in whole or in part by me and I
    have the right to submit it under the open source license
    indicated in the file; or

(b) The contribution is based upon previous work that, to the best
    of my knowledge, is covered under an appropriate open source
    license and I have the right under that license to submit that
    work with modifications, whether created in whole or in part
    by me, under the same open source license (unless I am
    permitted to submit under a different license), as indicated
    in the file; or

(c) The contribution was provided directly to me by some other
    person who certified (a), (b) or (c) and I have not modified
    it.

(d) I understand and agree that this project and the contribution
    are public and that a record of the contribution (including all
    personal information I submit with it, including my sign-off) is
    maintained indefinitely and may be redistributed consistent with
    this project or the open source license(s) involved.

@Anish9901 Anish9901 requested a review from mathemancer April 17, 2024 19:35
@Anish9901 Anish9901 added the pr-status: review A PR awaiting review label Apr 17, 2024
Copy link
Contributor

@mathemancer mathemancer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Test looks good, but the imports are (re)ordered strangely.

Is there a reason for the non-standard import sorting? If not, just use the style I recommended, please.

Comment on lines -1 to 10
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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did an automated tool reorder these imports? The new order is pretty non-standard. I'd rather have:

from http.client import CannotSendRequest

from django.core.exceptions import FieldDoesNotExist
from psycopg.errors import BadCopyFileFormat
import pytest
from sqlalchemy.exc import IntegrityError

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

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The imports should be grouped into:

  1. standard library
  2. 3rd party libraries
  3. local libraries (our code)

Sorting should be lexicographical by non-keyword within those groups.

Comment on lines +1 to +10
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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These are also sorted strangely.

@mathemancer mathemancer self-requested a review April 18, 2024 12:12
Copy link
Contributor

@mathemancer mathemancer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After discussing with @Anish9901 , I'm convinced there is a logic to the sorting of the imports in these test files.

@Anish9901 , Please add a comment or two about that logic, and then go ahead and merge this.

@Anish9901
Copy link
Member Author

I've sorted & grouped the imports based on "what's being tested" rather than "where are we importing from". Furthermore, if we try to see the imports through the lens of Arrange, Act and Assert we'll notice that the following imports are required for the Arrange step for the tests defined:

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

Similarly, we can think of the following import as something which will be Acted upon or rather the function that is to be tested.

from mathesar.rpc.exceptions.handlers import handle_rpc_exceptions

The first line is reserved for the imports that would be imported multiple times throughout our test files and for any imports that are required for rudementry python/pytest functions e.g. os, pytest etc.

@Anish9901 Anish9901 added this pull request to the merge queue Apr 18, 2024
Merged via the queue into develop with commit dc1fc4d Apr 18, 2024
36 checks passed
@Anish9901 Anish9901 deleted the exception_handler_tests branch April 18, 2024 17:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pr-status: review A PR awaiting review
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants