'Test create snapshot api.'

@mock.patch('six.moves.http_client.HTTPConnection')
def test_create_snapshot_api(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.create_snapshot_api('fakeLunIndex', 'fakeSnapshotName')
    fake_params = {}
    fake_params['func'] = 'create_snapshot'
    fake_params['lunID'] = 'fakeLunIndex'
    fake_params['snapshot_name'] = 'fakeSnapshotName'
    fake_params['expire_min'] = '0'
    fake_params['vital'] = '1'
    fake_params['snapshot_type'] = '0'
    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)
    create_snapshot_api_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', create_snapshot_api_url)]
    self.assertEqual(expected_call_list, mock_http_connection.return_value.request.call_args_list)
