Skip to content

add helper class to analyze response.location - #276

Open
bdauvergne wants to merge 2 commits into
Pylons:mainfrom
bdauvergne:wip/location
Open

add helper class to analyze response.location#276
bdauvergne wants to merge 2 commits into
Pylons:mainfrom
bdauvergne:wip/location

Conversation

@bdauvergne

@bdauvergne bdauvergne commented Jul 21, 2026

Copy link
Copy Markdown
Contributor

Suggestion by @gawel, a new webtest.utils.URL class used to return response.location/content_location/url and simplify tests, with pytest you can write things as simple as:

     assert resp.location.match('https://example.org/a/b/c')
     assert resp.location.match('?foo=bar')

and you get clear errors on output

        def test_location(self):
        app = webtest.TestApp(debug_app)
        res = app.post('/')
        res.location = 'http://pylons.org'
        self.assertTrue(res.location.match('http://'))
>       self.assertTrue(res.url.match('https://truc.org'))
E       AssertionError: scheme differs http != https is not true

@bdauvergne
bdauvergne force-pushed the wip/location branch 6 times, most recently from 3c1d374 to 201ff16 Compare July 22, 2026 06:57

@gawel gawel left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This project respect PEP8 80 char but you patch is not. Can you reformat your code ?

Can you also add a few doc strings/docs ? Maybe in docs/testresponse.rst

Comment thread webtest/utils.py Outdated
return self._response.headers.getall(headers)


class Error:

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you choose a more specific name ? Maybe URLMissMatch ?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok changed for URLMismatch.

Comment thread webtest/utils.py Outdated
errors.append(f'?{key}={value} was not expected.')

if errors:
return Error(' '.join(errors))

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can avoid this if and always return an object if Error.__bool__ is conditional

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

@bdauvergne
bdauvergne force-pushed the wip/location branch 2 times, most recently from a7589f1 to 99baf06 Compare August 5, 2026 08:51
@bdauvergne

Copy link
Copy Markdown
Contributor Author

This project respect PEP8 80 char but you patch is not. Can you reformat your code ?

It does not seem the case in tests/test_utils.py but ok.

Can you also add a few doc strings/docs ? Maybe in docs/testresponse.rst

Yep done.

@gawel

gawel commented Aug 5, 2026

Copy link
Copy Markdown
Member

LGTM. Thanks. I'll wait a few days before the merge in case someone wants to react

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants