Skip to content
Myr

Added a test to show a faulty behaviour when posting binary data for an object

Before adoption: this commit came in with the history the project adopted, so no landing records it.

with no __iter__

authored by tzickel · committed by tzickel · parent f0860bd · Browse files · 1 file+45 added−0 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

1 file+45 added−0 removed

  • tests:+45 added−0 removed

1 file+45 added−0 removed

modified:tests/test_requests.py+45 added
480 unmodified lines
481482 with pytest.raises(ValueError):483 requests.post(url, files=['bad file data'])484485 def test_POSTBIN_SEEKED_OBJECT_WITH_NO_ITER(self, httpbin):486487 class BufferedStream(object):488 def __init__(self, data):489 if isinstance(data, buffer):490 self.data = data491 else:492 self.data = buffer(data)493 self.length = len(self.data)494 self.index = 0495496 def __len__(self):497 return self.length498499 def read(self, size=None):500 if size:501 ret = buffer(self.data, self.index, size)502 self.index += size503 else:504 ret = buffer(self.data, self.index)505 self.index = self.length506 return ret507508 def tell(self):509 return self.index510511 def seek(self, offset, where=0):512 if where == 0:513 self.index = offset514 elif where == 1:515 self.index += offset516 elif where == 2:517 self.index = self.length + offset518519 test = BufferedStream('test')520 post1 = requests.post(httpbin('post'), data=test)521 assert post1.status_code == 200522 assert post1.json()['data'] == 'test'523524 test = BufferedStream('test')525 test.seek(2)526 post2 = requests.post(httpbin('post'), data=test)527 assert post2.status_code == 200528 assert post2.json()['data'] == 'st'529530 def test_POSTBIN_GET_POST_FILES_WITH_DATA(self, httpbin):531532 url = httpbin('post')533 requests.post(url).raise_for_status()
1047 unmodified lines