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

Support header comparisons with dict or list. #1326

Merged
merged 5 commits into from
Sep 25, 2020

Conversation

musale
Copy link
Member

@musale musale commented Sep 25, 2020

Allows comparison of headers with dict or list:

response = httpx.get(...)
assert response.status_code == 200
assert response.text == "Hello, world!"
assert response.headers == {"Content-Length": "13"} # True
assert response.headers == [("Content-Length", "13")] # True

Closes #1325

@@ -23,7 +23,8 @@ def test_headers():
assert dict(h) == {"a": "123, 456", "b": "789"}
assert repr(h) == "Headers([('a', '123'), ('a', '456'), ('b', '789')])"
assert h == httpx.Headers([("a", "123"), ("b", "789"), ("a", "456")])
assert h != [("a", "123"), ("A", "456"), ("b", "789")]
assert h == [("a", "123"), ("A", "456"), ("b", "789")]
assert h == {"a": "123", "A": "456", "b": "789"}
Copy link
Member

Choose a reason for hiding this comment

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

To keep coverage at 100% we'll also need a test against a no-headers-like item.

Eg...

assert h != "a: 123\nA: 456\nb: 789"

Copy link
Member

@tomchristie tomchristie left a comment

Choose a reason for hiding this comment

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

Great, thanks!

There's also several other places in the test cases that could be fixed up too...

$ grep "== httpx.Headers" -r tests -n
tests/models/test_requests.py:29:    assert request.headers == httpx.Headers(
tests/models/test_requests.py:39:    assert request.headers == httpx.Headers(
tests/models/test_requests.py:52:    assert request.headers == httpx.Headers(
tests/models/test_requests.py:76:    assert request.headers == httpx.Headers(
tests/models/test_responses.py:47:    assert response.headers == httpx.Headers(
tests/models/test_responses.py:60:    assert response.headers == httpx.Headers(
tests/models/test_responses.py:74:    assert response.headers == httpx.Headers(
tests/models/test_responses.py:88:    assert response.headers == httpx.Headers(
tests/models/test_responses.py:745:    assert response.headers == httpx.Headers({"Transfer-Encoding": "chunked"})
tests/models/test_responses.py:754:    assert response.headers == httpx.Headers({"Content-Length": "8"})
tests/models/test_headers.py:25:    assert h == httpx.Headers([("a", "123"), ("b", "789"), ("a", "456")])```

@tomchristie tomchristie added the user-experience Ensuring that users have a good experience using the library label Sep 25, 2020
@musale
Copy link
Member Author

musale commented Sep 25, 2020

Great, let me fix up.

@@ -0,0 +1,3 @@
{
"python.pythonPath": "/Users/mus/Projects/httpx/venv/bin/python3"
}
Copy link
Member

Choose a reason for hiding this comment

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

We don't really want this file. You might want to setup a global gitignore to avoid including config that's specific to your local dev environment.

Copy link
Member Author

Choose a reason for hiding this comment

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

Slipped me. Fixing.

@tomchristie
Copy link
Member

Fantastic stuff! 💚
We're good to go on this, right?

@musale
Copy link
Member Author

musale commented Sep 25, 2020

I see my master is behind. Let me ff.

@musale
Copy link
Member Author

musale commented Sep 25, 2020

Oh you did it. perfect!

Copy link
Member

@tomchristie tomchristie left a comment

Choose a reason for hiding this comment

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

Ace!

@tomchristie tomchristie merged commit 815ef94 into encode:master Sep 25, 2020
@tomchristie tomchristie mentioned this pull request Sep 25, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
user-experience Ensuring that users have a good experience using the library
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support header comparisons with dict / list.
2 participants