Skip to content

Commit

Permalink
Reuse endpoint description in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
sergey-misuk-valor committed May 20, 2024
1 parent 4876d5f commit 4ed7832
Showing 1 changed file with 13 additions and 25 deletions.
38 changes: 13 additions & 25 deletions tests/api/test_auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,39 +23,27 @@
PK = uuid4()


@mark.parametrize(
("view_name", "method", "args"),
(
(DEDUPLICATION_SET_LIST_VIEW, HTTPMethod.GET, ()),
(DEDUPLICATION_SET_LIST_VIEW, HTTPMethod.POST, ()),
(DEDUPLICATION_SET_DETAIL_VIEW, HTTPMethod.DELETE, (PK,)),
(IMAGE_LIST_VIEW, HTTPMethod.GET, (PK,)),
(IMAGE_LIST_VIEW, HTTPMethod.POST, (PK,)),
(BULK_IMAGE_LIST_VIEW, HTTPMethod.POST, (PK,)),
(IMAGE_DETAIL_VIEW, HTTPMethod.DELETE, (PK, PK)),
(BULK_IMAGE_CLEAR_VIEW, HTTPMethod.DELETE, (PK,)),
),
REQUESTS = (
(DEDUPLICATION_SET_LIST_VIEW, HTTPMethod.GET, ()),
(DEDUPLICATION_SET_LIST_VIEW, HTTPMethod.POST, ()),
(DEDUPLICATION_SET_DETAIL_VIEW, HTTPMethod.DELETE, (PK,)),
(IMAGE_LIST_VIEW, HTTPMethod.GET, (PK,)),
(IMAGE_LIST_VIEW, HTTPMethod.POST, (PK,)),
(BULK_IMAGE_LIST_VIEW, HTTPMethod.POST, (PK,)),
(IMAGE_DETAIL_VIEW, HTTPMethod.DELETE, (PK, PK)),
(BULK_IMAGE_CLEAR_VIEW, HTTPMethod.DELETE, (PK,)),
)


@mark.parametrize(("view_name", "method", "args"), REQUESTS)
def test_anonymous_cannot_access(
anonymous_api_client: APIClient, view_name: str, method: HTTPMethod, args: tuple[Any, ...]
) -> None:
response = getattr(anonymous_api_client, method.lower())(reverse(view_name, args))
assert response.status_code == status.HTTP_401_UNAUTHORIZED


@mark.parametrize(
("view_name", "method", "args"),
(
(DEDUPLICATION_SET_LIST_VIEW, HTTPMethod.GET, ()),
(DEDUPLICATION_SET_LIST_VIEW, HTTPMethod.POST, ()),
(DEDUPLICATION_SET_DETAIL_VIEW, HTTPMethod.DELETE, (PK,)),
(IMAGE_LIST_VIEW, HTTPMethod.GET, (PK,)),
(IMAGE_LIST_VIEW, HTTPMethod.POST, (PK,)),
(BULK_IMAGE_LIST_VIEW, HTTPMethod.POST, (PK,)),
(IMAGE_DETAIL_VIEW, HTTPMethod.DELETE, (PK, PK)),
(BULK_IMAGE_CLEAR_VIEW, HTTPMethod.DELETE, (PK,)),
),
)
@mark.parametrize(("view_name", "method", "args"), REQUESTS)
def test_authenticated_can_access(
api_client: APIClient, view_name: str, method: HTTPMethod, args: tuple[Any, ...]
) -> None:
Expand Down

0 comments on commit 4ed7832

Please sign in to comment.