From d68366cfd41bd18f72c040cda9e4c9df31f96b64 Mon Sep 17 00:00:00 2001 From: "ghendricks%novell.com" Date: Thu, 3 Sep 2009 20:37:39 +0000 Subject: [PATCH] Allow test cases in runs to have their own priority. git-svn-id: svn://10.0.0.236/trunk@258318 18797224-902f-48f8-a5cc-f745e15eee43 --- .../code/db_schema-abstract_schema.pl | 10 ++++++ .../testopia/code/install-update_db.pl | 16 +++++++++ .../testopia/lib/Testopia/Search.pm | 35 +++++++++---------- .../testopia/lib/Testopia/TestCase.pm | 1 - .../testopia/lib/Testopia/TestCaseRun.pm | 28 ++++++++++++--- .../lib/Testopia/WebService/TestCaseRun.pm | 12 +++++++ mozilla/webtools/testopia/tr_caserun.cgi | 4 +-- 7 files changed, 80 insertions(+), 26 deletions(-) diff --git a/mozilla/webtools/testopia/extensions/testopia/code/db_schema-abstract_schema.pl b/mozilla/webtools/testopia/extensions/testopia/code/db_schema-abstract_schema.pl index b9c2ac1b5cc..e53696990ae 100644 --- a/mozilla/webtools/testopia/extensions/testopia/code/db_schema-abstract_schema.pl +++ b/mozilla/webtools/testopia/extensions/testopia/code/db_schema-abstract_schema.pl @@ -260,6 +260,15 @@ $schema->{test_attachments} = { DELETE => 'CASCADE' } }, + priority_id => { + TYPE => 'INT2', + REFERENCES => { + TABLE => 'priority', + COLUMN => 'id', + DELETE => 'RESTRICT' + } + }, + ], INDEXES => [ case_run_case_id_idx => ['case_id'], @@ -274,6 +283,7 @@ $schema->{test_attachments} = { case_run_text_ver_idx => ['case_text_version'], case_run_build_idx_v2 => ['build_id'], case_run_env_idx_v2 => ['environment_id'], + case_run_priority_idx => ['priority_id'], ], }, $schema->{test_case_texts} = { diff --git a/mozilla/webtools/testopia/extensions/testopia/code/install-update_db.pl b/mozilla/webtools/testopia/extensions/testopia/code/install-update_db.pl index 4bbb3e96730..d4e50301490 100644 --- a/mozilla/webtools/testopia/extensions/testopia/code/install-update_db.pl +++ b/mozilla/webtools/testopia/extensions/testopia/code/install-update_db.pl @@ -84,6 +84,7 @@ sub testopiaUpdateDB { $dbh->bz_add_column('test_case_status', 'description', {TYPE => 'MEDIUMTEXT'}, 0); $dbh->bz_add_column('test_case_run_status', 'description', {TYPE => 'MEDIUMTEXT'}, 0); $dbh->bz_add_column('test_case_runs', 'iscurrent', {TYPE => 'INT1', NOTNULL => 1, DEFAULT => 0}, 0); + $dbh->bz_add_column('test_case_runs', 'priority_id', {TYPE => 'INT2', NOTNULL => 1, DEFAULT => 0}, 0); $dbh->bz_add_column('test_named_queries', 'type', {TYPE => 'INT3', NOTNULL => 1, DEFAULT => 0}, 0); fixTables(); @@ -227,6 +228,7 @@ sub testopiaUpdateDB { $dbh->bz_add_index('test_case_runs', 'case_run_env_idx_v2', ['environment_id']); $dbh->bz_add_index('test_case_runs', 'case_run_status_idx', ['case_run_status_id']); $dbh->bz_add_index('test_case_runs', 'case_run_text_ver_idx', ['case_text_version']); + $dbh->bz_add_index('test_case_runs', 'case_run_priority_idx', ['priority_id']); $dbh->bz_add_index('test_cases', 'test_case_requirement_idx', ['requirement']); $dbh->bz_add_index('test_cases', 'test_case_status_idx', ['case_status_id']); $dbh->bz_add_index('test_cases', 'test_case_tester_idx', ['default_tester_id']); @@ -560,4 +562,18 @@ sub finalFixups { $dbh->do("INSERT INTO test_fielddefs (name, description, table_name) " . "VALUES ('estimated_time', 'Estimated Time', 'test_cases')"); } + if ($dbh->selectrow_array("SELECT COUNT(*) FROM test_case_runs WHERE priority_id = 0")){ + print "Updating case_run priorities...\n"; + my $cases = $dbh->selectall_arrayref("SELECT case_id, priority_id FROM test_cases",{'Slice'=>{}}); + my $sth = $dbh->prepare_cached("UPDATE test_case_runs SET priority_id = ? WHERE case_id = ?"); + foreach my $c (@$cases){ + $sth->execute($c->{priority_id},$c->{case_id}) + } + # Anything left over should get the default priority + $dbh->do("UPDATE test_case_runs + SET priority_id = (SELECT id + FROM priority + WHERE value = ?) + WHERE priority_id = 0", undef, Bugzilla->params->{defaultpriority}); + } } diff --git a/mozilla/webtools/testopia/extensions/testopia/lib/Testopia/Search.pm b/mozilla/webtools/testopia/extensions/testopia/lib/Testopia/Search.pm index 691213fd301..85b9542e18d 100644 --- a/mozilla/webtools/testopia/extensions/testopia/lib/Testopia/Search.pm +++ b/mozilla/webtools/testopia/extensions/testopia/lib/Testopia/Search.pm @@ -404,6 +404,16 @@ sub init { push @supptables, "INNER JOIN test_builds AS build ON build.build_id = test_". $obj ."s.build_id"; push @orderby, 'build.name'; } + elsif ($order eq 'priority') { + if ($obj eq 'case_run'){ + push @supptables, "INNER JOIN priority ON priority.id = test_case_runs.priority_id"; + push @orderby, 'priority.sortkey'; + } + else{ + push @supptables, "INNER JOIN priority ON priority.id = test_cases.priority_id"; + push @orderby, 'priority.sortkey'; + } + } elsif ($order eq 'environment') { push @supptables, "INNER JOIN test_environments AS env ON env.environment_id = test_". $obj ."s.environment_id"; push @orderby, 'env.name'; @@ -424,13 +434,6 @@ sub init { push @supptables, "INNER JOIN test_cases ON test_cases.case_id = test_case_runs.case_id"; push @orderby, 'test_cases.requirement'; } - elsif ($order eq 'priority') { - if ($obj eq 'case_run'){ - push @supptables, "INNER JOIN test_cases ON test_cases.case_id = test_case_runs.case_id"; - } - push @supptables, "INNER JOIN priority ON priority.id = test_cases.priority_id"; - push @orderby, 'test_cases.priority_id'; - } elsif ($order eq 'build') { push @supptables, "INNER JOIN test_builds ON test_builds.build_id = test_case_runs.build_id"; push @orderby, 'test_builds.name'; @@ -548,11 +551,13 @@ sub init { if ($obj eq 'case_run'){ push(@supptables, "INNER JOIN test_cases - ON test_cases.case_id = test_case_runs.case_id"); + ON test_case_runs.priority_id = priority.id"); } - push(@supptables, - "INNER JOIN priority ". - "ON test_cases.priority_id = priority.id"); + else{ + push(@supptables, + "INNER JOIN priority ". + "ON test_cases.priority_id = priority.id"); + } $f = 'priority.value'; }, "^environment," => sub { @@ -659,14 +664,6 @@ sub init { "ON components.id = tc_components.component_id"); $f = "components.name"; }, - "^priority_id," => sub { - if ($obj eq 'case_run'){ - push(@supptables, - "INNER JOIN test_cases - ON test_cases.case_id = test_case_runs.case_id"); - } - $f = "test_cases.priority_id"; - }, "^isautomated," => sub { if ($obj eq 'case_run'){ push(@supptables, diff --git a/mozilla/webtools/testopia/extensions/testopia/lib/Testopia/TestCase.pm b/mozilla/webtools/testopia/extensions/testopia/lib/Testopia/TestCase.pm index d20720af53e..313bd417757 100644 --- a/mozilla/webtools/testopia/extensions/testopia/lib/Testopia/TestCase.pm +++ b/mozilla/webtools/testopia/extensions/testopia/lib/Testopia/TestCase.pm @@ -202,7 +202,6 @@ sub _check_priority{ } ThrowCodeError('bad_arg', {argument => 'priority', function => 'set_priority'}) unless $priority_id; return $priority_id; - } sub _check_tester{ diff --git a/mozilla/webtools/testopia/extensions/testopia/lib/Testopia/TestCaseRun.pm b/mozilla/webtools/testopia/extensions/testopia/lib/Testopia/TestCaseRun.pm index 62bf177b238..1dfa2eac678 100644 --- a/mozilla/webtools/testopia/extensions/testopia/lib/Testopia/TestCaseRun.pm +++ b/mozilla/webtools/testopia/extensions/testopia/lib/Testopia/TestCaseRun.pm @@ -77,6 +77,7 @@ use constant DB_COLUMNS => qw( case_text_version build_id environment_id + priority_id notes running_date close_date @@ -85,7 +86,7 @@ use constant DB_COLUMNS => qw( ); use constant REQUIRED_CREATE_FIELDS => qw(case_id run_id build_id environment_id case_run_status_id); -use constant UPDATE_COLUMNS => qw(case_run_status_id case_text_version notes sortkey); +use constant UPDATE_COLUMNS => qw(case_run_status_id case_text_version notes sortkey priority_id); use constant VALIDATORS => { case_id => \&_check_case_id, @@ -94,6 +95,7 @@ use constant VALIDATORS => { environment_id => \&_check_env_id, case_text_version => \&_check_case_text_version, case_run_status_id => \&_check_case_run_status_id, + priority_id => \&Testopia::TestCase::_check_priority, }; sub report_columns { @@ -175,7 +177,6 @@ sub _check_assignee{ } } - ############################### #### Mutators #### ############################### @@ -218,10 +219,15 @@ sub new { sub create { my ($class, $params) = @_; - + $class->SUPER::check_required_create_fields($params); my $field_values = $class->run_create_validators($params); + unless ($field_values->{priority_id}){ + my $case = Testopia::TestCase->new($field_values->{case_id}); + $field_values->{priority_id} = $case->{priority_id}; + } + $field_values->{iscurrent} = 1; my $self = $class->SUPER::insert_create_data($field_values); @@ -327,7 +333,7 @@ sub TO_JSON { $obj->{'env_name'} = $self->environment->name if $self->environment; $obj->{'env_id'} = $self->environment->id if $self->environment; $obj->{'category'} = $self->case->category->name if $self->case && $self->case->category; - $obj->{'priority'} = $self->case->priority if $self->case; + $obj->{'priority'} = $self->priority if $self->case; $obj->{'bug_count'} = $self->bug_count; $obj->{'case_summary'} = $self->case->summary if $self->case; $obj->{'component'} = @{$self->case->components}[0]->name if ($self->case && scalar @{$self->case->components}); @@ -455,6 +461,8 @@ sub set_sortkey { $self->{'sortkey'} = $sortkey; } +sub set_priority { $_[0]->set('priority_id', $_[1]); } + =head2 set_assignee Sets the assigned tester for the case-run @@ -814,6 +822,18 @@ sub sortkey { return $_[0]->{'sortkey'}; } sub isprivate { return $_[0]->{'isprivate'}; } sub updated_deps { return $_[0]->{'updated_deps'}; } +sub priority { + my $self = shift; + my $dbh = Bugzilla->dbh; + return $self->{'priority'} if exists $self->{'priority'}; + my ($res) = $dbh->selectrow_array("SELECT value + FROM priority + WHERE id = ?", + undef, $self->{'priority_id'}); + $self->{'priority'} = $res; + return $self->{'priority'}; +} + =head2 type Returns 'case' diff --git a/mozilla/webtools/testopia/extensions/testopia/lib/Testopia/WebService/TestCaseRun.pm b/mozilla/webtools/testopia/extensions/testopia/lib/Testopia/WebService/TestCaseRun.pm index 5a476523ce0..dd29bd3a896 100644 --- a/mozilla/webtools/testopia/extensions/testopia/lib/Testopia/WebService/TestCaseRun.pm +++ b/mozilla/webtools/testopia/extensions/testopia/lib/Testopia/WebService/TestCaseRun.pm @@ -113,9 +113,11 @@ sub create { $new_values->{'build_id'} ||= $new_values->{'build'}; $new_values->{'environment_id'} ||= $new_values->{'environment'}; + $new_values->{'priority_id'} ||= $new_values->{'priority'}; delete $new_values->{'build'}; delete $new_values->{'environment'}; + delete $new_values->{'priority'}; if (trim($new_values->{'build_id'}) !~ /^\d+$/ ){ my $build = extensions::testopia::lib::Testopia::Build::check_build($new_values->{'build_id'}, $run->plan->product, "THROWERROR"); @@ -172,6 +174,7 @@ sub update { $new_values->{'case_run_status_id'} ||= $new_values->{'status'}; $new_values->{'build_id'} ||= $new_values->{'build'}; $new_values->{'environment_id'} ||= $new_values->{'environment'}; + $new_values->{'priority_id'} ||= $new_values->{'priority'}; my @results; @@ -220,6 +223,13 @@ sub update { $caserun->append_note($new_values->{'notes'}); } + if ($new_values->{'priority'}){ + delete $new_values->{'priority_id'}; + $caserun->set_priority($new_values->{'notes'}); + $caserun->update(); + } + + # Remove assignee user object and replace with just assignee id if (ref $caserun->{'assignee'} eq 'Bugzilla::User'){ $caserun->{assignee} = $caserun->{assignee}->id(); @@ -414,6 +424,7 @@ TestCaseRun->get($run_id, $case_id, $build_id, $environment_id) | case_id | Integer/String | Required | ID or alias of test case | | build | Integer/String | Required | ID or name of a Build in plan's product | | environment | Integer/String | Required | ID or name of an Environment in plan's product | + | priority | Integer/String | Optional | ID or name of priority. Default same as case | | assignee | Integer/String | Optional | Defaults to test case default tester | | status | String | Optional | Defaults to "IDLE" | | case_text_version | Integer | Optional | | @@ -674,6 +685,7 @@ TestCaseRun->get($run_id, $case_id, $build_id, $environment_id) | build | Integer/String | | environment | Integer/String | | assignee | Integer/String | + | priority | Integer/String | | status | String | | notes | String | | sortkey | Integer | diff --git a/mozilla/webtools/testopia/tr_caserun.cgi b/mozilla/webtools/testopia/tr_caserun.cgi index 04a0671743a..6ab8493fa49 100755 --- a/mozilla/webtools/testopia/tr_caserun.cgi +++ b/mozilla/webtools/testopia/tr_caserun.cgi @@ -137,8 +137,8 @@ elsif ($action eq 'update_priority'){ print $cgi->header; ThrowUserError("testopia-read-only", {'object' => $caserun}) unless $caserun->canedit; - $caserun->case->set_priority($cgi->param('priority')); - $caserun->case->update(); + $caserun->set_priority($cgi->param('priority')); + $caserun->update(); print "{'success': true, caserun:" . $caserun->TO_JSON ."}";