'Test clone snapshot.'

@mock.patch('six.moves.http_client.HTTPConnection')
def test_clone_snapshot(self, mock_http_connection):

    mock_http_connection.return_value.getresponse.side_effect = [FakeLoginResponse(), FakeGetBasicInfoResponse(), FakeLoginResponse(), FakeCreateSnapshotResponse()]
    self.driver = qnap.QnapISCSIDriver(configuration=create_configuration('admin', 'qnapadmin', 'http://1.2.3.4:8080', '1.2.3.4', 'Pool1', True))
    self.driver.do_setup('context')
    self.driver.api_executor.clone_snapshot('fakeSnapshotId', 'fakeLunName')
    fake_params = {}
    fake_params['func'] = 'clone_qsnapshot'
    fake_params['by_lun'] = '1'
    fake_params['snapshotID'] = 'fakeSnapshotId'
    fake_params['new_name'] = 'fakeLunName'
    fake_params['sid'] = 'fakeSid'
    sanitized_params = {}
    for key in fake_params:
        value = fake_params[key]
        if (value is not None):
            sanitized_params[key] = six.text_type(value)
    sanitized_params = urllib.parse.urlencode(sanitized_params)
    clone_snapshot_url = ('/cgi-bin/disk/snapshot.cgi?%s' % sanitized_params)
    expected_call_list = [mock.call('POST', login_url, global_sanitized_params, header), mock.call('GET', get_basic_info_url), mock.call('POST', login_url, global_sanitized_params, header), mock.call('GET', clone_snapshot_url)]
    self.assertEqual(expected_call_list, mock_http_connection.return_value.request.call_args_list)
