Allow API to use ID or string in many fields.

Fixed issue in which creating a build is broken if milestone is not ---
Updated API docs
This commit is contained in:
ghendricks%novell.com 2008-03-10 23:13:33 +00:00
Родитель 0707eaca0f
Коммит 9b73cb7382
15 изменённых файлов: 303 добавлений и 109 удалений

Просмотреть файл

@ -63,7 +63,13 @@ sub _check_product {
ThrowUserError("testopia-create-denied", {'object' => 'build'}) unless Bugzilla->user->in_group('Testers');
my $product = Bugzilla::Testopia::Product->new($product_id);
my $product;
if (trim($product_id) !~ /^\d+$/ ){
$product = Bugzilla::Product::check_product($product_id);
}
else {
$product = Bugzilla::Testopia::Product->new($product_id);
}
if (ref $invocant){
$invocant->{'product'} = $product;

Просмотреть файл

@ -62,7 +62,14 @@ sub _check_product {
ThrowUserError("testopia-create-denied", {'object' => 'category'}) unless Bugzilla->user->in_group('Testers');
my $product = Bugzilla::Testopia::Product->new($product_id);
my $product;
if (trim($product_id) !~ /^\d+$/ ){
$product = Bugzilla::Product::check_product($product_id);
}
else {
$product = Bugzilla::Testopia::Product->new($product_id);
}
if (ref $invocant){
$invocant->{'product'} = $product;

Просмотреть файл

@ -96,8 +96,16 @@ sub _check_product {
$product_id = trim($product_id);
my $product = Bugzilla::Testopia::Product->new($product_id);
my $product;
if (trim($product_id) !~ /^\d+$/ ){
$product = Bugzilla::Product::check_product($product_id);
}
else {
$product = Bugzilla::Testopia::Product->new($product_id);
}
ThrowUserError("testopia-create-denied", {'object' => 'environment'}) unless $product->canedit;
if (ref $invocant){
$invocant->{'product'} = $product;
return $product->id;

Просмотреть файл

@ -116,7 +116,14 @@ sub _check_product {
}
$product_id = trim($product_id);
my $product = Bugzilla::Testopia::Product->new($product_id);
my $product;
if ($product_id !~ /^\d+$/ ){
$product = Bugzilla::Product::check_product($product_id);
}
else {
$product = Bugzilla::Testopia::Product->new($product_id);
}
ThrowUserError("invalid-test-id-non-existent", {'id' => $product_id, 'type' => 'product'}) unless $product;
ThrowUserError("testopia-create-denied", {'object' => 'plan'}) unless $product->canedit;
if (ref $invocant){

Просмотреть файл

@ -157,11 +157,12 @@ sub _check_manager {
}
}
#TODO: Check that version is in plan versions
sub _check_plan_text_version {
my ($invocant, $version) = @_;
trick_taint($version);
ThrowUserError('testopia-missing-required-field', {'field' => 'plan_version'}) unless $version;
return $version
return $version;
}
sub _check_notes {

Просмотреть файл

@ -75,7 +75,7 @@ sub create{
my $product = Bugzilla::Testopia::Product->new($new_values->{'product_id'});
ThrowUserError('testopia-read-only', {'object' => $product}) unless $product->canedit;
$new_values->{'milestone'} ||= '---';
$new_values->{'milestone'} ||= $product->default_milestone;
my $build = Bugzilla::Testopia::Build->create($new_values);
@ -186,14 +186,6 @@ Provides methods for automated scripts to manipulate Testopia Builds
=over
=item C<get($id)>
Description: Used to load an existing build from the database.
Params: $id - An integer representing the ID in the database
Returns: A blessed Bugzilla::Testopia::Build object hash
=item C<check_build($name, $product)>
Description: Looks up and returns a build by name.
@ -206,6 +198,36 @@ Provides methods for automated scripts to manipulate Testopia Builds
Returns: Hash: Matching Build object hash or error if not found.
=item C<create($values)>
Description: Creates a new build object and stores it in the database
Params: $values - Hash: A reference to a hash with keys and values
matching the fields of the build to be created.
+-------------+----------------+-----------+------------------------------------+
| Field | Type | Null | Description |
+-------------+----------------+-----------+------------------------------------+
| product_id | Integer/String | Required | ID or Name of product |
| name | String | Required | |
| milestone | String | Optional | Defaults to product's default MS |
| description | String | Optional | |
| isactive | Boolean | Optional | Defaults to True (1) |
+-------------+----------------+-----------+------------------------------------+
Returns: The newly created object hash.
=item C<get($id)>
Description: Used to load an existing build from the database.
Params: $id - An integer representing the ID in the database
Returns: A blessed Bugzilla::Testopia::Build object hash
=item C<lookup_id_by_name> B<DEPRICATED - CONSIDERED HARMFUL> Use Build::check_build instead
=item C<lookup_name_by_id> B<DEPRICATED> Use Build::get instead
=item C<update($ids, $values)>
Description: Updates the fields of the selected build or builds.
@ -218,26 +240,20 @@ Provides methods for automated scripts to manipulate Testopia Builds
$values - Hash of keys matching Build fields and the new values
to set each field to.
+-------------+----------------+
| Field | Type |
+-------------+----------------+
| name | String |
| milestone | String |
| description | String |
| isactive | Boolean |
+-------------+----------------+
Returns: Hash/Array: In the case of a single build it is returned. If a
list was passed, it returns an array of build hashes. If the
update on any particular build failed, the hash will contain a
FAILED key and the message as to why it failed.
=item C<create($values)>
Description: Creates a new build object and stores it in the database
Params: $values - Hash: A reference to a hash with keys and values
matching the fields of the build to be created.
See Bugzilla::Testopia::Build for a list of required fields.
Returns: The newly created object hash.
=item C<lookup_name_by_id> B<DEPRICATED> Use Build::get instead
=item C<lookup_id_by_name> B<DEPRICATED - CONSIDERED HARMFUL> Use Build::check_build instead
=back
=head1 SEE ALSO

Просмотреть файл

@ -168,6 +168,35 @@ Provides methods for automated scripts to manipulate Testopia Environments
=over
=item C<check_environment($name, $product)>
Description: Looks up and returns an environment by name.
Params: $name - String: name of the environment.
$product - Integer/String/Object
Integer: product_id of the product in the Database
String: Product name
Object: Blessed Bugzilla::Product object
Returns: Hash: Matching Environment object hash or error if not found.
=item C<create($values)>
Description: Creates a new environment object and stores it in the database
Params: $values - Hash: A reference to a hash with keys and values
matching the fields of the environment to be created.
+-------------+----------------+-----------+------------------------------------+
| Field | Type | Null | Description |
+-------------+----------------+-----------+------------------------------------+
| product_id | Integer/String | Required | ID or Name of product |
| name | String | Required | |
| isactive | Boolean | Optional | Defaults to True (1) |
+-------------+----------------+-----------+------------------------------------+
Returns: The newly created object hash.
=item C<get($id)>
Description: Used to load an existing Environment from the database.
@ -176,6 +205,22 @@ Provides methods for automated scripts to manipulate Testopia Environments
Returns: A blessed Bugzilla::Testopia::Environment object hash
=item C<get_caseruns($id)>
Description: Returns the list of case-runs that this Environment is used in.
Params: $id - Integer: Environment ID.
Returns: Array: List of case-run object hashes.
=item C<get_runs($id)>
Description: Returns the list of runs that this Environment is used in.
Params: $id - Integer: Environment ID.
Returns: Array: List of run object hashes.
=item C<list($query)>
Description: Performs a search and returns the resulting list of Environments
@ -203,47 +248,15 @@ Provides methods for automated scripts to manipulate Testopia Environments
$values - Hash of keys matching Environment fields and the new values
to set each field to.
+-------------+----------------+
| Field | Type |
+-------------+----------------+
| name | String |
| isactive | Boolean |
+-------------+----------------+
Returns: Hash: The updated environment object hash.
=item C<check_environment($name, $product)>
Description: Looks up and returns an environment by name.
Params: $name - String: name of the environment.
$product - Integer/String/Object
Integer: product_id of the product in the Database
String: Product name
Object: Blessed Bugzilla::Product object
Returns: Hash: Matching Environment object hash or error if not found.
=item C<create($values)>
Description: Creates a new environment object and stores it in the database
Params: $values - Hash: A reference to a hash with keys and values
matching the fields of the environment to be created.
See Bugzilla::Testopia::Environment for a list of required fields.
Returns: The newly created object hash.
=item C<get_runs($id)>
Description: Returns the list of runs that this Environment is used in.
Params: $id - Integer: Environment ID.
Returns: Array: List of run object hashes.
=item C<get_caseruns($id)>
Description: Returns the list of case-runs that this Environment is used in.
Params: $id - Integer: Environment ID.
Returns: Array: List of case-run object hashes.
=back
=head1 SEE ALSO
@ -251,7 +264,6 @@ Provides methods for automated scripts to manipulate Testopia Environments
=over
L<Bugzilla::Testopia::Environment>
L<Bugzilla::Webservice>
=back

Просмотреть файл

@ -166,10 +166,10 @@ sub get_versions {
}
sub lookup_name_by_id {
return {FAILED => 1, message=> 'This method id depricated. Use Product->get instead.'};
return {FAILED => 1, message=> 'This method id depricated. Use Product::get instead.'};
}
sub lookup_id_by_name {
return {FAILED => 1, message=> 'This method id depricated. Use check_product instead.'};
return {FAILED => 1, message=> 'This method id depricated. Use Product::check_product instead.'};
}
1;

Просмотреть файл

@ -106,11 +106,21 @@ sub create {
if (ref $new_values->{'bugs'} eq 'ARRAY'){
push @bug_ids, @{$new_values->{'bugs'}};
}
my @dependson;
if (ref $new_values->{'dependson'} eq 'ARRAY'){
push @dependson, @{$new_values->{'dependson'}};
}
my @blocks;
if (ref $new_values->{'blocks'} eq 'ARRAY'){
push @blocks, @{$new_values->{'blocks'}};
}
$new_values->{'plans'} = \@plans;
$new_values->{'author'} = Bugzilla->user->id;
$new_values->{'runs'} = join(',', @run_ids) if scalar @run_ids;
$new_values->{'bugs'} = join(',', @bug_ids) if scalar @bug_ids;
$new_values->{'dependson'} = join(',', @dependson) if scalar @dependson;
$new_values->{'blocks'} = join(',', @blocks) if scalar @blocks;
my $case = Bugzilla::Testopia::TestCase->create($new_values);
@ -124,6 +134,16 @@ sub update {
Bugzilla->login(LOGIN_REQUIRED);
my @ids = Bugzilla::Testopia::Util::process_list($ids);
my @dependson;
if (ref $new_values->{'dependson'} eq 'ARRAY'){
push @dependson, @{$new_values->{'dependson'}};
}
my @blocks;
if (ref $new_values->{'blocks'} eq 'ARRAY'){
push @blocks, @{$new_values->{'blocks'}};
}
$new_values->{'dependson'} = join(',', @dependson) if scalar @dependson;
$new_values->{'blocks'} = join(',', @blocks) if scalar @blocks;
my @cases;
foreach my $id (@ids){
@ -707,7 +727,32 @@ Provides methods for automated scripts to manipulate Testopia TestCases
Params: $values - Hash: A reference to a hash with keys and values
matching the fields of the test case to be created.
+-------------------+----------------+-----------+------------------------+
| Field | Type | Null | Description |
+-------------------+----------------+-----------+------------------------+
| case_status_id | Integer/String | Required | ID or Name of status |
| category_id | Integer/String | Required | ID or Name of Category |
| priority_id | Integer/String | Required | ID or Name of Priority |
| summary | String | Required | |
| default_tester_id | Integer/String | Optional | ID or Login of tester |
| estimated_time | String | Optional | HH:MM:SS Format |
| isautomated | Boolean | Optional | Defaults to False (0) |
| sortkey | Integer | Optional | |
| script | String | Optional | |
| arguments | String | Optional | |
| requirement | String | Optional | |
| alias | String | Optional | Must be unique |
| action | String | Optional | |
| effect | String | Optional | ExpectedResult |
| setup | String | Optional | |
| breakdown | String | Optional | |
| dependson | Array/String | Optional | String Comma separated |
| blocks | Array/String | Optional | String Comma separated |
| tags | Array/String | Optional | String Comma separated |
| bugs | Array/String | Optional | String Comma separated |
| plans | Array/String | Optional | String Comma separated |
| components | Array/String | Optional | String Comma separated |
+-------------------+----------------+-----------+------------------------+
Returns: The newly created object hash.
@ -990,7 +1035,25 @@ Provides methods for automated scripts to manipulate Testopia TestCases
list was passed, it returns an array of case hashes. If the
update on any particular case failed, the has will contain a
FAILED key and the message as to why it failed.
+-------------------+----------------+
| Field | Type |
+-------------------+----------------+
| case_status_id | Integer/String |
| category_id | Integer/String |
| priority_id | Integer/String |
| default_tester_id | Integer/String |
| estimated_time | String |
| isautomated | Boolean |
| sortkey | Integer |
| script | String |
| arguments | String |
| summary | String |
| requirement | String |
| alias | String |
| dependson | Array/String |
| blocks | Array/String |
+-------------------+----------------+
=back
=head1 SEE ALSO

Просмотреть файл

@ -77,6 +77,15 @@ sub create {
ThrowUserError('invalid-test-id-non-existent', {type => 'Test Run', id => $new_values->{'run_id'}}) unless $run;
ThrowUserError('testopia-read-only', {'object' => $run}) unless $run->canedit;
if (trim($new_values->{'build_id'}) !~ /^\d+$/ ){
my $build = Bugzilla::Testopia::Build::check_build($new_values->{'build_id'}, $run->plan->product);
$new_values->{'build_id'} = $build->id;
}
if (trim($new_values->{'environment_id'}) !~ /^\d+$/ ){
my $environment = Bugzilla::Testopia::Environment::check_environment($new_values->{'environment_id'}, $run->plan->product);
$new_values->{'environment_id'} = $environment->id;
}
if ($new_values->{'status'}){
$new_values->{'case_run_status_id'} = Bugzilla::Testopia::TestCaseRun::lookup_status_by_name($new_values->{'status'});
delete $new_values->{'status'};
@ -359,7 +368,21 @@ TestCaseRun->get($run_id, $case_id, $build_id, $environment_id)
Params: $values - Hash: A reference to a hash with keys and values
matching the fields of the test case to be created.
+--------------------+----------------+-----------+------------------------------------------------+
| Field | Type | Null | Description |
+--------------------+----------------+-----------+------------------------------------------------+
| run_id | Integer | Required | Test Run Number |
| case_id | Integer/String | Required | ID or alias of test case |
| build_id | Integer/String | Required | ID or name of a Build in plan's product |
| environment_id | Integer/String | Required | ID or name of an Environment in plan's product |
| assignee | Integer/String | Optional | Defaults to test case default tester |
| status | String | Optional | Defaults to "IDLE" |
| case_text_version | Integer | Optional | |
| notes | String | Optional | |
| sortkey | Integer | Optional | a.k.a. Index |
+--------------------+----------------+-----------+------------------------------------------------+
Valid statuses include: IDLE, PASSED, FAILED, RUNNING, PAUSED, BLOCKED
Returns: The newly created object hash.
=item C<detach_bug($caserun_id, $bug_id)>
@ -597,6 +620,17 @@ TestCaseRun->get($run_id, $case_id, $build_id, $environment_id)
$values - Hash of keys matching TestCaseRun fields and the new values
to set each field to.
+--------------------+----------------+
| Field | Type |
+--------------------+----------------+
| build_id | Integer/String |
| environment_id | Integer/String |
| assignee | Integer/String |
| status | String |
| notes | String |
| sortkey | Integer |
| update_bugs | Boolean | 1: Reopen bugs on FAILED 0: Don't change bug status
+--------------------+----------------+
Returns: Hash/Array: In the case of a single object, it is returned. If a
list was passed, it returns an array of object hashes. If the
@ -613,7 +647,7 @@ TestCaseRun->get($run_id, $case_id, $build_id, $environment_id)
$environment_id - Integer: An integer representing the ID of the environment in the database.
$values - Hash of keys matching TestCaseRun fields and the new values
to set each field to.
to set each field to. See above.
Returns: Hash/Array: In the case of a single object, it is returned. If a
list was passed, it returns an array of object hashes. If the

Просмотреть файл

@ -324,7 +324,15 @@ Provides methods for automated scripts to manipulate Testopia TestPlans
Params: $values - Hash: A reference to a hash with keys and values
matching the fields of the test plan to be created.
+-------------------------+----------------+-----------+------------------------------------+
| Field | Type | Null | Description |
+-------------------------+----------------+-----------+------------------------------------+
| product_id | Integer/String | Required | ID or Name of product |
| name | String | Required | |
| type_id | Integer/String | Required | ID or name of plan type |
| default_product_version | String | Required | |
| isactive | Boolean | Optional | 0: Archived 1: Active (Default 1) |
+-------------------------+----------------+-----------+------------------------------------+
Returns: The newly created object hash.
@ -498,6 +506,14 @@ Provides methods for automated scripts to manipulate Testopia TestPlans
$values - Hash of keys matching TestPlan fields and the new values
to set each field to.
+-------------------------+----------------+
| Field | Type |
+-------------------------+----------------+
| name | String |
| type_id | Integer/String |
| default_product_version | String |
| isactive | Boolean |
+-------------------------+----------------+
Returns: Hash: The updated test plan object.

Просмотреть файл

@ -76,8 +76,17 @@ sub create {
Bugzilla->login(LOGIN_REQUIRED);
my $product = Bugzilla::Testopia::Product->new($new_values->{'product_id'});
ThrowUserError('testopia-read-only', {'object' => $product}) unless $product->canedit;
my $plan = Bugzilla::Testopia::Plan->new($new_values->{'plan_id'});
ThrowUserError("testopia-create-denied", {'object' => 'Test Run', 'plan' => $plan}) unless ($plan->canedit);
if (trim($new_values->{'build_id'}) !~ /^\d+$/ ){
my $build = Bugzilla::Testopia::Build::check_build($new_values->{'build_id'}, $plan->product);
$new_values->{'build_id'} = $build->id;
}
if (trim($new_values->{'environment_id'}) !~ /^\d+$/ ){
my $environment = Bugzilla::Testopia::Environment::check_environment($new_values->{'environment_id'}, $plan->product);
$new_values->{'environment_id'} = $environment->id;
}
my $run = Bugzilla::Testopia::TestRun->create($new_values);
@ -94,6 +103,15 @@ sub update {
ThrowUserError('invalid-test-id-non-existent', {type => 'Test Run', id => $run_id}) unless $run;
ThrowUserError('testopia-read-only', {'object' => $run}) unless $run->canedit;
if (trim($new_values->{'build_id'}) !~ /^\d+$/ ){
my $build = Bugzilla::Testopia::Build::check_build($new_values->{'build_id'}, $plan->product);
$new_values->{'build_id'} = $build->id;
}
if (trim($new_values->{'environment_id'}) !~ /^\d+$/ ){
my $environment = Bugzilla::Testopia::Environment::check_environment($new_values->{'environment_id'}, $plan->product);
$new_values->{'environment_id'} = $environment->id;
}
my $timestamp;
$timestamp = $run->stop_date;
@ -101,12 +119,12 @@ sub update {
$timestamp = get_time_stamp() if $new_values->{'status'} == 0 && !$run->stop_date;
$run->set_summary(trim($new_values->{'summary'})) if exists $new_values->{'summary'};
$run->set_product_version($new_values->{'product_version')) if $new_values->{'product_version'};
$run->set_plan_text_version($new_values->{'plan_text_version')) if $new_values->{'plan_text_version'};
$run->set_build($new_values->{'build_id')) if $new_values->{'build_id'};
$run->set_environment($new_values->{'environment_id')) if $new_values->{'environment_id'};
$run->set_manager($new_values->{'manager_id')) if $new_values->{'manager_id'};
$run->set_notes($new_values->{'notes')} if exists $cgi->{'notes'};
$run->set_product_version($new_values->{'product_version'}) if $new_values->{'product_version'};
$run->set_plan_text_version($new_values->{'plan_text_version'}) if $new_values->{'plan_text_version'};
$run->set_build($new_values->{'build_id'}) if $new_values->{'build_id'};
$run->set_environment($new_values->{'environment_id'}) if $new_values->{'environment_id'};
$run->set_manager($new_values->{'manager_id'}) if $new_values->{'manager_id'};
$run->set_notes($new_values->{'notes'}} if exists $cgi->{'notes'};
$run->set_stop_date($timestamp) if $new_values->{'status'};
$run->update();
@ -184,7 +202,7 @@ sub lookup_environment_id_by_name {
}
sub lookup_environment_name_by_id {
return { FAILED => 1, message => 'This method is considered harmful and has been depricated. Please use Environment::get instead'};
return { FAILED => 1, message => 'This method has been depricated. Please use Environment::get instead'};
}
sub add_tag {
@ -287,8 +305,20 @@ Provides methods for automated scripts to manipulate Testopia TestRuns
Params: $values - Hash: A reference to a hash with keys and values
matching the fields of the test run to be created.
+-------------------+----------------+-----------+------------------------------------+
| Field | Type | Null | Description |
+-------------------+----------------+-----------+------------------------------------+
| plan_id | Integer | Required | ID of test plan |
| environment_id | Integer/String | Required | ID or Name of Environment |
| build_id | Integer/String | Required | ID or Name of Build |
| manager_id | Integer/String | Required | ID or Login of run manager |
| summary | String | Required | |
| product_version | String | Optional | Defaults to plan's version |
| plan_text_version | Integer | Optional | |
| notes | String | Optional | |
| status | Integer | Optional | 0:STOPPED 1: RUNNING (default 1) |
+-------------------+----------------+-----------+------------------------------------+
Returns: The newly created object hash.
=item C<get($run_id)>
@ -354,25 +384,6 @@ Provides methods for automated scripts to manipulate Testopia TestRuns
Params: $query - Hash: keys must match valid search fields.
build A fine Build indeed
ctype json
current_tab run
environment 1183153988 PerlUnit Test for Testopia API -- Environment.create -- PLEASE IGNORE
limit 25
manager
manager_type substring
milestone 3.0
notes
notes_type allwordssubstr
plan_id
product_id 2
run_id
run_status 0
summary
summary_type allwordssubstr
tags
tags_type anyexact
version 2.20
+--------------------------------------------------------+
| Run Search Parameters |
+--------------------------------------------------------+
@ -474,7 +485,20 @@ version 2.20
Params: $ids - Integer: A single TestRun ID.
$values - Hash of keys matching TestRun fields and the new values
to set each field to.
to set each field to. See L<create> for description
+-------------------+----------------+
| Field | Type |
+-------------------+----------------+
| plan_id | Integer |
| environment_id | Integer/String |
| build_id | Integer/String |
| manager_id | Integer/String |
| summary | String |
| product_version | String |
| plan_text_version | Integer |
| notes | String |
| status | Integer |
+-------------------+----------------+
Returns: Hash: The updated test run object.

Просмотреть файл

@ -107,7 +107,7 @@ Ext.extend(BuildGrid, Ext.grid.EditorGridPanel, {
]);
var b = new NewBuild({
name: '',
milestone: '---',
milestone: Ext.getCmp('products-pane').getSelectionModel().getSelectedNode().attributes.attributes.defaultmilestone,
description: '',
isactive: true
});

Просмотреть файл

@ -73,7 +73,7 @@ ThrowUserError("testopia-create-denied", {'object' => 'Test Run', 'plan' => $pla
if ($action eq 'add'){
Bugzilla->error_mode(ERROR_MODE_AJAX);
my $prod_version = $cgi->param('prod_version') ? $cgi->param('prod_version') : $plan->product_version();
my $build = trim($cgi->param('build'));
my $env = trim($cgi->param('environment'));
@ -101,7 +101,7 @@ if ($action eq 'add'){
'plan_id' => $plan->id,
'environment_id' => $env,
'build_id' => $build,
'product_version' => $cgi->param('prod_version'),
'product_version' => $prod_version,
'plan_text_version' => $plan->version,
'manager_id' => $cgi->param('manager'),
'summary' => $cgi->param('summary'),

Просмотреть файл

@ -387,7 +387,7 @@ else{
my @products;
my $classification = Bugzilla::Testopia::Classification->new($node);
foreach my $p (@{$classification->products}){
push @products, {id => $p->id, text => $p->name, leaf => 'true'};
push @products, {id => $p->id, text => $p->name, leaf => 'true', attributes =>{ defaultmilestone => $p->default_milestone}};
}
my $json = new JSON;
print $json->objToJson(\@products);