-
Notifications
You must be signed in to change notification settings - Fork 387
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixes: #846 Signed-off-by: Mathieu Parent <math.parent@gmail.com>
- Loading branch information
Showing
4 changed files
with
110 additions
and
3 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,33 @@ | ||
from io import BytesIO, StringIO | ||
|
||
import pytest | ||
|
||
from vcr import request | ||
from vcr.util import read_body | ||
|
||
|
||
@pytest.mark.parametrize( | ||
"input_, expected_output", | ||
[ | ||
(BytesIO(b"Stream"), b"Stream"), | ||
(StringIO("Stream"), b"Stream"), | ||
(iter(["StringIter"]), b"StringIter"), | ||
(iter(["String", "Iter"]), b"StringIter"), | ||
(iter([b"BytesIter"]), b"BytesIter"), | ||
(iter([b"Bytes", b"Iter"]), b"BytesIter"), | ||
(iter([70, 111, 111]), b"Foo"), | ||
(iter([]), b""), | ||
("String", b"String"), | ||
(b"Bytes", b"Bytes"), | ||
], | ||
) | ||
def test_read_body(input_, expected_output): | ||
r = request.Request("POST", "http://host.com/", input_, {}) | ||
assert read_body(r) == expected_output | ||
|
||
|
||
def test_unsupported_read_body(): | ||
r = request.Request("POST", "http://host.com/", iter([[]]), {}) | ||
with pytest.raises(ValueError) as excinfo: | ||
assert read_body(r) | ||
assert excinfo.value.args == ("Body type <class 'list'> not supported",) |
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