File: Country.t

package info (click to toggle)
libgeoip2-perl 2.006002-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 2,156 kB
  • sloc: perl: 2,275; makefile: 10
file content (177 lines) | stat: -rw-r--r-- 3,549 bytes parent folder | download | duplicates (3)
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
use strict;
use warnings;

use Test::More 0.88;

use GeoIP2::Model::Country;

{
    my %raw = (
        continent => {
            code       => 'NA',
            geoname_id => 42,
            names      => { en => 'North America' },
        },
        country => {
            geoname_id => 1,
            iso_code   => 'US',
            names      => { en => 'United States of America' },
        },
        maxmind => {
            queries_remaining => 42,
        },
        registered_country => {
            geoname_id           => 2,
            is_in_european_union => 1,
            iso_code             => 'DE',
            names                => { en => 'Germany' },
        },
        traits => {
            ip_address => '1.2.3.4',
        },
    );

    my $model = GeoIP2::Model::Country->new(%raw);

    isa_ok(
        $model,
        'GeoIP2::Model::Country',
        'minimal GeoIP2::Model::Country object'
    );

    isa_ok(
        $model->continent,
        'GeoIP2::Record::Continent',
        '$model->continent'
    );

    isa_ok(
        $model->country,
        'GeoIP2::Record::Country',
        '$model->country'
    );

    isa_ok(
        $model->maxmind,
        'GeoIP2::Record::MaxMind',
        '$model->maxmind'
    );

    isa_ok(
        $model->registered_country,
        'GeoIP2::Record::Country',
        '$model->registered_country'
    );

    isa_ok(
        $model->traits,
        'GeoIP2::Record::Traits',
        '$model->traits'
    );

    is(
        $model->continent->geoname_id,
        42,
        'continent geoname_id is 42'
    );

    is(
        $model->continent->code,
        'NA',
        'continent code is NA'
    );

    is_deeply(
        $model->continent->names,
        { en => 'North America' },
        'continent names'
    );

    is(
        $model->continent->name,
        'North America',
        'continent name is North America'
    );

    is(
        $model->country->geoname_id,
        1,
        'country geoname_id is 1'
    );

    is(
        $model->country->is_in_european_union,
        0,
        'country is_in_european_union is 0'
    );

    is(
        $model->country->iso_code,
        'US',
        'country iso_code is US'
    );

    is_deeply(
        $model->country->names,
        { en => 'United States of America' },
        'country names'
    );

    is(
        $model->country->name,
        'United States of America',
        'country name is United States of America'
    );

    is(
        $model->country->confidence,
        undef,
        'country confidence is undef'
    );

    is(
        $model->registered_country->geoname_id,
        2,
        'registered_country geoname_id is 2'
    );

    is(
        $model->registered_country->is_in_european_union,
        1,
        'registered_country is_in_european_union is 1'
    );

    is(
        $model->registered_country->iso_code,
        'DE',
        'registered_country iso_code is DE'
    );

    is_deeply(
        $model->registered_country->names,
        { en => 'Germany' },
        'registered_country names'
    );

    is(
        $model->registered_country->name,
        'Germany',
        'registered_country name is Germany'
    );

    for my $meth (qw( is_anonymous_proxy is_satellite_provider )) {
        is(
            $model->traits->$meth(),
            0,
            "traits $meth returns 0 by default"
        );
    }

    is_deeply(
        $model->raw,
        \%raw,
        'raw method returns raw input'
    );
}

done_testing();