def test_chunked_hex(): # Test hex lengths c = http.ChunkedData() full_data = 'af\r\n' full_data += 'A' * 0xAF full_data += '\r\n' full_data += '0\r\n\r\n' c.add_data(full_data) assert c.complete assert c.body == 'A' * 0xAF c = http.ChunkedData() full_data = 'AF\r\n' full_data += 'A' * 0xAF full_data += '\r\n' full_data += '0\r\n\r\n' c.add_data(full_data) assert c.complete assert c.body == 'A' * 0xAF c = http.ChunkedData() full_data = 'aF\r\n' full_data += 'A' * 0xAF full_data += '\r\n' full_data += '0\r\n\r\n' c.add_data(full_data) assert c.complete assert c.body == 'A' * 0xAF
def test_chunked_leading_zeros(): # Test leading zeros c = http.ChunkedData() full_data = '000000000000000aF\r\n' full_data += 'A' * 0xAF full_data += '\r\n' full_data += '0\r\n\r\n' c.add_data(full_data) assert c.complete assert c.body == 'A' * 0xAF
def test_chunked_one_char_add(): # Test adding one character at a time c = http.ChunkedData() full_data = 'af\r\n' full_data += 'A' * 0xAF full_data += '\r\n' full_data += '0\r\n\r\n' for ch in full_data: c.add_data(ch) assert c.complete assert c.body == 'A' * 0xAF
def test_chunked_simple(): # Test a simple add_data c = http.ChunkedData() assert (not c.complete) full_data = '5\r\n' full_data += 'A' * 5 full_data += '\r\n' full_data += '0\r\n\r\n' c.add_data(full_data) assert c.complete assert c.body == 'A' * 5
def test_chunked_incomplete(): # Tests that complete isn't true until the data is received full_data = 'af\r\n' full_data += 'A' * 0xAF full_data += '\r\n' full_data += '0' # right now we're fine ending on 0 without \r\n for i in range(len(full_data) - 1): c = http.ChunkedData() c.add_data(full_data[:i]) assert not c.complete # Test incomplete one character at a time full_data = 'af\r\n' full_data += 'A' * 0xAF full_data += '\r\n' full_data += '0' # right now we're fine ending on 0 without \r\n for i in range(len(full_data) - 1): c = http.ChunkedData() for ii in range(i): c.add_data(full_data[ii]) assert not c.complete