From 4d71e53b8c0936fd1422048b6bc98b9cdd5254e2 Mon Sep 17 00:00:00 2001 From: Oliver Kurz Date: Tue, 2 Aug 2016 00:30:42 +0200 Subject: [PATCH] Add 'latest' query route Should always refer to most recent job for the specified scenario. * have the same link for test development, i.e. if one retriggers tests, the person has to always update the URL. If there would be a static URL even the browser can be instructed to reload the page automatically * for linking to the always current execution of the last job within one scenario, e.g. to respond faster to the standard question in bug reports "does this bug still happen?" --- lib/OpenQA/WebAPI.pm | 2 ++ lib/OpenQA/WebAPI/Controller/Test.pm | 14 ++++++++++++++ t/ui/18-tests-details.t | 10 ++++++++++ 3 files changed, 26 insertions(+) diff --git a/lib/OpenQA/WebAPI.pm b/lib/OpenQA/WebAPI.pm index aaedc6fead90..bd06d2569736 100644 --- a/lib/OpenQA/WebAPI.pm +++ b/lib/OpenQA/WebAPI.pm @@ -297,6 +297,8 @@ sub startup { $r->get('/tests')->name('tests')->to('test#list'); $r->get('/tests/overview')->name('tests_overview')->to('test#overview'); + $r->get('/tests/latest')->name('latest')->to('test#latest'); + $r->get('/tests/export')->name('tests_export')->to('test#export'); $r->post('/tests/list_ajax')->name('tests_ajax')->to('test#list_ajax'); my $test_r = $r->route('/tests/:testid', testid => qr/\d+/); diff --git a/lib/OpenQA/WebAPI/Controller/Test.pm b/lib/OpenQA/WebAPI/Controller/Test.pm index a335741c425c..5ec5cb59fe32 100644 --- a/lib/OpenQA/WebAPI/Controller/Test.pm +++ b/lib/OpenQA/WebAPI/Controller/Test.pm @@ -503,6 +503,20 @@ sub overview { ); } +sub latest { + my ($self) = @_; + my %search_args; + my @scenario_keys = qw/DISTRI VERSION FLAVOR ARCH TEST/; + for my $arg (@scenario_keys) { + my $key = lc $arg; + next unless defined $self->param($key); + $search_args{$key} = $self->param($key); + } + my $job = $self->db->resultset("Jobs")->complex_query(%search_args)->first; + return $self->render(text => 'No matching job found', status => 404) unless $job; + return $self->redirect_to('test', testid => $job->id); +} + sub add_comment { my ($self) = @_; diff --git a/t/ui/18-tests-details.t b/t/ui/18-tests-details.t index cdbcb66e57e8..90c380e52df4 100644 --- a/t/ui/18-tests-details.t +++ b/t/ui/18-tests-details.t @@ -80,6 +80,16 @@ is($num_active_tabs, 1, 'only one tab visible at the same time'); my $href_to_isosize = $t->tx->res->dom->at('.component a[href*=installer_timezone]')->{href}; $t->get_ok($baseurl . ($href_to_isosize =~ s@^/@@r))->status_is(200); +subtest 'route to latest' => sub { + $get = $t->get_ok($baseurl . 'tests/latest?distri=opensuse&version=13.1&flavor=DVD&arch=x86_64&test=kde&machine=64bit')->status_is(302); + is($t->tx->res->headers->location, '/tests/99963', 'latest link shows tests/99963'); + $get = $t->get_ok($baseurl . 'tests/latest?flavor=DVD&arch=x86_64&test=kde')->status_is(302); + is($t->tx->res->headers->location, '/tests/99963', '... as long as it is unique'); + $get = $t->get_ok($baseurl . 'tests/latest?version=13.1')->status_is(302); + is($t->tx->res->headers->location, '/tests/99981', 'returns highest job nr of ambiguous group'); + $get = $t->get_ok($baseurl . 'tests/latest?test=foobar')->status_is(404); +}; + #print $driver->get_page_source(); #t::ui::PhantomTest::make_screenshot('mojoResults.png');