Skip to content

Commit

Permalink
docs(testing): clean up the docs, tests and notes before merging
Browse files Browse the repository at this point in the history
  • Loading branch information
vytas7 committed Dec 8, 2024
1 parent fb8951c commit 7add3db
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 17 deletions.
6 changes: 5 additions & 1 deletion docs/_newsfragments/2262.newandimproved.rst
Original file line number Diff line number Diff line change
@@ -1 +1,5 @@
:py:func:`falcon.testing.helpers.create_scope` preserves the raw_path. This is to keep consistency with `#2159 <https://github.com/falconry/falcon/pull/2159>`_
Similar to :func:`~falcon.testing.create_environ`,
the :func:`~falcon.testing.create_scope` testing helper now preserves the raw URI path,
and propagates it to the created ASGI connection scope as the ``raw_path`` byte string
(according to the `ASGI specification
<https://asgi.readthedocs.io/en/latest/specs/www.html#http-connection-scope>`__).
22 changes: 6 additions & 16 deletions tests/test_recipes.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,33 +115,23 @@ def test_optional_indent(self, util):


class TestRawURLPath:
def path_extras(self, asgi, url):
if asgi:
return {'raw_path': url.encode()}
return None

def test_raw_path(self, asgi, app_kind, util):
recipe = util.load_module(
'raw_url_path', parent_dir='examples/recipes', suffix=app_kind
)

# TODO(vytas): Improve TestClient to automatically add ASGI raw_path
# (as it does for WSGI): GH #2262.

url1 = '/cache/http%3A%2F%2Ffalconframework.org'
result1 = falcon.testing.simulate_get(
recipe.app, url1, extras=self.path_extras(asgi, url1)
)
scope1 = falcon.testing.create_scope(url1)
result1 = falcon.testing.simulate_get(recipe.app, url1)
assert result1.status_code == 200
assert result1.json == {'url': 'http://falconframework.org'}

scope1 = falcon.testing.create_scope(url1)
assert scope1['raw_path'] == url1.encode()

url2 = '/cache/http%3A%2F%2Ffalconframework.org/status'
result2 = falcon.testing.simulate_get(
recipe.app, url2, extras=self.path_extras(asgi, url2)
)
scope2 = falcon.testing.create_scope(url2)
result2 = falcon.testing.simulate_get(recipe.app, url2)
assert result2.status_code == 200
assert result2.json == {'cached': True}

scope2 = falcon.testing.create_scope(url2)
assert scope2['raw_path'] == url2.encode()

0 comments on commit 7add3db

Please sign in to comment.