-
Notifications
You must be signed in to change notification settings - Fork 122
Expand file tree
/
Copy pathhandler_lite_test.py
More file actions
73 lines (60 loc) · 2.17 KB
/
handler_lite_test.py
File metadata and controls
73 lines (60 loc) · 2.17 KB
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
import os
import pytest
from ipinfo import handler_utils
from ipinfo.cache.default import DefaultCache
from ipinfo.details import Details
from ipinfo.handler_lite import HandlerLite
def test_init():
token = "mytesttoken"
handler = HandlerLite(token)
assert handler.access_token == token
assert isinstance(handler.cache, DefaultCache)
assert "US" in handler.countries
def test_headers():
token = "mytesttoken"
handler = HandlerLite(token, headers={"custom_field": "yes"})
headers = handler_utils.get_headers(token, handler.headers)
assert "user-agent" in headers
assert "accept" in headers
assert "authorization" in headers
assert "custom_field" in headers
@pytest.mark.skipif(
"IPINFO_TOKEN" not in os.environ,
reason="Can't call Lite API without token",
)
def test_get_details():
token = os.environ.get("IPINFO_TOKEN", "")
handler = HandlerLite(token)
details = handler.getDetails("8.8.8.8")
assert isinstance(details, Details)
assert details.ip == "8.8.8.8"
assert details.asn == "AS15169"
assert details.as_name == "Google LLC"
assert details.as_domain == "google.com"
assert details.country_code == "US"
assert details.country == "United States"
assert details.continent_code == "NA"
assert details.continent == {"code": "NA", "name": "North America"}
assert details.country_name == "United States"
assert not details.isEU
assert (
details.country_flag_url
== "https://cdn.ipinfo.io/static/images/countries-flags/US.svg"
)
assert details.country_flag == {"emoji": "🇺🇸", "unicode": "U+1F1FA U+1F1F8"}
assert details.country_currency == {"code": "USD", "symbol": "$"}
assert not hasattr(details, "latitude")
assert not hasattr(details, "longitude")
#############
# BOGON TESTS
#############
@pytest.mark.skipif(
"IPINFO_TOKEN" not in os.environ,
reason="Can't call Lite API without token",
)
def test_bogon_details():
token = os.environ.get("IPINFO_TOKEN", "")
handler = HandlerLite(token)
details = handler.getDetails("127.0.0.1")
assert isinstance(details, Details)
assert details.all == {"bogon": True, "ip": "127.0.0.1"}