Skip to content

Commit b8a196a

Browse files
committed
add user_count trait
1 parent ccbbbc9 commit b8a196a

File tree

4 files changed

+22
-1
lines changed

4 files changed

+22
-1
lines changed

HISTORY.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ History
1515
* Python 3.3 and 3.4 are no longer supported.
1616
* Updated documentation of anonymizer attributes - ``is_anonymous_vpn`` and
1717
``is_hosting_provider`` - to be more descriptive.
18+
* Added support for 'user_count' trait for the GeoIP2 Precision webservice.
1819

1920
2.9.0 (2018-05-25)
2021
++++++++++++++++++

geoip2/records.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -688,6 +688,14 @@ class Traits(Record):
688688
689689
:type: unicode
690690
691+
.. attribute:: user_count
692+
693+
The estimated number of users sharing the IP/network during the past 24
694+
hours. For IPv4, the count is for the individual IP. For IPv6, the count
695+
is for the /64 network.
696+
697+
:type: int
698+
691699
.. attribute:: user_type
692700
693701
The user type associated with the IP
@@ -733,6 +741,7 @@ def __init__(self,
733741
network=None,
734742
organization=None,
735743
prefix_len=None,
744+
user_count=None,
736745
user_type=None,
737746
**_):
738747
self.autonomous_system_number = autonomous_system_number
@@ -750,6 +759,7 @@ def __init__(self,
750759
self.isp = isp
751760
self.organization = organization
752761
self.user_type = user_type
762+
self.user_count = user_count
753763
self.ip_address = ip_address
754764
self._network = network
755765
self._prefix_len = prefix_len

tests/models_test.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ def test_insights_full(self):
104104
'isp': 'Comcast',
105105
'network_speed': 'cable/DSL',
106106
'organization': 'Blorg',
107+
'user_count': 2,
107108
'user_type': 'college',
108109
},
109110
}
@@ -183,6 +184,8 @@ def test_insights_full(self):
183184
self.assertIs(model.traits.is_satellite_provider, True)
184185
self.assertIs(model.traits.is_tor_exit_node, True)
185186

187+
self.assertEqual(model.traits.user_count, 2)
188+
186189
def test_insights_min(self):
187190
model = geoip2.models.Insights({'traits': {'ip_address': '5.6.7.8'}})
188191
self.assertEqual(type(model), geoip2.models.Insights,

tests/webservice_test.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import sys
55
sys.path.append('..')
66

7+
import copy
78
import geoip2
89
import requests_mock
910
from geoip2.errors import (AddressNotFoundError, AuthenticationError,
@@ -59,6 +60,11 @@ def setUp(self):
5960
},
6061
}
6162

63+
# this is not a comprehensive representation of the
64+
# JSON from the server
65+
insights = copy.deepcopy(country)
66+
insights['traits']['user_count'] = 2
67+
6268
def _content_type(self, endpoint):
6369
return ('application/vnd.maxmind.com-' + endpoint +
6470
'+json; charset=UTF-8; version=1.0')
@@ -276,14 +282,15 @@ def test_city_ok(self, mock):
276282
@requests_mock.mock()
277283
def test_insights_ok(self, mock):
278284
mock.get(self.base_uri + 'insights/1.2.3.4',
279-
json=self.country,
285+
json=self.insights,
280286
status_code=200,
281287
headers={'Content-Type': self._content_type('country')})
282288
insights = self.client.insights('1.2.3.4')
283289
self.assertEqual(type(insights), geoip2.models.Insights,
284290
'return value of client.insights')
285291
self.assertEqual(insights.traits.network,
286292
compat_ip_network('1.2.3.0/24'), 'network')
293+
self.assertEqual(insights.traits.user_count, 2, 'user_count is 2')
287294

288295
def test_named_constructor_args(self):
289296
id = '47'

0 commit comments

Comments
 (0)