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

error thrown when provided invalid uid #84

Merged
merged 10 commits into from
Apr 20, 2021
Merged

error thrown when provided invalid uid #84

merged 10 commits into from
Apr 20, 2021

Conversation

Anwesh1
Copy link
Contributor

@Anwesh1 Anwesh1 commented Apr 15, 2021

This handles the scenario when only a uid is provided without the text and this uid is invalid. The response looks like this:

image

P.S. I made an accidental pull request before this, but I closed it. Hopefully that doesn't cause any issues.

closes #81

@Anwesh1 Anwesh1 requested a review from JohnGiorgi April 15, 2021 15:53
semantic_search/ncbi.py Outdated Show resolved Hide resolved
@JohnGiorgi
Copy link
Collaborator

JohnGiorgi commented Apr 16, 2021

Cool! I left one comment.

Also, think you could add a test here to make sure that an invalid PMID throws an error? Pytest supports out of the box: https://docs.pytest.org/en/reorganize-docs/new-docs/user/pytest_raises.html

@Anwesh1
Copy link
Contributor Author

Anwesh1 commented Apr 18, 2021

Hey @JohnGiorgi, I'm not exactly sure why this codecov/patch check is failing.

@JohnGiorgi
Copy link
Collaborator

Hey @JohnGiorgi, I'm not exactly sure why this codecov/patch check is failing.

Don't worry about that!

Can you add a test that checks that this error is thrown for an invalid pmid? I linked some relevant pytest documentation above

@Anwesh1
Copy link
Contributor Author

Anwesh1 commented Apr 19, 2021

Hey @JohnGiorgi, I was trying something like this:

import pytest

from fastapi.exceptions import HTTPException

from semantic_search import ncbi
from semantic_search.ncbi import uids_to_docs

def test_invalid_uid_test():
    with pytest.raises(HTTPException):
        uid = ['93846392868']
        uids_to_docs(uid)

However, the pytest test failed and said this:

    def test_invalid_uid_test():
        with pytest.raises(HTTPException):
            uid = ['93846392868']
>           uids_to_docs(uid)
E           Failed: DID NOT RAISE <class 'fastapi.exceptions.HTTPException'>

tests/test_ncbi.py:11: Failed

Do I need to actually start up the FastAPI app?

@JohnGiorgi
Copy link
Collaborator

Weird! No I don't think we need to start the app unless I am really misunderstanding.

What if you just remove the "with" statement and see what kind of error is raised for that PMID

@Anwesh1
Copy link
Contributor Author

Anwesh1 commented Apr 19, 2021

When I send that request on Insomnia with this uid, I get the invalid uid HTTPException. However, if I take out the with statement, the pytest test passes with no errors.

@JohnGiorgi
Copy link
Collaborator

JohnGiorgi commented Apr 19, 2021

It is _medline_to_docs you added the new code to, right? I think that is the function that the unit test should call then

@Anwesh1
Copy link
Contributor Author

Anwesh1 commented Apr 19, 2021

Oh I see, I was going to call the whole process but this works now, I have updated it.

semantic_search/ncbi.py Outdated Show resolved Hide resolved
tests/test_ncbi.py Outdated Show resolved Hide resolved
@JohnGiorgi
Copy link
Collaborator

LGTM!

@JohnGiorgi JohnGiorgi mentioned this pull request Apr 20, 2021
@Anwesh1 Anwesh1 merged commit 613032c into develop Apr 20, 2021
@jvwong jvwong deleted the invalid_uid branch December 14, 2021 19:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants