2010-09-24 18:50:29 -05:00
|
|
|
/* Authors:
|
|
|
|
* Endi Sukma Dewata <edewata@redhat.com>
|
|
|
|
*
|
|
|
|
* Copyright (C) 2010 Red Hat
|
|
|
|
* see file 'COPYING' for use and warranty information
|
|
|
|
*
|
2010-12-09 06:59:11 -06:00
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
2010-09-24 18:50:29 -05:00
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
2010-12-09 06:59:11 -06:00
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
2010-09-24 18:50:29 -05:00
|
|
|
*/
|
|
|
|
|
2010-10-25 18:55:57 -05:00
|
|
|
module('ipa');
|
|
|
|
|
2010-09-24 18:50:29 -05:00
|
|
|
test("Testing ipa_init().", function() {
|
|
|
|
|
|
|
|
expect(1);
|
|
|
|
|
2010-10-27 22:32:30 -05:00
|
|
|
IPA.ajax_options.async = false;
|
2010-09-24 18:50:29 -05:00
|
|
|
|
2010-10-27 22:32:30 -05:00
|
|
|
IPA.init(
|
2010-09-24 18:50:29 -05:00
|
|
|
"data",
|
|
|
|
true,
|
2010-10-01 12:53:13 -05:00
|
|
|
function(data, text_status, xhr) {
|
2010-09-24 18:50:29 -05:00
|
|
|
ok(true, "ipa_init() succeeded.");
|
|
|
|
},
|
2010-10-01 12:53:13 -05:00
|
|
|
function(xhr, text_status, error_thrown) {
|
|
|
|
ok(false, "ipa_init() failed: "+error_thrown);
|
2010-09-24 18:50:29 -05:00
|
|
|
}
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
2011-01-12 18:51:22 -06:00
|
|
|
test("Testing IPA.get_param_info().", function() {
|
2010-09-24 18:50:29 -05:00
|
|
|
|
2011-02-16 12:46:59 -06:00
|
|
|
var param_info = IPA.get_entity_param("user", "uid");
|
2010-09-24 18:50:29 -05:00
|
|
|
ok(
|
|
|
|
param_info,
|
2011-01-12 18:51:22 -06:00
|
|
|
"IPA.get_param_info(\"user\", \"uid\") not null"
|
2010-09-24 18:50:29 -05:00
|
|
|
);
|
|
|
|
|
|
|
|
equals(
|
|
|
|
param_info["label"], "User login",
|
2011-01-12 18:51:22 -06:00
|
|
|
"IPA.get_param_info(\"user\", \"uid\")[\"label\"]"
|
2010-09-24 18:50:29 -05:00
|
|
|
);
|
|
|
|
|
|
|
|
equals(
|
2011-02-16 12:46:59 -06:00
|
|
|
IPA.get_entity_param("user", "wrong_attribute"), null,
|
2011-01-12 18:51:22 -06:00
|
|
|
"IPA.get_param_info(\"user\", \"wrong_attribute\")"
|
2010-09-24 18:50:29 -05:00
|
|
|
);
|
|
|
|
|
|
|
|
equals(
|
2011-02-16 12:46:59 -06:00
|
|
|
IPA.get_entity_param("user", null), null,
|
2011-01-12 18:51:22 -06:00
|
|
|
"IPA.get_param_info(\"user\", null)"
|
2010-09-24 18:50:29 -05:00
|
|
|
);
|
|
|
|
|
|
|
|
equals(
|
2011-02-16 12:46:59 -06:00
|
|
|
IPA.get_entity_param("wrong_entity", "uid"), null,
|
2011-01-12 18:51:22 -06:00
|
|
|
"IPA.get_param_info(\"wrong_entity\", \"uid\")"
|
2010-09-24 18:50:29 -05:00
|
|
|
);
|
|
|
|
|
|
|
|
equals(
|
2011-02-16 12:46:59 -06:00
|
|
|
IPA.get_entity_param(null, "uid"), null,
|
2011-01-12 18:51:22 -06:00
|
|
|
"IPA.get_param_info(null, \"uid\")"
|
2010-09-24 18:50:29 -05:00
|
|
|
);
|
|
|
|
});
|
|
|
|
|
2011-01-12 18:51:22 -06:00
|
|
|
test("Testing IPA.get_member_attribute().", function() {
|
2010-09-24 18:50:29 -05:00
|
|
|
|
|
|
|
equals(
|
2011-01-12 18:51:22 -06:00
|
|
|
IPA.get_member_attribute("user", "group"), "memberof",
|
|
|
|
"IPA.get_member_attribute(\"user\", \"group\")"
|
2010-09-24 18:50:29 -05:00
|
|
|
);
|
|
|
|
|
|
|
|
equals(
|
2011-01-12 18:51:22 -06:00
|
|
|
IPA.get_member_attribute("user", "host"), null,
|
|
|
|
"IPA.get_member_attribute(\"user\", \"host\")"
|
2010-09-24 18:50:29 -05:00
|
|
|
);
|
|
|
|
|
|
|
|
equals(
|
2011-01-12 18:51:22 -06:00
|
|
|
IPA.get_member_attribute("user", null), null,
|
|
|
|
"IPA.get_member_attribute(\"user\", null)"
|
2010-09-24 18:50:29 -05:00
|
|
|
);
|
|
|
|
|
|
|
|
equals(
|
2011-01-12 18:51:22 -06:00
|
|
|
IPA.get_member_attribute(null, "group"), null,
|
|
|
|
"IPA.get_member_attribute(null, \"group\")"
|
2010-09-24 18:50:29 -05:00
|
|
|
);
|
|
|
|
});
|
2010-09-29 00:52:56 -05:00
|
|
|
|
2011-04-12 02:13:30 -05:00
|
|
|
test("Testing successful IPA.command().", function() {
|
2010-09-29 00:52:56 -05:00
|
|
|
|
|
|
|
var method = 'method';
|
|
|
|
var args = ['arg1', 'arg2', 'arg3'];
|
|
|
|
var options = {
|
|
|
|
opt1: 'val1',
|
|
|
|
opt2: 'val2',
|
|
|
|
opt3: 'val3'
|
|
|
|
};
|
|
|
|
var object = 'object';
|
|
|
|
|
|
|
|
var success_handler_counter = 0;
|
|
|
|
var error_handler_counter = 0;
|
|
|
|
|
|
|
|
function success_handler(data, status, xhr) {
|
|
|
|
success_handler_counter++;
|
|
|
|
}
|
|
|
|
|
|
|
|
function error_handler(xhr, text_status, error_thrown) {
|
|
|
|
error_handler_counter++;
|
|
|
|
}
|
|
|
|
|
|
|
|
var orig = $.ajax;
|
|
|
|
|
|
|
|
var xhr = {};
|
|
|
|
var text_status = null;
|
|
|
|
var error_thrown = {name:'ERROR', message:'An error has occured'};
|
|
|
|
|
|
|
|
var ajax_counter = 0;
|
|
|
|
|
|
|
|
$.ajax = function(request) {
|
|
|
|
ajax_counter++;
|
|
|
|
|
|
|
|
equals(
|
|
|
|
request.url, "data/"+object+"_"+method+".json",
|
|
|
|
"Checking request.url"
|
|
|
|
);
|
|
|
|
|
|
|
|
var data = JSON.parse(request.data);
|
|
|
|
|
|
|
|
equals(
|
|
|
|
data.method, object+'_'+method,
|
|
|
|
"Checking method"
|
|
|
|
);
|
|
|
|
|
|
|
|
same(
|
|
|
|
data.params, [args, options],
|
|
|
|
"Checking parameters"
|
|
|
|
);
|
|
|
|
|
|
|
|
request.success(xhr, text_status, error_thrown);
|
|
|
|
};
|
|
|
|
|
2011-04-12 02:13:30 -05:00
|
|
|
IPA.command({
|
|
|
|
entity: object,
|
|
|
|
method: method,
|
|
|
|
args: args,
|
|
|
|
options: options,
|
|
|
|
on_success: success_handler,
|
|
|
|
on_error: error_handler
|
|
|
|
}).execute();
|
2010-09-29 00:52:56 -05:00
|
|
|
|
|
|
|
equals(
|
|
|
|
ajax_counter, 1,
|
|
|
|
"Checking ajax invocation counter"
|
|
|
|
);
|
|
|
|
|
|
|
|
ok(
|
2011-03-05 00:21:49 -06:00
|
|
|
!IPA.error_dialog,
|
2010-09-29 00:52:56 -05:00
|
|
|
"The dialog box is not created."
|
|
|
|
);
|
|
|
|
|
|
|
|
ok(
|
|
|
|
success_handler_counter == 1 && error_handler_counter == 0,
|
|
|
|
"Only the success handler is called."
|
|
|
|
);
|
|
|
|
|
|
|
|
$.ajax = orig;
|
|
|
|
});
|
|
|
|
|
2011-04-12 02:13:30 -05:00
|
|
|
test("Testing unsuccessful IPA.command().", function() {
|
2010-09-29 00:52:56 -05:00
|
|
|
|
|
|
|
var method = 'method';
|
|
|
|
var args = ['arg1', 'arg2', 'arg3'];
|
|
|
|
var options = {
|
|
|
|
opt1: 'val1',
|
|
|
|
opt2: 'val2',
|
|
|
|
opt3: 'val3'
|
|
|
|
};
|
|
|
|
var object = 'object';
|
|
|
|
|
|
|
|
var success_handler_counter = 0;
|
|
|
|
var error_handler_counter = 0;
|
|
|
|
|
|
|
|
function success_handler(data, status, xhr) {
|
|
|
|
success_handler_counter++;
|
|
|
|
}
|
|
|
|
|
|
|
|
function error_handler(xhr, text_status, error_thrown) {
|
|
|
|
error_handler_counter++;
|
|
|
|
}
|
|
|
|
|
|
|
|
var orig = $.ajax;
|
|
|
|
|
|
|
|
var xhr = {};
|
|
|
|
var text_status = null;
|
|
|
|
var error_thrown = {name:'ERROR', message:'An error has occured'};
|
|
|
|
|
|
|
|
var ajax_counter = 0;
|
|
|
|
|
|
|
|
$.ajax = function(request) {
|
|
|
|
ajax_counter++;
|
|
|
|
|
|
|
|
equals(
|
|
|
|
request.url, "data/"+object+"_"+method+".json",
|
|
|
|
"Checking request.url"
|
|
|
|
);
|
|
|
|
|
|
|
|
var data = JSON.parse(request.data);
|
|
|
|
|
|
|
|
equals(
|
|
|
|
data.method, object+'_'+method,
|
|
|
|
"Checking method"
|
|
|
|
);
|
|
|
|
|
|
|
|
same(
|
|
|
|
data.params, [args, options],
|
|
|
|
"Checking parameters"
|
|
|
|
);
|
|
|
|
|
|
|
|
request.error(xhr, text_status, error_thrown);
|
|
|
|
};
|
|
|
|
|
2011-04-12 02:13:30 -05:00
|
|
|
IPA.command({
|
|
|
|
entity: object,
|
|
|
|
method: method,
|
|
|
|
args: args,
|
|
|
|
options: options,
|
|
|
|
on_success: success_handler,
|
|
|
|
on_error: error_handler
|
|
|
|
}).execute();
|
2010-09-29 00:52:56 -05:00
|
|
|
|
2010-10-27 22:32:30 -05:00
|
|
|
var dialog = IPA.error_dialog.parent('.ui-dialog');
|
2010-09-29 00:52:56 -05:00
|
|
|
|
|
|
|
equals(
|
|
|
|
ajax_counter, 1,
|
|
|
|
"Checking ajax invocation counter"
|
|
|
|
);
|
|
|
|
|
|
|
|
ok(
|
2010-10-27 22:32:30 -05:00
|
|
|
dialog.length == 1 && IPA.error_dialog.dialog('isOpen'),
|
2010-09-29 00:52:56 -05:00
|
|
|
"The dialog box is created and open."
|
|
|
|
);
|
|
|
|
|
|
|
|
ok(
|
|
|
|
success_handler_counter == 0 && error_handler_counter == 0,
|
|
|
|
"Initially none of the handlers are called."
|
|
|
|
);
|
|
|
|
|
|
|
|
// search the retry button from the beginning
|
|
|
|
var retry = $('button', dialog).first();
|
|
|
|
retry.trigger('click');
|
|
|
|
|
|
|
|
equals(
|
|
|
|
ajax_counter, 2,
|
|
|
|
"Checking ajax invocation counter"
|
|
|
|
);
|
|
|
|
|
|
|
|
ok(
|
|
|
|
success_handler_counter == 0 && error_handler_counter == 0,
|
|
|
|
"After 1st retry, none of the handlers are called."
|
|
|
|
);
|
|
|
|
|
|
|
|
// search the retry button from the beginning again because the dialog
|
|
|
|
// has been recreated
|
2010-10-27 22:32:30 -05:00
|
|
|
dialog = IPA.error_dialog.parent('.ui-dialog');
|
2010-09-29 00:52:56 -05:00
|
|
|
retry = $('button', dialog).first();
|
|
|
|
retry.trigger('click');
|
|
|
|
|
|
|
|
equals(
|
|
|
|
ajax_counter, 3,
|
|
|
|
"Checking ajax invocation counter"
|
|
|
|
);
|
|
|
|
|
|
|
|
ok(
|
|
|
|
success_handler_counter == 0 && error_handler_counter == 0,
|
|
|
|
"After 2nd retry, none of the handlers are called."
|
|
|
|
);
|
|
|
|
|
|
|
|
// search the cancel button from the beginning because the dialog has
|
|
|
|
// been recreated
|
2010-10-27 22:32:30 -05:00
|
|
|
dialog = IPA.error_dialog.parent('.ui-dialog');
|
2010-09-29 00:52:56 -05:00
|
|
|
var cancel = $('button', dialog).first().next();
|
|
|
|
cancel.trigger('click');
|
|
|
|
|
|
|
|
equals(
|
|
|
|
ajax_counter, 3,
|
|
|
|
"Checking ajax invocation counter"
|
|
|
|
);
|
|
|
|
|
|
|
|
ok(
|
2011-03-05 00:21:49 -06:00
|
|
|
!IPA.error_dialog,
|
2010-09-29 00:52:56 -05:00
|
|
|
"After cancel, the dialog box is closed."
|
|
|
|
);
|
|
|
|
|
|
|
|
ok(
|
|
|
|
success_handler_counter == 0 && error_handler_counter == 1,
|
|
|
|
"Only the error handler is called."
|
|
|
|
);
|
|
|
|
|
|
|
|
$.ajax = orig;
|
|
|
|
});
|