def test_file_continue(self): writer = OverwriteFileWriter(self.get_path_namer(), file_continuing=True) session = writer.session() with open('my_file.txt', 'wb') as file: file.write(b'TEST') request = HTTPRequest('http://example.com/my_file.txt') session.process_request(request) self.assertIn('Range', request.fields) response = HTTPResponse(status_code=206, reason='Partial content', request=request) session.process_response(response) response.body.write(b'END') response.body.flush() session.save_document(response) with open('my_file.txt', 'rb') as file: data = file.read() self.assertEqual(b'TESTEND', data)
def test_dir_or_file_dir_got_first(self): writer = OverwriteFileWriter(self.get_path_namer()) session = writer.session() os.mkdir('dir_or_file') request = HTTPRequest('http://example.com/dir_or_file') response = HTTPResponse(status_code=200, reason='OK', request=request) session.process_request(request) session.process_response(response) session.save_document(response) print(list(os.walk('.'))) self.assertTrue(os.path.isdir('dir_or_file')) self.assertTrue(os.path.isfile('dir_or_file.f'))