You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@trafficcontrol.apache.org by da...@apache.org on 2017/01/05 18:44:44 UTC
[3/3] incubator-trafficcontrol git commit: adds crud tests for asn api
adds crud tests for asn api
Project: http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/commit/da27b27c
Tree: http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/tree/da27b27c
Diff: http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/diff/da27b27c
Branch: refs/heads/master
Commit: da27b27c2f4989e1e2ff20dc538f52020b73866e
Parents: 4c95bee
Author: Jeremy Mitchell <mi...@gmail.com>
Authored: Wed Jan 4 14:34:59 2017 -0700
Committer: Dan Kirkwood <da...@gmail.com>
Committed: Thu Jan 5 11:13:10 2017 -0700
----------------------------------------------------------------------
traffic_ops/app/lib/Fixtures/Asn.pm | 8 +++++
traffic_ops/app/t/api/1.2/asn.t | 51 ++++++++++++++++++++++++++++----
2 files changed, 54 insertions(+), 5 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/blob/da27b27c/traffic_ops/app/lib/Fixtures/Asn.pm
----------------------------------------------------------------------
diff --git a/traffic_ops/app/lib/Fixtures/Asn.pm b/traffic_ops/app/lib/Fixtures/Asn.pm
index d0d05f3..e896bcf 100644
--- a/traffic_ops/app/lib/Fixtures/Asn.pm
+++ b/traffic_ops/app/lib/Fixtures/Asn.pm
@@ -23,6 +23,14 @@ my %definition_for = (
using => {
id => 1,
asn => 9939,
+ cachegroup => 2,
+ },
+ },
+ test_cran_2 => {
+ new => 'Asn',
+ using => {
+ id => 2,
+ asn => 9940,
cachegroup => 1,
},
},
http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/blob/da27b27c/traffic_ops/app/t/api/1.2/asn.t
----------------------------------------------------------------------
diff --git a/traffic_ops/app/t/api/1.2/asn.t b/traffic_ops/app/t/api/1.2/asn.t
index 2232a3a..f9508e1 100644
--- a/traffic_ops/app/t/api/1.2/asn.t
+++ b/traffic_ops/app/t/api/1.2/asn.t
@@ -40,18 +40,59 @@ 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}; } );
-$t->get_ok("/api/1.2/asns.json")->status_is(200)->json_is( "/response/0/id", "1" )->json_is( "/response/0/cachegroup", "mid-northeast-group" )
+$t->get_ok("/api/1.2/asns")->status_is(200)->json_is( "/response/0/id", "1" )->json_is( "/response/0/cachegroup", "mid-northwest-group" )
->json_is( "/response/0/asn", "9939" )->or( sub { diag $t->tx->res->content->asset->{content}; } );
-$t->get_ok("/api/1.2/asns.json?orderby=id")->status_is(200)->json_is( "/response/0/id", "1" )
- ->json_is( "/response/0/cachegroup", "mid-northeast-group" )->json_is( "/response/0/asn", "9939" )
+$t->get_ok("/api/1.2/asns?orderby=id")->status_is(200)->json_is( "/response/0/id", "1" )
+ ->json_is( "/response/0/cachegroup", "mid-northwest-group" )->json_is( "/response/0/asn", "9939" )
->or( sub { diag $t->tx->res->content->asset->{content}; } );
-$t->get_ok("/api/1.2/asns.json?orderby=cachegroup")->status_is(200)->json_is( "/response/0/id", "1" )
- ->json_is( "/response/0/cachegroup", "mid-northeast-group" )->json_is( "/response/0/asn", "9939" )
+$t->get_ok("/api/1.2/asns?orderby=cachegroup")->status_is(200)->json_is( "/response/0/id", "2" )
+ ->json_is( "/response/0/cachegroup", "mid-northeast-group" )->json_is( "/response/0/asn", "9940" )
->or( sub { diag $t->tx->res->content->asset->{content}; } );
+$t->get_ok("/api/1.2/asns/2")->status_is(200)->json_is( "/response/0/id", "2" )
+ ->json_is( "/response/0/cachegroup", "mid-northeast-group" )->json_is( "/response/0/asn", "9940" )
+ ->or( sub { diag $t->tx->res->content->asset->{content}; } );
+
+ok $t->post_ok('/api/1.2/asns' => {Accept => 'application/json'} => json => {
+ "asn" => 852,
+ "cachegroupId" => 1
+ })
+ ->status_is(200)->or( sub { diag $t->tx->res->content->asset->{content}; } )
+ ->json_is( "/response/asn" => 852 )
+ ->json_is( "/response/cachegroupId" => 1 )
+ ->json_is( "/response/cachegroup" => "mid-northeast-group" )
+ ->json_is( "/alerts/0/level" => "success" )
+ ->json_is( "/alerts/0/text" => "ASN create was successful." )
+ , 'Does the asn details return?';
+
+my $asn_id = &get_asn_id(852);
+
+ok $t->put_ok('/api/1.2/asns/' . $asn_id => {Accept => 'application/json'} => json => {
+ "asn" => 853,
+ "cachegroupId" => 1
+ })
+ ->status_is(200)->or( sub { diag $t->tx->res->content->asset->{content}; } )
+ ->json_is( "/response/asn" => 853 )
+ ->json_is( "/alerts/0/level" => "success" )
+ , 'Does the asn details return?';
+
+ok $t->delete_ok('/api/1.2/asns/' . $asn_id)->status_is(200)->or( sub { diag $t->tx->res->content->asset->{content}; } );
+
ok $t->get_ok('/logout')->status_is(302)->or( sub { diag $t->tx->res->content->asset->{content}; } );
$dbh->disconnect();
done_testing();
+
+sub get_asn_id {
+ my $asn = shift;
+ my $q = "select id from asn where asn = \'$asn\'";
+ my $get_svr = $dbh->prepare($q);
+ $get_svr->execute();
+ my $p = $get_svr->fetchall_arrayref( {} );
+ $get_svr->finish();
+ my $id = $p->[0]->{id};
+ return $id;
+}
+