def test_stream_to_vdi_tiny(self): mock_file = mock.Mock() mock_file.read.side_effect = ['a'] mock_conn = mock.Mock() resp = mock.Mock() resp.status = '200' resp.reason = 'OK' mock_conn.getresponse.return_value = resp volume_utils._stream_to_vdi(mock_conn, '/path', 1, mock_file) args, kwargs = mock_conn.request.call_args self.assertEqual(kwargs['headers']['Content-Length'], '1') mock_file.read.assert_called_once_with(1) mock_conn.send.assert_called_once_with('a')
def test_stream_to_vdi_chunk_remaining(self): mock_file = mock.Mock() mock_file.read.side_effect = ['aaaaa', 'bb'] mock_conn = mock.Mock() resp = mock.Mock() resp.status = '200' resp.reason = 'OK' mock_conn.getresponse.return_value = resp tot_size = 16 * 1024 + 1024 volume_utils._stream_to_vdi(mock_conn, '/path', tot_size, mock_file) args, kwargs = mock_conn.request.call_args self.assertEqual(kwargs['headers']['Content-Length'], str(tot_size)) mock_file.read.assert_has_calls([mock.call(16 * 1024), mock.call(1024)]) mock_conn.send.assert_has_calls([mock.call('aaaaa'), mock.call('bb')])
def test_stream_to_vdi_chunk_remaining(self): mock_file = mock.Mock() mock_file.read.side_effect = ['aaaaa', 'bb'] mock_conn = mock.Mock() resp = mock.Mock() resp.status = '200' resp.reason = 'OK' mock_conn.getresponse.return_value = resp tot_size = 16 * 1024 + 1024 volume_utils._stream_to_vdi(mock_conn, '/path', tot_size, mock_file) args, kwargs = mock_conn.request.call_args self.assertEqual(kwargs['headers']['Content-Length'], str(tot_size)) mock_file.read.assert_has_calls( [mock.call(16 * 1024), mock.call(1024)]) mock_conn.send.assert_has_calls([mock.call('aaaaa'), mock.call('bb')])