Skip to content
This repository has been archived by the owner on Sep 12, 2023. It is now read-only.

Commit

Permalink
fix: ignore 405s in ControllerTest utility.
Browse files Browse the repository at this point in the history
If a method handler isn't registered, we ignore that test.

Closes #234
  • Loading branch information
peterschutt committed Jan 16, 2023
1 parent 8ddd2f2 commit 6221bab
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
12 changes: 11 additions & 1 deletion src/starlite_saqlalchemy/testing/controller_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,11 @@
import random
from typing import TYPE_CHECKING

from starlite.status_codes import HTTP_200_OK, HTTP_201_CREATED
from starlite.status_codes import (
HTTP_200_OK,
HTTP_201_CREATED,
HTTP_405_METHOD_NOT_ALLOWED,
)

if TYPE_CHECKING:
from collections.abc import Sequence
Expand Down Expand Up @@ -67,6 +71,9 @@ async def _list(*_: Any, **__: Any) -> list[Any]:
self.base_path, params=self.collection_filters if with_filters else None
)

if resp.status_code == HTTP_405_METHOD_NOT_ALLOWED:
return

assert resp.status_code == HTTP_200_OK
assert resp.json() == self.raw_collection

Expand All @@ -91,6 +98,9 @@ async def _method(*_: Any, **__: Any) -> Any:

resp = self.client.request(method, url, **request_kw)

if resp.status_code == HTTP_405_METHOD_NOT_ALLOWED:
return

assert resp.status_code == exp_status
assert resp.json() == raw

Expand Down
15 changes: 14 additions & 1 deletion tests/unit/test_testing.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,11 @@

import httpx
import pytest
from starlite.status_codes import HTTP_200_OK, HTTP_404_NOT_FOUND
from starlite.status_codes import (
HTTP_200_OK,
HTTP_404_NOT_FOUND,
HTTP_405_METHOD_NOT_ALLOWED,
)

from starlite_saqlalchemy import testing
from starlite_saqlalchemy.exceptions import ConflictError, StarliteSaqlalchemyError
Expand Down Expand Up @@ -210,3 +214,12 @@ def test_tester_run_method(params: dict[str, Any] | None) -> None:
("test_member_request", ("POST", "create", 201), {}),
("test_member_request", ("DELETE", "delete", 200), {}),
]


def test_tester_ignores_405_response(
tester: testing.ControllerTest, mock_response: MagicMock
) -> None:
"""Test that 405 responses don't raise from asserts."""
mock_response.status_code = HTTP_405_METHOD_NOT_ALLOWED
tester.test_get_collection()
tester.test_member_request("GET", "get", HTTP_200_OK)

0 comments on commit 6221bab

Please sign in to comment.