Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test_form failed with treq 20.4.1 #339

Closed
yan12125 opened this issue Apr 26, 2020 · 10 comments
Closed

test_form failed with treq 20.4.1 #339

yan12125 opened this issue Apr 26, 2020 · 10 comments
Labels

Comments

@yan12125
Copy link

I'm the maintainer of Arch Linux package python-klein, and I run a periodic script to check compatibility among Python packages. Recently I notice tests in python-klein no longer work with python-treq 20.4.1.

Steps to reproduce:

  1. Clone commit c91085d of this repo

  2. Change the following line to treq==20.4.1

    klein/tox.ini

    Line 46 in c91085d

    {test,coverage}: treq==20.3.0

  3. Run tox -e coverage-py38-twcurrent

Actual results:

[FAIL]
Traceback (most recent call last):
  File "/home/yen/tmp/klein/.tox/coverage-py38-twcurrent/lib/python3.8/site-packages/klein/test/test_form.py", line 473, in test_customParameterValidation
    self.assertTrue(errorText.endswith("'not a number'"))
  File "/home/yen/tmp/klein/.tox/coverage-py38-twcurrent/lib/python3.8/site-packages/twisted/trial/_synctest.py", line 397, in assertTrue
    super(_Assertions, self).assertTrue(condition, msg)
  File "/usr/lib/python3.8/unittest/case.py", line 765, in assertTrue
    raise self.failureException(msg)
twisted.trial.unittest.FailTest: False is not true

klein.test.test_form.TestForms.test_customParameterValidation
===============================================================================
[FAIL]
Traceback (most recent call last):
  File "/home/yen/tmp/klein/.tox/coverage-py38-twcurrent/lib/python3.8/site-packages/klein/test/test_form.py", line 409, in test_handlingGET
    self.assertEqual(calls, [(u"hello, big world", 4321)])
  File "/home/yen/tmp/klein/.tox/coverage-py38-twcurrent/lib/python3.8/site-packages/twisted/trial/_synctest.py", line 434, in assertEqual
    super(_Assertions, self).assertEqual(first, second, msg)
  File "/usr/lib/python3.8/unittest/case.py", line 912, in assertEqual
    assertion_func(first, second, msg=msg)
  File "/usr/lib/python3.8/unittest/case.py", line 1118, in assertListEqual
    self.assertSequenceEqual(list1, list2, msg, seq_type=list)
  File "/usr/lib/python3.8/unittest/case.py", line 1100, in assertSequenceEqual
    self.fail(msg)
twisted.trial.unittest.FailTest: Lists differ: [('hello, big+world', 4321.0)] != [('hello, big world', 4321)]

First differing element 0:
('hello, big+world', 4321.0)
('hello, big world', 4321)

- [('hello, big+world', 4321.0)]
?              ^            --

+ [('hello, big world', 4321)]
?              ^


klein.test.test_form.TestForms.test_handlingGET

Expected results: tests pass

@twm
Copy link
Contributor

twm commented Apr 27, 2020

Here's the full test on trunk:

def test_handlingGET(self):
# type: () -> None
"""
A GET handler for a Form with Fields receives query parameters matching
those field names as input.
"""
router, calls = simpleFormRouter()
stub = StubTreq(router.resource())
response = self.successResultOf(
stub.get(
b"https://localhost/getme?name=hello,%20big+world&value=4321"
)
)
self.assertEqual(response.code, 200)
self.assertEqual(self.successResultOf(content(response)), b"got")
self.assertEqual(calls, [(u"hello, big world", 4321)])

This looks like a behavioral change in treq. twisted/treq#265 made treq always parse URLs with hyperlink, rather than passing bytes URLs through.

Hyperlink seems to be percent-encoding the + when parsing the URL:

>>> from hyperlink import parse
>>> u = parse(b"https://localhost/getme?name=hello,%20big+world&value=4321".decode('ascii'))
>>> u
DecodedURL(url=URL.from_text('https://localhost/getme?name=hello,%20big%2Bworld&value=4321'))
>>> u.to_uri().to_text().encode('ascii')
b'https://localhost/getme?name=hello,%20big%2Bworld&value=4321'

This seems like a bug to me. + in the query part should be treated like %20. For example, this is what the web API does:

u = new URL("https://localhost/getme?name=hello,%20big+world&value=4321");
console.log(u.searchParams.get("name"));
// outputs: hello, big world

@dol-sen
Copy link

dol-sen commented Jun 1, 2020

I can confirm this same error. But I am also getting a test fail at line 454 of test_customParameterValidation in test_form.py. The result is
"'not+a+number'" for
self.assertTrue( errorText.endswith("'not a number'") )

This sounds like the same hyperlink error

@wsanchez
Copy link
Member

wsanchez commented Jun 1, 2020

Hrm. I wonder why requires.io hasn't generated a PR with the treq update yet…

@yan12125
Copy link
Author

yan12125 commented Jun 2, 2020

There seems to be a bug in requires.io. treq 20.4.1 is released on Apr 17 [1] but the pull request created on Apr 19 [2] updated treq to 20.3.0.

[1] https://github.com/twisted/treq/releases/tag/release-20.4.1
[2] #337

@wsanchez
Copy link
Member

wsanchez commented Jun 2, 2020

OK I can open a PR and manually update some things, but I have a queue of PRs open that need review before I want to throw more on the pile.

@wsanchez
Copy link
Member

wsanchez commented Jun 3, 2020

OK #352 will update everything else, but we'll need a resolution on a fix to this before updating treq.

@wsanchez wsanchez mentioned this issue Sep 15, 2020
@wsanchez
Copy link
Member

See python-hyper/hyperlink#129 for debate as to whether this test is correct.

twm added a commit to twisted/treq that referenced this issue Dec 23, 2020
@twm
Copy link
Contributor

twm commented Jan 11, 2021

There was a Hyperlink release on Friday, so twisted/treq#304 is ready for review! I'll do a treq release as soon as that's in.

@yan12125
Copy link
Author

Thanks for the update! I can confirm with hyperlink 21.0.0, all klein tests are green.

@wsanchez
Copy link
Member

Thanks! Closing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants