Skip to content

Commit

Permalink
Moves the upload session files endpoint to upload-sessions/files/ (#1139
Browse files Browse the repository at this point in the history
)

Tidies up the router definition so that the endpoints
are in alphabetical order.
  • Loading branch information
jmsmkn authored Jan 31, 2020
1 parent 0ecbfc8 commit a3613cb
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 27 deletions.
44 changes: 28 additions & 16 deletions app/grandchallenge/api/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,30 +30,34 @@
app_name = "api"

router = routers.DefaultRouter()

# Algorithms
router.register(
r"cases/upload-sessions",
RawImageUploadSessionViewSet,
basename="upload-session",
r"algorithms/images", AlgorithmImageViewSet, basename="algorithms-image"
)
router.register(r"algorithms/jobs", JobViewSet, basename="algorithms-job")
router.register(
r"cases/image-files", RawImageFileViewSet, basename="image-file"
r"algorithms/results", ResultViewSet, basename="algorithms-result"
)
router.register(r"algorithms", AlgorithmViewSet, basename="algorithm")

# Cases
router.register(r"cases/images", ImageViewSet, basename="image")
router.register(r"workstations/sessions", SessionViewSet)
router.register(
r"workstations/configs",
WorkstationConfigViewSet,
basename="workstations-config",
)
router.register(r"algorithms/jobs", JobViewSet, basename="algorithms-job")
router.register(
r"algorithms/results", ResultViewSet, basename="algorithms-result"
r"cases/upload-sessions/files",
RawImageFileViewSet,
basename="upload-session-file",
)
router.register(
r"algorithms/images", AlgorithmImageViewSet, basename="algorithms-image"
r"cases/upload-sessions",
RawImageUploadSessionViewSet,
basename="upload-session",
)
router.register(r"algorithms", AlgorithmViewSet, basename="algorithm")

# Chunked uploads
router.register(r"chunked-uploads", StagedFileViewSet, basename="staged-file")

# Reader studies
router.register(
r"reader-studies/answers", AnswerViewSet, basename="reader-studies-answer"
)
Expand All @@ -63,15 +67,23 @@
basename="reader-studies-question",
)
router.register(r"reader-studies", ReaderStudyViewSet, basename="reader-study")
router.register(r"chunked-uploads", StagedFileViewSet, basename="staged-file")

# Retina
router.register(
r"retina/landmark-annotation",
LandmarkAnnotationSetViewSet,
basename="landmark-annotation",
)

# TODO: add terms_of_service and contact
# Workstations
router.register(
r"workstations/configs",
WorkstationConfigViewSet,
basename="workstations-config",
)
router.register(r"workstations/sessions", SessionViewSet)


schema_view = get_schema_view(
openapi.Info(
title=f"{settings.SESSION_COOKIE_DOMAIN.lstrip('.')} API",
Expand Down
4 changes: 3 additions & 1 deletion app/grandchallenge/cases/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,9 @@ class RawImageFile(UUIDModel):

@property
def api_url(self):
return reverse("api:image-file-detail", kwargs={"pk": self.pk})
return reverse(
"api:upload-session-file-detail", kwargs={"pk": self.pk}
)

def save(self, *args, **kwargs):
adding = self._state.adding
Expand Down
20 changes: 10 additions & 10 deletions app/tests/cases_tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ def test_image_file_list(client):
RawImageFileFactory(upload_session=us1)

response = get_view_for_user(
viewname="api:image-file-list",
viewname="api:upload-session-file-list",
client=client,
user=u1,
content_type="application/json",
Expand All @@ -148,7 +148,7 @@ def test_image_file_list(client):
assert response.json()["count"] == 1

response = get_view_for_user(
viewname="api:image-file-list",
viewname="api:upload-session-file-list",
client=client,
user=u2,
content_type="application/json",
Expand All @@ -164,15 +164,15 @@ def test_image_file_detail(client):
rif = RawImageFileFactory(upload_session=us)

response = get_view_for_user(
viewname="api:image-file-detail",
viewname="api:upload-session-file-detail",
reverse_kwargs={"pk": rif.pk},
client=client,
user=u1,
)
assert response.status_code == 200

response = get_view_for_user(
viewname="api:image-file-detail",
viewname="api:upload-session-file-detail",
reverse_kwargs={"pk": rif.pk},
client=client,
user=u2,
Expand All @@ -190,7 +190,7 @@ def test_image_file_create(client):
)

response = get_view_for_user(
viewname="api:image-file-list",
viewname="api:upload-session-file-list",
user=user,
client=client,
method=client.post,
Expand All @@ -208,7 +208,7 @@ def test_image_file_create(client):
upload_session = RawImageUploadSessionFactory()

response = get_view_for_user(
viewname="api:image-file-list",
viewname="api:upload-session-file-list",
user=user,
client=client,
method=client.post,
Expand All @@ -226,7 +226,7 @@ def test_invalid_image_file_post(client):
user = UserFactory(is_staff=True)

response = get_view_for_user(
viewname="api:image-file-list",
viewname="api:upload-session-file-list",
user=user,
client=client,
method=client.post,
Expand All @@ -240,7 +240,7 @@ def test_invalid_image_file_post(client):

upload_session = RawImageUploadSessionFactory()
response = get_view_for_user(
viewname="api:image-file-list",
viewname="api:upload-session-file-list",
user=user,
client=client,
method=client.post,
Expand All @@ -256,7 +256,7 @@ def test_empty_data_image_files(client):
user = UserFactory(is_staff=True)

response = get_view_for_user(
viewname="api:image-file-list",
viewname="api:upload-session-file-list",
user=user,
client=client,
method=client.post,
Expand All @@ -281,7 +281,7 @@ def test_image_file_post_permissions(client, is_active, expected_response):
creator=user, algorithm_image=algo
)
response = get_view_for_user(
viewname="api:image-file-list",
viewname="api:upload-session-file-list",
user=user,
client=client,
method=client.post,
Expand Down

0 comments on commit a3613cb

Please sign in to comment.