Skip to content
This repository was archived by the owner on Jan 15, 2025. It is now read-only.

Commit 3c023c9

Browse files
updated automated tests
1 parent 8b283a5 commit 3c023c9

File tree

5 files changed

+225
-15
lines changed

5 files changed

+225
-15
lines changed

docs/apiconnector.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<!--
66
generated by Pod::Simple::HTML v3.35,
77
using Pod::Simple::PullParser v3.35,
8-
under Perl v5.026000 at Fri Jul 20 12:34:05 2018 GMT.
8+
under Perl v5.026000 at Fri Jul 20 16:04:32 2018 GMT.
99
1010
If you want to change this HTML document, you probably shouldn't do that
1111
by changing it directly. Instead, see about changing the calling options

lib/HEXONET/Apiconnector/Connection.pm

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,9 @@ sub call_raw {
3636
$config = {} if !defined $config;
3737
$config = { User => $config } if ( defined $config ) && ( !ref $config );
3838

39+
#TODO check above line if we still need it; $config should always be defined
40+
#because of the line before, so that at least the if branch can be reviewed
41+
3942
return $self->call_raw_http( $command, $config );
4043
}
4144

@@ -55,7 +58,7 @@ sub call_raw_http {
5558
$post->{s_pw} = $self->{password} if exists $self->{password};
5659
$post->{s_user} = $self->{user} if exists $self->{user};
5760
$post->{s_login} = $self->{login} . "!" . $self->{role}
58-
if exists $self->{role};
61+
if ( exists $self->{login} ) && ( exists $self->{role} );
5962

6063
if ( exists $config->{user} ) {
6164
if ( exists $post->{s_user} ) {

lib/HEXONET/Apiconnector/Response.pm

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,15 +104,17 @@ sub property {
104104
my $index = shift;
105105
my $p = $self->as_hash()->{PROPERTY};
106106
if ( defined $index ) {
107-
return ( LIST { undef } SCALAR { undef } )
107+
return undef
108108
unless exists $p->{$property};
109109
return $p->{$property}[$index];
110110
}
111111
if (wantarray) {
112112
return () unless exists $p->{$property};
113113
return @{ $p->{$property} };
114114
}
115-
return ( LIST { undef } SCALAR { undef } ) unless exists $p->{$property};
115+
return undef unless exists $p->{$property};
116+
117+
#TODO: we mixup here wantarray and LIST/SCALAR which does basically the same
116118
return $p->{$property};
117119
}
118120

lib/HEXONET/Apiconnector/Util.pm

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ our @EXPORT_OK = qw(sqltime timesql);
1414

1515
sub timesql {
1616
my $sqltime = shift;
17-
return ( LIST { undef } SCALAR { undef } )
17+
return undef
1818
if !defined $sqltime || $sqltime !~ /(\d\d+)-(\d+)-(\d+)/;
1919
my $year = $1;
2020
my $mon = $2;
@@ -67,7 +67,7 @@ sub sqltime {
6767

6868
sub url_encode {
6969
my $s = shift;
70-
return ( LIST { undef } SCALAR { undef } )
70+
return undef
7171
unless defined $s;
7272
utf8::encode($s) if utf8::is_utf8($s);
7373
$s =~ s/([^A-Za-z0-9\-\._~])/sprintf("%%%02X", ord($1))/seg;

t/HEXONET-apiconnector.t

Lines changed: 214 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,23 @@
11
use strict;
22
use warnings;
33

4-
use Test::More tests => 5;
4+
use Test::More tests => 50;
5+
use Test::Exception;
56

67
our $VERSION = '1.00';
78

8-
# T1-3: test import modules
9-
use_ok( "lib", qw(./lib) );
10-
use_ok( "Scalar::Util", qw(blessed) );
11-
use_ok( "HEXONET::Apiconnector", $VERSION );
9+
#######################################
10+
# TESTS for Connection.pm
11+
#######################################
1212

13-
# T4: instantiate API Client
13+
# T1-5: test import modules
14+
use_ok( "lib", qw(./lib) );
15+
use_ok( "Scalar::Util", qw(blessed) );
16+
use_ok( "HEXONET::Apiconnector", $VERSION );
17+
use_ok( "HEXONET::Apiconnector::Response", $VERSION );
18+
use_ok( "HEXONET::Apiconnector::Util", $VERSION );
19+
20+
# T6: instantiate API Client
1421
our $api = HEXONET::Apiconnector::connect(
1522
url => 'https://coreapi.1api.net/api/call.cgi',
1623
entity => '1234',
@@ -21,15 +28,213 @@ our $cl = blessed($api);
2128
is( $cl, "HEXONET::Apiconnector::Connection",
2229
"API Client Instance type check" );
2330

24-
# T5: make API call and test Response instance
31+
# T7: make API call and test Response instance
2532
our $r = $api->call(
33+
{
34+
COMMAND => "GetUserIndex"
35+
}
36+
);
37+
38+
$cl = blessed($r);
39+
is( $cl, "HEXONET::Apiconnector::Response",
40+
"API Response Instance type check" );
41+
42+
# T8: add subuser and role - just to increase coverage, no special checks necessary
43+
$api = HEXONET::Apiconnector::connect(
44+
url => 'https://coreapi.1api.net/api/call.cgi',
45+
entity => '1234',
46+
login => 'test.user',
47+
password => 'test.passw0rd',
48+
user => 'hexotestman.com',
49+
role => 'testrole'
50+
);
51+
$cl = blessed($api);
52+
is( $cl, "HEXONET::Apiconnector::Connection",
53+
"API Client Instance type check" );
54+
55+
# T9: make API call and test Response instance - just to increase coverage, no special checks necessary
56+
$r = $api->call(
57+
{
58+
COMMAND => "GetUserIndex"
59+
}
60+
);
61+
$cl = blessed($r);
62+
is( $cl, "HEXONET::Apiconnector::Response",
63+
"API Response Instance type check" );
64+
$r = $api->call_raw(
65+
{
66+
COMMAND => "GetUserIndex"
67+
},
68+
{
69+
user => "accesscontroltest",
70+
role => ""
71+
}
72+
);
73+
74+
# T10: add subuser and role - just to increase coverage, no special checks necessary
75+
$api = HEXONET::Apiconnector::connect(
76+
url => 'https://coreapi.1api.net/api/call.cgi',
77+
role => 'testrole'
78+
);
79+
$cl = blessed($api);
80+
is( $cl, "HEXONET::Apiconnector::Connection",
81+
"API Client Instance type check" );
82+
$r = $api->call_raw(
83+
{
84+
COMMAND => "GetUserIndex"
85+
},
86+
{
87+
user => 'somesubsubuser'
88+
}
89+
);
90+
91+
#######################################
92+
# TESTS for Response.pm
93+
#######################################
94+
# T11 - T18: initial response class coverage test
95+
$api = HEXONET::Apiconnector::connect(
96+
login => 'test.user',
97+
password => 'test.password',
98+
entity => '1234',
99+
url => 'https://coreapi.1api.net/api/call.cgi'
100+
);
101+
$cl = blessed($api);
102+
103+
#T11
104+
is( $cl, "HEXONET::Apiconnector::Connection",
105+
"API Client Instance type check" );
106+
107+
#T12
108+
$r = $api->call(
109+
{
110+
COMMAND => "GetUserIndex"
111+
}
112+
);
113+
$cl = blessed($r);
114+
is( $cl, "HEXONET::Apiconnector::Response",
115+
"API Response Instance type check" );
116+
117+
#T13
118+
ok( $r->description() eq "Authentication failed",
119+
"Check response description" );
120+
121+
#T14
122+
ok( $r->code() eq 530, "Check response code" );
123+
124+
#T15
125+
isa_ok( $r->as_list(), 'ARRAY' );
126+
127+
#T16
128+
ok( ref( $r->as_list_hash() ) );
129+
130+
#T17
131+
our $tmp = $r->as_string();
132+
our $regex = qr/code=.+description=.+/;
133+
$tmp =~ /$regex/;
134+
ok($tmp);
135+
136+
#T18
137+
ok( !$r->is_success() );
138+
139+
# T19 - T20 constructor branch tests
140+
#T19
141+
dies_ok {
142+
HEXONET::Apiconnector::Response->new($api);
143+
}
144+
'Unsupported Class';
145+
146+
#T20
147+
$r = HEXONET::Apiconnector::Response->new( $r->as_list_hash() );
148+
$cl = blessed($r);
149+
is( $cl, "HEXONET::Apiconnector::Response",
150+
"API Response Instance type check" );
151+
152+
#T21 - T43 check list response
153+
$api = HEXONET::Apiconnector::connect(
154+
login => "test.user",
155+
password => "test.passw0rd",
156+
url => "https://coreapi.1api.net/api/call.cgi",
157+
entity => "1234"
158+
);
159+
$r = $api->call(
26160
{
27161
COMMAND => "QueryDomainList",
28-
LIMIT => 5,
162+
VERSION => 2,
163+
NOTOTAL => 1, # TOTAL to have value from total to equal to count
164+
LIMIT => 10,
29165
FIRST => 0
30166
}
31167
);
32-
33168
$cl = blessed($r);
34169
is( $cl, "HEXONET::Apiconnector::Response",
35170
"API Response Instance type check" );
171+
ok( $r->description() eq "Command completed successfully" );
172+
ok( $r->code() eq 200 );
173+
ok( ref( $r->properties() ) );
174+
ok( !$r->property("DOMAIN") );
175+
isa_ok( $r->property("OBJECTID"), 'ARRAY' );
176+
ok( $r->is_success() );
177+
ok( !$r->is_tmp_error() );
178+
isa_ok( $r->columns(), 'ARRAY' );
179+
ok( $r->first() eq 0 );
180+
ok( $r->last() eq 9 );
181+
ok( $r->count() eq 10 );
182+
ok( $r->limit() eq 10 );
183+
ok( $r->total() eq 10 );
184+
ok( $r->pages() eq 1 );
185+
ok( $r->page() eq 1 );
186+
ok( !$r->prevpage() );
187+
ok( !$r->nextpage() );
188+
ok( !$r->prevpagefirst() );
189+
ok( !$r->nextpagefirst() );
190+
ok( $r->lastpagefirst() eq 0 ); #should be 9?
191+
$tmp = $r->runtime();
192+
ok( $tmp || !$tmp );
193+
$tmp = $r->queuetime();
194+
ok( $tmp || !$tmp );
195+
196+
#######################################
197+
# TESTS for Util.pm
198+
#######################################
199+
#T44
200+
$api = HEXONET::Apiconnector::connect(
201+
login => "test.user",
202+
password => "test.passw0rd",
203+
url => "https://coreapi.1api.net/api/call.cgi",
204+
entity => "1234"
205+
);
206+
$r = $api->call(
207+
{
208+
COMMAND => "QueryDomainPendingDeleteList",
209+
ZONE => [ "COM", "NET" ],
210+
LIMIT => 10,
211+
FIRST => 20
212+
}
213+
);
214+
ok( $r->code() eq 200 );
215+
216+
#T45
217+
our $uxorg = 1531479459;
218+
our $ts = HEXONET::Apiconnector::Util::sqltime($uxorg);
219+
ok( $ts eq "2018-07-13 10:57:39", $ts ); # should be 12:57:39!
220+
221+
#T46
222+
our $ux = HEXONET::Apiconnector::Util::timesql($ts);
223+
ok( $ux eq $uxorg );
224+
225+
#T47
226+
our $enc = HEXONET::Apiconnector::Util::url_encode("+");
227+
ok( $enc == "%2B" );
228+
229+
#T48
230+
our $dec = HEXONET::Apiconnector::Util::url_decode($enc);
231+
ok( $dec == "+" );
232+
233+
#T49
234+
our $key = "das stinkt zum Himmel";
235+
$enc = HEXONET::Apiconnector::Util::base64_encode($key);
236+
ok( $enc eq "ZGFzIHN0aW5rdCB6dW0gSGltbWVs" );
237+
238+
#T50
239+
$dec = HEXONET::Apiconnector::Util::base64_decode($enc);
240+
ok( $dec eq $key );

0 commit comments

Comments
 (0)