|
7 | 7 | import unittest |
8 | 8 | import unittest.mock |
9 | 9 | import urllib.parse |
| 10 | +import os.path |
10 | 11 |
|
11 | 12 | import aiohttp |
12 | 13 | from aiohttp.client import ClientRequest, ClientResponse |
@@ -542,6 +543,39 @@ def test_chunked_length(self): |
542 | 543 | self.assertEqual(req.headers['TRANSFER-ENCODING'], 'chunked') |
543 | 544 | self.assertNotIn('CONTENT-LENGTH', req.headers) |
544 | 545 |
|
| 546 | + def test_file_upload_not_chunked(self): |
| 547 | + here = os.path.dirname(__file__) |
| 548 | + fname = os.path.join(here, 'sample.key') |
| 549 | + with open(fname, 'rb') as f: |
| 550 | + req = ClientRequest( |
| 551 | + 'post', 'http://python.org/', |
| 552 | + data=f) |
| 553 | + self.assertFalse(req.chunked) |
| 554 | + self.assertEqual(req.headers['CONTENT-LENGTH'], |
| 555 | + str(os.path.getsize(fname))) |
| 556 | + |
| 557 | + def test_file_upload_not_chunked_seek(self): |
| 558 | + here = os.path.dirname(__file__) |
| 559 | + fname = os.path.join(here, 'sample.key') |
| 560 | + with open(fname, 'rb') as f: |
| 561 | + f.seek(100) |
| 562 | + req = ClientRequest( |
| 563 | + 'post', 'http://python.org/', |
| 564 | + data=f) |
| 565 | + self.assertEqual(req.headers['CONTENT-LENGTH'], |
| 566 | + str(os.path.getsize(fname) - 100)) |
| 567 | + |
| 568 | + def test_file_upload_force_chunked(self): |
| 569 | + here = os.path.dirname(__file__) |
| 570 | + fname = os.path.join(here, 'sample.key') |
| 571 | + with open(fname, 'rb') as f: |
| 572 | + req = ClientRequest( |
| 573 | + 'post', 'http://python.org/', |
| 574 | + data=f, |
| 575 | + chunked=True) |
| 576 | + self.assertTrue(req.chunked) |
| 577 | + self.assertNotIn('CONTENT-LENGTH', req.headers) |
| 578 | + |
545 | 579 | def test_expect100(self): |
546 | 580 | req = ClientRequest('get', 'http://python.org/', |
547 | 581 | expect100=True, loop=self.loop) |
|
0 commit comments