-
Notifications
You must be signed in to change notification settings - Fork 0
/
03-retrieve-sciper.t
60 lines (49 loc) · 1.66 KB
/
03-retrieve-sciper.t
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# Original work (c) ECOLE POLYTECHNIQUE FEDERALE DE LAUSANNE, Switzerland, VPSI, 2017-2018.
# Modified work (c) William Belle, 2018-2019.
# See the LICENSE file for more details.
use strict;
use warnings;
use IO::All;
use lib 't/';
use MockSite;
use EPFL::Sciper::List qw/p_buildUrl retrieveSciper toJson toTsv/;
use Test::JSON;
use Test::MockModule;
use Test::More tests => 10;
is(
p_buildUrl('k'),
'https://search.epfl.ch/json/autocompletename.action?maxRows=99999999&term=k',
'correct url'
);
my $urlRoot = MockSite::mockLocalSite('t/resources/epfl-search');
my $module = Test::MockModule->new('EPFL::Sciper::List');
$module->mock(
'p_buildUrl',
sub {
my $letter = shift;
return $urlRoot . q{/} . $letter . '.json';
}
);
my @personsList = retrieveSciper();
is( scalar @personsList, 62, 'number of persons' );
is( $personsList[0]->{sciper}, 100654, 'sciper of first person' );
is( $personsList[0]->{name}, 'Klum', 'name of first person' );
is( $personsList[22]->{sciper}, 168745, 'sciper of first person' );
is( $personsList[22]->{firstname}, 'Rebecca', 'name of first person' );
$urlRoot = MockSite::mockLocalSite('t/resources/epfl-search-empty');
$module->mock(
'p_buildUrl',
sub {
my $letter = shift;
return $urlRoot . q{/} . $letter . '.json';
}
);
my $output = toJson(@personsList);
my $content < io 't/resources/output.json';
is_valid_json( $output, 'is valid json' );
is_json( $output, $content, 'same json' );
$output = toTsv(@personsList);
$content < io 't/resources/output.tsv';
is( $output, $content, 'same tsv output' );
@personsList = retrieveSciper();
is( scalar @personsList, 0, 'number of persons' );