You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@trafficcontrol.apache.org by de...@apache.org on 2017/04/19 14:00:43 UTC

[2/2] incubator-trafficcontrol git commit: adds limit query param to GET api/../logs

adds limit query param to GET api/../logs


Project: http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/commit/cfbd0b98
Tree: http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/tree/cfbd0b98
Diff: http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/diff/cfbd0b98

Branch: refs/heads/master
Commit: cfbd0b98616ed49b1e87c4443f1f06e752c78258
Parents: 76970c3
Author: Jeremy Mitchell <mi...@gmail.com>
Authored: Tue Apr 18 16:01:30 2017 -0600
Committer: Dewayne Richardson <de...@apache.org>
Committed: Wed Apr 19 08:00:38 2017 -0600

----------------------------------------------------------------------
 .../traffic_ops_api/v12/changelog.rst           | 16 ++++--
 traffic_ops/app/lib/API/ChangeLog.pm            |  2 +-
 traffic_ops/app/lib/Test/TestHelper.pm          |  3 ++
 traffic_ops/app/t/api/1.2/log.t                 | 54 ++++++++++++++++++++
 4 files changed, 71 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/blob/cfbd0b98/docs/source/development/traffic_ops_api/v12/changelog.rst
----------------------------------------------------------------------
diff --git a/docs/source/development/traffic_ops_api/v12/changelog.rst b/docs/source/development/traffic_ops_api/v12/changelog.rst
index 5cedbe0..ff0d72d 100644
--- a/docs/source/development/traffic_ops_api/v12/changelog.rst
+++ b/docs/source/development/traffic_ops_api/v12/changelog.rst
@@ -24,12 +24,22 @@ Change Logs
 /api/1.2/logs
 +++++++++++++
 
-**GET /api/1.2/logs.json**
+**GET /api/1.2/logs**
 
   Authentication Required: Yes
 
   Role(s) Required: None
 
+  **Request Query Parameters**
+
+  +-----------------+----------+---------------------------------------------------+
+  | Name            | Required | Description                                       |
+  +=================+==========+===================================================+
+  | ``days``        | no       | The number of days of change logs to return.      |
+  +-----------------+----------+---------------------------------------------------+
+  | ``limit``       | no       | The number of rows to limit the response to.      |
+  +-----------------+----------+---------------------------------------------------+
+
   **Response Properties**
 
   +-----------------+--------+--------------------------------------------------------------------------+
@@ -73,7 +83,7 @@ Change Logs
 
 |
 
-**GET /api/1.2/logs/:days/days.json**
+**GET /api/1.2/logs/:days/days**
 
   Authentication Required: Yes
 
@@ -130,7 +140,7 @@ Change Logs
 
 |
 
-**GET /api/1.2/logs/newcount.json**
+**GET /api/1.2/logs/newcount**
 
   Authentication Required: Yes
 

http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/blob/cfbd0b98/traffic_ops/app/lib/API/ChangeLog.pm
----------------------------------------------------------------------
diff --git a/traffic_ops/app/lib/API/ChangeLog.pm b/traffic_ops/app/lib/API/ChangeLog.pm
index cf54256..f4c3f8e 100644
--- a/traffic_ops/app/lib/API/ChangeLog.pm
+++ b/traffic_ops/app/lib/API/ChangeLog.pm
@@ -22,7 +22,7 @@ use Mojo::Base 'Mojolicious::Controller';
 sub index {
 	my $self    = shift;
 	my $numdays = defined( $self->param('days') ) ? $self->param('days') : 30;
-	my $rows    = defined( $self->param('days') ) ? 1000000 : 1000;              # all of them gets to be too much
+	my $rows    = defined( $self->param('limit') ) ? $self->param('limit') : defined( $self->param('days') ) ? 1000000 : 1000;
 
 	my $date_string = `date "+%Y-%m-%d% %H:%M:%S"`;
 	chomp($date_string);

http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/blob/cfbd0b98/traffic_ops/app/lib/Test/TestHelper.pm
----------------------------------------------------------------------
diff --git a/traffic_ops/app/lib/Test/TestHelper.pm b/traffic_ops/app/lib/Test/TestHelper.pm
index 90570c6..c18c301 100644
--- a/traffic_ops/app/lib/Test/TestHelper.pm
+++ b/traffic_ops/app/lib/Test/TestHelper.pm
@@ -31,6 +31,7 @@ use Fixtures::DeliveryserviceTmuser;
 use Fixtures::Asn;
 use Fixtures::Cachegroup;
 use Fixtures::EdgeCachegroup;
+use Fixtures::Log;
 use Fixtures::Job;
 use Fixtures::JobAgent;
 use Fixtures::JobStatus;
@@ -137,6 +138,7 @@ sub load_core_data {
 	$self->load_all_fixtures( Fixtures::JobStatus->new($schema_values) );
 	$self->load_all_fixtures( Fixtures::JobAgent->new($schema_values) );
 	$self->load_all_fixtures( Fixtures::Job->new($schema_values) );
+	$self->load_all_fixtures( Fixtures::Log->new($schema_values) );
 }
 
 sub unload_core_data {
@@ -145,6 +147,7 @@ sub unload_core_data {
 
 	$self->teardown($schema, 'ToExtension');
 	$self->teardown($schema, 'Staticdnsentry');
+	$self->teardown($schema, 'Log');
 	$self->teardown($schema, 'Job');
 	$self->teardown($schema, 'JobAgent');
 	$self->teardown($schema, 'JobStatus');

http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/blob/cfbd0b98/traffic_ops/app/t/api/1.2/log.t
----------------------------------------------------------------------
diff --git a/traffic_ops/app/t/api/1.2/log.t b/traffic_ops/app/t/api/1.2/log.t
new file mode 100644
index 0000000..d62ddb8
--- /dev/null
+++ b/traffic_ops/app/t/api/1.2/log.t
@@ -0,0 +1,54 @@
+package main;
+#
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+use Mojo::Base -strict;
+use Test::More;
+use Test::Mojo;
+use DBI;
+use JSON;
+use strict;
+use warnings;
+no warnings 'once';
+use warnings 'all';
+use Test::TestHelper;
+
+#no_transactions=>1 ==> keep fixtures after every execution, beware of duplicate data!
+#no_transactions=>0 ==> delete fixtures after every execution
+
+BEGIN { $ENV{MOJO_MODE} = "test" }
+
+my $schema = Schema->connect_to_database;
+my $t      = Test::Mojo->new('TrafficOps');
+
+# Count the 'response number'
+my $count_response = sub {
+    my ( $t, $count ) = @_;
+    my $json = decode_json( $t->tx->res->content->asset->slurp );
+    my $r    = $json->{response};
+    return $t->success( is( scalar(@$r), $count ) );
+};
+
+Test::TestHelper->unload_core_data($schema);
+Test::TestHelper->load_core_data($schema);
+
+ok $t->post_ok( '/login', => form => { u => Test::TestHelper::ADMIN_USER, p => Test::TestHelper::ADMIN_USER_PASSWORD } )->status_is(302)
+        ->or( sub { diag $t->tx->res->content->asset->{content}; } ), 'Should login?';
+
+ok $t->get_ok('/api/1.2/logs?limit=1')->status_is(200)->$count_response(1);
+
+ok $t->get_ok('/logout')->status_is(302)->or( sub { diag $t->tx->res->content->asset->{content}; } );
+done_testing();
+
+