-
Notifications
You must be signed in to change notification settings - Fork 35
204 Fix #213
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
204 Fix #213
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
# SPDX-FileCopyrightText: 2024 Justin Myers | ||
# | ||
# SPDX-License-Identifier: Unlicense | ||
|
||
"""Real call Tests""" | ||
|
||
import socket | ||
import ssl | ||
|
||
import adafruit_connection_manager | ||
import pytest | ||
|
||
import adafruit_requests | ||
|
||
|
||
@pytest.mark.parametrize( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These tests, do actual calls to httpbin. We should make sure not to add too many, but this should help us make sure we don't break anything... There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I agree with limiting the use of calls out to 3rd party services in the tests. This one is okay for now, but perhaps it would be good to add a simple httpserver script in the tests dir that the tests can then interact with. That way it can get the same functionality but be more self contained, and not reliant on actual network conditions (I had httpbin returning 503 for a moment which I think would've caused the test to fail). There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @justmobilize This did end up causing the test and thus actions check to fail: https://github.com/adafruit/Adafruit_CircuitPython_Requests/actions/runs/15278252260/job/42970208909#step:2:1007 With that in mind I think rather just not have our tests rely on the 3rd party service. If you have a moment and can PR removing this test, or altering it to use a local server please do. I can circle back in a day or two and do it if you don't. |
||
("path", "status_code", "text_result", "json_keys"), | ||
( | ||
("get", 200, None, {"url": "https://httpbin.org/get"}), | ||
("status/200", 200, "", None), | ||
("status/204", 204, "", None), | ||
), | ||
) | ||
def test_gets(path, status_code, text_result, json_keys): | ||
requests = adafruit_requests.Session(socket, ssl.create_default_context()) | ||
with requests.get(f"https://httpbin.org/{path}") as response: | ||
assert response.status_code == status_code | ||
if text_result is not None: | ||
assert response.text == text_result | ||
if json_keys is not None: | ||
for key, value in json_keys.items(): | ||
assert response.json()[key] == value | ||
|
||
adafruit_connection_manager.connection_manager_close_all(release_references=True) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@FoamyGuy This is the only way we can also do the HEAD check (which would also have no content). Are we good with this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Makes sense to me.