-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #847 from ImageMarkup/isic-161-add-lesion-retrieval
Add lesion listing endpoint
- Loading branch information
Showing
7 changed files
with
174 additions
and
3 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
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
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,73 @@ | ||
import pytest | ||
from pytest_lazyfixture import lazy_fixture | ||
|
||
|
||
@pytest.mark.django_db | ||
def test_api_lesion(authenticated_client, lesion_factory, image_factory): | ||
lesion = lesion_factory() | ||
image_factory(accession__lesion=lesion) | ||
|
||
resp = authenticated_client.get("/api/v2/lesions/") | ||
assert resp.status_code == 200, resp.json() | ||
|
||
|
||
@pytest.mark.django_db | ||
def test_api_lesion_ignores_imageless_lesions(authenticated_client, lesion_factory, user): | ||
# give access to the lesion to ensure this isn't passing due to lack of permissions | ||
lesion_factory(cohort__contributor__owners=[user]) | ||
|
||
resp = authenticated_client.get("/api/v2/lesions/") | ||
assert resp.status_code == 200, resp.json() | ||
assert len(resp.json()["results"]) == 0 | ||
|
||
|
||
@pytest.mark.django_db | ||
@pytest.mark.parametrize( | ||
["client_", "image_public_states", "expected_lesion_count"], | ||
[ | ||
[lazy_fixture("client"), [True, True], 1], | ||
[lazy_fixture("client"), [True, False], 0], | ||
[lazy_fixture("client"), [False, False], 0], | ||
[lazy_fixture("authenticated_client"), [True, True], 1], | ||
[lazy_fixture("authenticated_client"), [True, False], 0], | ||
[lazy_fixture("authenticated_client"), [False, False], 0], | ||
[lazy_fixture("staff_client"), [True, True], 1], | ||
[lazy_fixture("staff_client"), [True, False], 1], | ||
[lazy_fixture("staff_client"), [False, False], 1], | ||
], | ||
) | ||
def test_api_lesion_permissions_public( | ||
client_, | ||
image_public_states, | ||
expected_lesion_count, | ||
lesion_factory, | ||
image_factory, | ||
user_factory, | ||
user, | ||
): | ||
other_user = user_factory() | ||
lesion = lesion_factory(cohort__contributor__owners=[other_user]) | ||
|
||
for public in image_public_states: | ||
image_factory( | ||
accession__lesion=lesion, | ||
public=public, | ||
accession__cohort__contributor__owners=[other_user], | ||
) | ||
|
||
resp = client_.get("/api/v2/lesions/") | ||
assert resp.status_code == 200, resp.json() | ||
assert len(resp.json()["results"]) == expected_lesion_count | ||
|
||
|
||
@pytest.mark.django_db | ||
def test_api_lesion_permissions_contributor( | ||
authenticated_client, lesion_factory, image_factory, contributor | ||
): | ||
lesion = lesion_factory() | ||
image_factory( | ||
accession__lesion=lesion, accession__cohort__contributor=contributor, public=False | ||
) | ||
|
||
resp = authenticated_client.get("/api/v2/lesions/") | ||
assert resp.status_code == 200, resp.json() |
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