File tree Expand file tree Collapse file tree 2 files changed +34
-6
lines changed
Expand file tree Collapse file tree 2 files changed +34
-6
lines changed Original file line number Diff line number Diff line change @@ -82,16 +82,29 @@ class Client(object):
8282
8383 """
8484
85- def __init__ (self ,
86- account_id ,
87- license_key ,
88- host = 'geoip.maxmind.com' ,
89- locales = None ,
90- timeout = None ):
85+ def __init__ (
86+ self ,
87+ account_id = None ,
88+ license_key = None ,
89+ host = 'geoip.maxmind.com' ,
90+ locales = None ,
91+ timeout = None ,
92+
93+ # This is deprecated and not documented for that reason.
94+ # It can be removed if we do a major release in the future.
95+ user_id = None ):
9196 """Construct a Client."""
9297 # pylint: disable=too-many-arguments
9398 if locales is None :
9499 locales = ['en' ]
100+ if account_id is None :
101+ account_id = user_id
102+
103+ if account_id is None :
104+ raise TypeError ('The account_id is a required parameter' )
105+ if license_key is None :
106+ raise TypeError ('The license_key is a required parameter' )
107+
95108 self ._locales = locales
96109 # requests 2.12.2 requires that the username passed to auth be bytes
97110 # or a string, with the former being preferred.
Original file line number Diff line number Diff line change @@ -293,6 +293,21 @@ def test_insights_ok(self, mock):
293293 type (insights ), geoip2 .models .Insights ,
294294 'return value of client.insights' )
295295
296+ def test_named_constructor_args (self ):
297+ id = '47'
298+ key = '1234567890ab'
299+ for client in (Client (account_id = id , license_key = key ),
300+ Client (user_id = id , license_key = key )):
301+ self .assertEqual (client ._account_id , id )
302+ self .assertEqual (client ._license_key , key )
303+
304+ def test_missing_constructor_args (self ):
305+ with self .assertRaises (TypeError ):
306+ Client (license_key = '1234567890ab' )
307+
308+ with self .assertRaises (TypeError ):
309+ Client ('47' )
310+
296311
297312if __name__ == '__main__' :
298313 unittest .main ()
You can’t perform that action at this time.
0 commit comments