File tree Expand file tree Collapse file tree 7 files changed +106
-1
lines changed
Expand file tree Collapse file tree 7 files changed +106
-1
lines changed Original file line number Diff line number Diff line change 11from setuptools import setup
22
33setup (name = 'ipinfo_wrapper' ,
4- version = '0.1.4 ' ,
4+ version = '0.1.5 ' ,
55 description = 'Official Python library for IPInfo' ,
66 url = 'https://github.com/ipinfo/python' ,
77 author = 'James Timmins' ,
1111 install_requires = [
1212 'requests' ,
1313 'cachetools' ,
14+ 'pytest' ,
1415 ],
1516 include_package_data = True ,
1617 zip_safe = False )
Original file line number Diff line number Diff line change 1+ from ipinfo_wrapper .cache .default import DefaultCache
2+
3+
4+ def _get_new_cache ():
5+ maxsize = 4
6+ ttl = 8
7+ return DefaultCache (maxsize , ttl )
8+
9+
10+ def test_contains ():
11+ cache = _get_new_cache ()
12+ cache ['foo' ] = 'bar'
13+
14+ assert 'foo' in cache
15+
16+
17+ def test_get ():
18+ cache = _get_new_cache ()
19+ cache ['foo' ] = 'bar'
20+
21+ assert cache ['foo' ] == 'bar'
Original file line number Diff line number Diff line change 1+ import pytest
2+ from ipinfo_wrapper .details import Details
3+
4+
5+ def test_init ():
6+ data = {'foo' : 'bar' }
7+ details = Details (data )
8+ assert details .details == data
9+
10+
11+ def test_getattr_success ():
12+ data = {'foo' : 'bar' }
13+ details = Details (data )
14+ assert details .foo == data ['foo' ]
15+
16+
17+ def test_getattr_fail ():
18+ data = {'foo' : 'bar' }
19+ details = Details (data )
20+ with pytest .raises (Exception ):
21+ details .blah
22+
23+
24+ def test_all ():
25+ data = {'foo' : 'bar' , 'ham' : 'eggs' }
26+ details = Details (data )
27+ assert details .all == data
Original file line number Diff line number Diff line change 1+ from ipinfo_wrapper .cache .default import DefaultCache
2+ from ipinfo_wrapper .details import Details
3+ from ipinfo_wrapper .handler import Handler
4+ import ipaddress
5+
6+
7+ def test_init ():
8+ token = 'mytesttoken'
9+ handler = Handler (token )
10+ assert handler .access_token == token
11+ assert isinstance (handler .cache , DefaultCache )
12+ assert 'US' in handler .countries
13+
14+
15+ def test_headers ():
16+ token = 'mytesttoken'
17+ handler = Handler (token )
18+ headers = handler ._get_headers ()
19+
20+ assert 'user-agent' in headers
21+ assert 'accept' in headers
22+ assert 'authorization' in headers
23+
24+
25+ def test_get_details ():
26+ handler = Handler ()
27+ fake_details = {
28+ 'country' : 'US' ,
29+ 'ip' : '127.0.0.1' ,
30+ 'loc' : '12.34,56.78'
31+ }
32+
33+ handler ._requestDetails = lambda x : fake_details
34+
35+ details = handler .getDetails (fake_details ['ip' ])
36+ assert isinstance (details , Details )
37+ assert details .country == fake_details ['country' ]
38+ assert details .country_name == 'United States'
39+ assert details .ip == fake_details ['ip' ]
40+ assert isinstance (details .ip_address , ipaddress .IPv4Address )
41+ assert details .loc == fake_details ['loc' ]
42+ assert details .longitude == '56.78'
43+ assert details .latitude == '12.34'
Original file line number Diff line number Diff line change 1+ import ipinfo_wrapper
2+ from ipinfo_wrapper .handler import Handler
3+
4+
5+ def test_get_handler ():
6+ handler = ipinfo_wrapper .getHandler ()
7+ assert (isinstance (handler , Handler ))
Original file line number Diff line number Diff line change 1+ def f (x ):
2+ return x + 1
3+
4+
5+ def test_answer ():
6+ assert f (1 ) == 2
You can’t perform that action at this time.
0 commit comments