Skip to content

Commit

Permalink
changed to have only one rest fixture
Browse files Browse the repository at this point in the history
  • Loading branch information
ZohebShaikh committed Oct 17, 2024
1 parent 697e7c9 commit 8ad8d9b
Showing 1 changed file with 7 additions and 12 deletions.
19 changes: 7 additions & 12 deletions tests/unit_tests/client/test_rest.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,9 @@
from blueapi.service.model import PlanModel, PlanResponse


@pytest.fixture
def rest() -> BlueapiRestClient:
return BlueapiRestClient()


@pytest.fixture
@responses.activate
def rest_with_auth() -> BlueapiRestClient:
def rest() -> BlueapiRestClient:
responses.add(
responses.GET,
"http://example.com",
Expand Down Expand Up @@ -65,7 +60,7 @@ class MyModel(BaseModel):


@responses.activate
def test_auth_request_functionality(rest_with_auth: BlueapiRestClient):
def test_auth_request_functionality(rest: BlueapiRestClient):
plan = Plan(name="my-plan", model=MyModel)
responses.add(
responses.GET,
Expand All @@ -77,13 +72,13 @@ def test_auth_request_functionality(rest_with_auth: BlueapiRestClient):
# Mock the verify_token function to return True (indicating a valid token)
mock_verify_token.return_value = True

result = rest_with_auth.get_plans()
result = rest.get_plans()
# Add assertions as needed
assert result == PlanResponse(plans=[PlanModel.from_plan(plan)])


@responses.activate
def test_refresh_if_signature_expired(rest_with_auth: BlueapiRestClient):
def test_refresh_if_signature_expired(rest: BlueapiRestClient):
plan = Plan(name="my-plan", model=MyModel)
responses.add(
responses.GET,
Expand All @@ -97,12 +92,12 @@ def test_refresh_if_signature_expired(rest_with_auth: BlueapiRestClient):
):
mock_verify_token.side_effect = jwt.ExpiredSignatureError
mock_refresh_token.return_value = True
result = rest_with_auth.get_plans()
result = rest.get_plans()
assert result == PlanResponse(plans=[PlanModel.from_plan(plan)])


@responses.activate
def test_handle_exceptions_other_than_expired_token(rest_with_auth: BlueapiRestClient):
def test_handle_exceptions_other_than_expired_token(rest: BlueapiRestClient):
plan = Plan(name="my-plan", model=MyModel)
responses.add(
responses.GET,
Expand All @@ -114,5 +109,5 @@ def test_handle_exceptions_other_than_expired_token(rest_with_auth: BlueapiRestC
patch("blueapi.service.Authenticator.verify_token") as mock_verify_token,
):
mock_verify_token.side_effect = Exception
result = rest_with_auth.get_plans()
result = rest.get_plans()
assert result == PlanResponse(plans=[PlanModel.from_plan(plan)])

0 comments on commit 8ad8d9b

Please sign in to comment.