Skip to content

Commit 10833fb

Browse files
committed
Removed duplicate test. Tidied.
1 parent 1160729 commit 10833fb

File tree

1 file changed

+22
-42
lines changed

1 file changed

+22
-42
lines changed

tests/webservice_test.py

Lines changed: 22 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -28,15 +28,14 @@
2828
class TestClient(unittest.TestCase):
2929

3030
def setUp(self):
31-
self.client = Client(42, 'abcdef123456',)
31+
self.client = Client(42, 'abcdef123456')
3232

3333
base_uri = 'https://geoip.maxmind.com/geoip/v2.1/'
3434
country = {
35-
'continent': {
36-
'code': 'NA',
37-
'geoname_id': 42,
38-
'names': {'en': 'North America'}
39-
},
35+
'continent':
36+
{'code': 'NA',
37+
'geoname_id': 42,
38+
'names': {'en': 'North America'}},
4039
'country': {
4140
'geoname_id': 1,
4241
'iso_code': 'US',
@@ -47,32 +46,29 @@ def setUp(self):
4746
}
4847

4948
def _content_type(self, endpoint):
50-
return ('application/vnd.maxmind.com-' +
51-
endpoint + '+json; charset=UTF-8; version=1.0')
49+
return ('application/vnd.maxmind.com-' + endpoint +
50+
'+json; charset=UTF-8; version=1.0')
5251

5352
@requests_mock.mock()
5453
def test_country_ok(self, mock):
5554
mock.get(self.base_uri + 'country/1.2.3.4',
5655
json=self.country,
5756
status_code=200,
58-
headers={'Content-Type':
59-
self._content_type('country')})
57+
headers={'Content-Type': self._content_type('country')})
6058
country = self.client.country('1.2.3.4')
6159
self.assertEqual(type(country), geoip2.models.Country,
6260
'return value of client.country')
6361
self.assertEqual(country.continent.geoname_id, 42,
6462
'continent geoname_id is 42')
65-
self.assertEqual(country.continent.code, 'NA',
66-
'continent code is NA')
63+
self.assertEqual(country.continent.code, 'NA', 'continent code is NA')
6764
self.assertEqual(country.continent.name, 'North America',
6865
'continent name is North America')
6966
self.assertEqual(country.country.geoname_id, 1,
7067
'country geoname_id is 1')
7168
self.assertEqual(country.country.iso_code, 'US',
7269
'country iso_code is US')
7370
self.assertEqual(country.country.names,
74-
{'en': 'United States of America'},
75-
'country names')
71+
{'en': 'United States of America'}, 'country names')
7672
self.assertEqual(country.country.name, 'United States of America',
7773
'country name is United States of America')
7874
self.assertEqual(country.maxmind.queries_remaining, 11,
@@ -84,8 +80,7 @@ def test_me(self, mock):
8480
mock.get(self.base_uri + 'country/me',
8581
json=self.country,
8682
status_code=200,
87-
headers={'Content-Type':
88-
self._content_type('country')})
83+
headers={'Content-Type': self._content_type('country')})
8984
implicit_me = self.client.country()
9085
self.assertEqual(type(implicit_me), geoip2.models.Country,
9186
'country() returns Country object')
@@ -114,8 +109,8 @@ def test_no_body_error(self, mock):
114109
text='',
115110
status_code=400,
116111
headers={'Content-Type': self._content_type('country')})
117-
with self.assertRaisesRegex(HTTPError,
118-
'Received a 400 error for .* with no body'):
112+
with self.assertRaisesRegex(
113+
HTTPError, 'Received a 400 error for .* with no body'):
119114
self.client.country('1.2.3.7')
120115

121116
@requests_mock.mock()
@@ -135,15 +130,13 @@ def test_bad_body_error(self, mock):
135130
text='bad body',
136131
status_code=400,
137132
headers={'Content-Type': self._content_type('country')})
138-
with self.assertRaisesRegex(HTTPError,
139-
'it did not include the expected JSON body'
140-
):
133+
with self.assertRaisesRegex(
134+
HTTPError, 'it did not include the expected JSON body'):
141135
self.client.country('1.2.3.9')
142136

143137
@requests_mock.mock()
144138
def test_500_error(self, mock):
145-
mock.get(self.base_uri + 'country/' + '1.2.3.10',
146-
status_code=500)
139+
mock.get(self.base_uri + 'country/' + '1.2.3.10', status_code=500)
147140
with self.assertRaisesRegex(HTTPError,
148141
'Received a server error \(500\) for'):
149142
self.client.country('1.2.3.10')
@@ -166,8 +159,7 @@ def test_address_not_found_error(self, mock):
166159
json=body,
167160
status_code=404,
168161
headers={'Content-Type': self._content_type('country')})
169-
with self.assertRaisesRegex(AddressNotFoundError,
170-
'Not in DB'):
162+
with self.assertRaisesRegex(AddressNotFoundError, 'Not in DB'):
171163
self.client.country('1.2.3.13')
172164

173165
@requests_mock.mock()
@@ -217,7 +209,7 @@ def test_out_of_queries_error(self, mock):
217209
json=body,
218210
status_code=402,
219211
headers={'Content-Type': self._content_type('country')})
220-
with self.assertRaisesRegex(OutOfQueriesError, 'Out of Queries',):
212+
with self.assertRaisesRegex(OutOfQueriesError, 'Out of Queries'):
221213
self.client.country('1.2.3.18')
222214

223215
@requests_mock.mock()
@@ -229,7 +221,7 @@ def test_unknown_error(self, mock):
229221
json=body,
230222
status_code=400,
231223
headers={'Content-Type': self._content_type('country')})
232-
with self.assertRaisesRegex(InvalidRequestError, msg,):
224+
with self.assertRaisesRegex(InvalidRequestError, msg):
233225
self.client.country(ip)
234226

235227
@requests_mock.mock()
@@ -241,15 +233,12 @@ def test_request(self, mock):
241233
self.client.country('1.2.3.4')
242234
request = mock.request_history[-1]
243235

244-
self.assertEqual(request.path,
245-
'/geoip/v2.1/country/1.2.3.4',
236+
self.assertEqual(request.path, '/geoip/v2.1/country/1.2.3.4',
246237
'correct URI is used')
247-
self.assertEqual(request.headers['Accept'],
248-
'application/json',
238+
self.assertEqual(request.headers['Accept'], 'application/json',
249239
'correct Accept header')
250240
self.assertRegex(request.headers['User-Agent'],
251-
'^GeoIP2 Python Client v',
252-
'Correct User-Agent')
241+
'^GeoIP2 Python Client v', 'Correct User-Agent')
253242
self.assertEqual(request.headers['Authorization'],
254243
'Basic NDI6YWJjZGVmMTIzNDU2', 'correct auth')
255244

@@ -273,15 +262,6 @@ def test_insights_ok(self, mock):
273262
self.assertEqual(type(insights), geoip2.models.Insights,
274263
'return value of client.insights')
275264

276-
@requests_mock.mock()
277-
def test_insights_ok(self, mock):
278-
mock.get(self.base_uri + 'insights/1.2.3.4',
279-
json=self.country,
280-
status_code=200,
281-
headers={'Content-Type': self._content_type('country')})
282-
insights = self.client.insights('1.2.3.4')
283-
self.assertEqual(type(insights), geoip2.models.Insights,
284-
'return value of client.insights')
285265

286266
if __name__ == '__main__':
287267
unittest.main()

0 commit comments

Comments
 (0)