Skip to content

Commit

Permalink
refactor: restore AttributeRemovedError for resp.body (#2361)
Browse files Browse the repository at this point in the history
* refactor: restore `AttributeRemovedError` for `resp.body`

* chore: update Python version in E2E tox envs

* chore: disable E2E Firefox
  • Loading branch information
vytas7 authored Oct 9, 2024
1 parent 25027b2 commit 8c7b5c0
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 3 deletions.
4 changes: 3 additions & 1 deletion .github/workflows/tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,9 @@ jobs:
- env: "wsgi_servers"
# E2E tests
- env: "e2e_chrome"
- env: "e2e_firefox"
# TODO(vytas): Something is not working correctly with the
# newly released Firefox 131.0, SeleniumBase, and our tests.
# - env: "e2e_firefox"

steps:
- name: Checkout repo
Expand Down
14 changes: 14 additions & 0 deletions falcon/response.py
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,20 @@ def status_code(self) -> int:
def status_code(self, value: int) -> None:
self.status = value

@property
def body(self) -> NoReturn:
raise AttributeRemovedError(
'The body attribute is no longer supported. '
'Please use the text attribute instead.'
)

@body.setter
def body(self, value: str) -> NoReturn:
raise AttributeRemovedError(
'The body attribute is no longer supported. '
'Please use the text attribute instead.'
)

@property
def data(self) -> Optional[bytes]:
"""Byte string representing response content.
Expand Down
11 changes: 11 additions & 0 deletions tests/test_response.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,17 @@ def test_add_link_removed(resp):
resp.add_link('/things/1337', 'next')


def test_body_removed(resp):
# NOTE(kgriffs): Ensure AttributeRemovedError inherits from AttributeError
for exc_type in (AttributeError, AttributeRemovedError):
with pytest.raises(exc_type):
resp.body = '{"message": "Hello, World!"}'

for exc_type in (AttributeError, AttributeRemovedError):
with pytest.raises(exc_type):
resp.body


def test_response_attempt_to_set_read_only_headers(resp):
resp.append_header('x-things1', 'thing-1')
resp.append_header('x-things2', 'thing-2')
Expand Down
4 changes: 2 additions & 2 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -431,14 +431,14 @@ commands =
# --------------------------------------------------------------------

[testenv:e2e_chrome]
basepython = python3.10
basepython = python3.12
deps =
-r{toxinidir}/requirements/e2e
commands =
pytest {toxinidir}/e2e-tests/ --browser=chrome

[testenv:e2e_firefox]
basepython = python3.10
basepython = python3.12
deps =
-r{toxinidir}/requirements/e2e
commands =
Expand Down

0 comments on commit 8c7b5c0

Please sign in to comment.