-
-
Notifications
You must be signed in to change notification settings - Fork 263
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Changed Response to use body: bytes (#375)
* Changed Response to use body: bytes - Added ActixBytesWrapper to conform to pyclass and MessageBody * Made suggested improvements to allow both PyString and PyBytes - Reverted unnecessary casting and type changes * Added test for supplying unsupported type to body - WIP: Issue with async testing * Remove unused unsupported type test due to issues with raises * Fixed issue where .unwrap causes Panic and instead raises Exception - Added tests for bad and good body types * Removed unused return - Parameterized body test fixtures --------- Co-authored-by: Antoine Romero-Romero <45259848+AntoineRR@users.noreply.github.com>
- Loading branch information
1 parent
7e24f9c
commit 4ef66b5
Showing
6 changed files
with
196 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import requests | ||
|
||
BASE_URL = "http://127.0.0.1:8080" | ||
|
||
|
||
def test_binary_output_sync(session): | ||
r = requests.get(f"{BASE_URL}/binary_output_sync") | ||
assert r.status_code == 200 | ||
assert r.headers["Content-Type"] == "application/octet-stream" | ||
assert r.text == "OK" | ||
|
||
|
||
def test_binary_output_response_sync(session): | ||
r = requests.get(f"{BASE_URL}/binary_output_response_sync") | ||
assert r.status_code == 200 | ||
assert r.headers["Content-Type"] == "application/octet-stream" | ||
assert r.text == "OK" | ||
|
||
|
||
def test_binary_output_async(session): | ||
r = requests.get(f"{BASE_URL}/binary_output_async") | ||
assert r.status_code == 200 | ||
assert r.headers["Content-Type"] == "application/octet-stream" | ||
assert r.text == "OK" | ||
|
||
|
||
def test_binary_output_response_async(session): | ||
r = requests.get(f"{BASE_URL}/binary_output_response_async") | ||
assert r.status_code == 200 | ||
assert r.headers["Content-Type"] == "application/octet-stream" | ||
assert r.text == "OK" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import pytest | ||
|
||
from robyn.robyn import Response | ||
|
||
|
||
class A: | ||
pass | ||
|
||
|
||
bad_bodies = [ | ||
None, | ||
1, | ||
True, | ||
A, | ||
{"body": "OK"}, | ||
["OK", b"OK"], | ||
Response( | ||
status_code=200, | ||
headers={}, | ||
body=b"OK", | ||
), | ||
] | ||
|
||
good_bodies = ["OK", b"OK"] | ||
|
||
|
||
@pytest.mark.parametrize("body", bad_bodies) | ||
def test_bad_body_types(body): | ||
with pytest.raises(ValueError): | ||
_ = Response( | ||
status_code=200, | ||
headers={}, | ||
body=body, | ||
) | ||
|
||
|
||
@pytest.mark.parametrize("body", good_bodies) | ||
def test_good_body_types(body): | ||
_ = Response( | ||
status_code=200, | ||
headers={}, | ||
body=body, | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters