Skip to content

Commit

Permalink
fixes after rebase
Browse files Browse the repository at this point in the history
  • Loading branch information
bandophahita committed Feb 13, 2024
1 parent 567b6c0 commit 87b25ba
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 7 deletions.
6 changes: 3 additions & 3 deletions screenpy_requests/questions/body_of_the_last_response.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from __future__ import annotations

from json.decoder import JSONDecodeError
from typing import TYPE_CHECKING
from typing import TYPE_CHECKING, Union

from screenpy.exceptions import UnableToAnswer
from screenpy.pacing import beat
Expand Down Expand Up @@ -56,6 +56,7 @@ class BodyOfTheLastResponse:
body_parts: list[subscripts]

def __getitem__(self, key: subscripts) -> BodyOfTheLastResponse:
"""Allows access to subscripts later in answered_by."""
self.body_parts.append(key)
return self

Expand All @@ -77,9 +78,8 @@ def answered_by(self, the_actor: Actor) -> dict | str:
response = responses[-1].json()
for part in self.body_parts:
response = response[part]
return response
except JSONDecodeError:
response = responses[-1].text
for part in self.body_parts:
response = response[part]
return response
return response
7 changes: 3 additions & 4 deletions tests/test_questions.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,12 @@ def test_ask_for_body_of_the_last_response(self, APITester: Actor) -> None:

assert BodyOfTheLastResponse().answered_by(APITester) == test_json

def test_stores_index_path(self):
def test_stores_index_path(self) -> None:
botlr = BodyOfTheLastResponse()["shuffled"]["off"][10]["mortal"]["coils"]

assert botlr.body_parts == ["shuffled", "off", 10, "mortal", "coils"]

def test_digs_into_json(self, APITester):
def test_digs_into_json(self, APITester: Actor) -> None:
test_json = {"plays": [{"name": "Hamlet"}]}
fake_response = mock.Mock()
fake_response.json.return_value = test_json
Expand All @@ -74,7 +74,7 @@ def test_digs_into_json(self, APITester):

assert botlr.answered_by(APITester) == "Hamlet"

def test_slices_text(self, APITester):
def test_slices_text(self, APITester: Actor) -> None:
test_text = "My favorite play is Hamlet."
fake_response = mock.Mock()
fake_response.json.return_value = test_text
Expand All @@ -84,7 +84,6 @@ def test_slices_text(self, APITester):
assert BodyOfTheLastResponse()[-7:-1].answered_by(APITester) == "Hamlet"



class TestCookies:
def test_can_be_instantiated(self) -> None:
c = Cookies()
Expand Down

0 comments on commit 87b25ba

Please sign in to comment.