'Test create lun.'

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

    fake_volume = VolumeClass('fakeDisplayName', 'fakeId', 100, 'fakeLunName')
    mock_http_connection.return_value.getresponse.side_effect = [FakeLoginResponse(), FakeGetBasicInfoResponse(), FakeLoginResponse(), FakeCreateLunResponse()]
    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.assertEqual('fakeLunIndex', self.driver.api_executor.create_lun(fake_volume, 'fakepool', 'fakeLun', 'False'))
    fake_params = {}
    fake_params['func'] = 'add_lun'
    fake_params['FileIO'] = 'no'
    fake_params['LUNThinAllocate'] = '1'
    fake_params['LUNName'] = 'fakeLun'
    fake_params['LUNPath'] = 'fakeLun'
    fake_params['poolID'] = 'fakepool'
    fake_params['lv_ifssd'] = 'no'
    fake_params['LUNCapacity'] = 100
    fake_params['lv_threshold'] = '80'
    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_lun_url = ('/cgi-bin/disk/iscsi_lun_setting.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_lun_url)]
    self.assertEqual(expected_call_list, mock_http_connection.return_value.request.call_args_list)
