Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(37)

Side by Side Diff: Lib/test/test_urllib2.py

Issue 17485: Deleting Request data does not update Content-length header.
Patch Set: Created 6 years, 10 months ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | Lib/urllib/request.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 import unittest 1 import unittest
2 from test import support 2 from test import support
3 3
4 import os 4 import os
5 import io 5 import io
6 import socket 6 import socket
7 import array 7 import array
8 import sys 8 import sys
9 9
10 import urllib.request 10 import urllib.request
(...skipping 1424 matching lines...) Expand 10 before | Expand all | Expand 10 after
1435 request = urllib.request.Request("http://www.python.org/~jeremy/") 1435 request = urllib.request.Request("http://www.python.org/~jeremy/")
1436 self.assertEqual(None, request.data) 1436 self.assertEqual(None, request.data)
1437 1437
1438 opener.open(request, "1".encode("us-ascii")) 1438 opener.open(request, "1".encode("us-ascii"))
1439 self.assertEqual(b"1", request.data) 1439 self.assertEqual(b"1", request.data)
1440 self.assertEqual("1", request.get_header("Content-length")) 1440 self.assertEqual("1", request.get_header("Content-length"))
1441 1441
1442 opener.open(request, "1234567890".encode("us-ascii")) 1442 opener.open(request, "1234567890".encode("us-ascii"))
1443 self.assertEqual(b"1234567890", request.data) 1443 self.assertEqual(b"1234567890", request.data)
1444 self.assertEqual("10", request.get_header("Content-length")) 1444 self.assertEqual("10", request.get_header("Content-length"))
1445
1446 del request.data
1447 opener.open(request)
1448
1449 self.assertEqual(None, request.data)
1450 self.assertEqual(None, request.get_header("Content-length"))
1445 1451
1446 def test_HTTPError_interface(self): 1452 def test_HTTPError_interface(self):
1447 """ 1453 """
1448 Issue 13211 reveals that HTTPError didn't implement the URLError 1454 Issue 13211 reveals that HTTPError didn't implement the URLError
1449 interface even though HTTPError is a subclass of URLError. 1455 interface even though HTTPError is a subclass of URLError.
1450 1456
1451 >>> msg = 'something bad happened' 1457 >>> msg = 'something bad happened'
1452 >>> url = code = fp = None 1458 >>> url = code = fp = None
1453 >>> hdrs = 'Content-Length: 42' 1459 >>> hdrs = 'Content-Length: 42'
1454 >>> err = urllib.error.HTTPError(url, code, msg, hdrs, fp) 1460 >>> err = urllib.error.HTTPError(url, code, msg, hdrs, fp)
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
1536 support.run_doctest(urllib.request, verbose) 1542 support.run_doctest(urllib.request, verbose)
1537 tests = (TrivialTests, 1543 tests = (TrivialTests,
1538 OpenerDirectorTests, 1544 OpenerDirectorTests,
1539 HandlerTests, 1545 HandlerTests,
1540 MiscTests, 1546 MiscTests,
1541 RequestTests) 1547 RequestTests)
1542 support.run_unittest(*tests) 1548 support.run_unittest(*tests)
1543 1549
1544 if __name__ == "__main__": 1550 if __name__ == "__main__":
1545 test_main(verbose=True) 1551 test_main(verbose=True)
OLDNEW
« no previous file with comments | « no previous file | Lib/urllib/request.py » ('j') | no next file with comments »

RSS Feeds Recent Issues | This issue
This is Rietveld 894c83f36cb7+