|
22 | 22 |
|
23 | 23 | if sys.version_info[0] == 2: |
24 | 24 | unittest.TestCase.assertRaisesRegex = unittest.TestCase.assertRaisesRegexp |
| 25 | + unittest.TestCase.assertRegex = unittest.TestCase.assertRegexpMatches |
| 26 | + |
25 | 27 |
|
26 | 28 |
|
27 | 29 | @patch.object(requests, 'get') |
@@ -163,10 +165,17 @@ def test_300_error(self, get): |
163 | 165 | def test_request(self, get): |
164 | 166 | self._setup_get(get, 'country', 200, self.country) |
165 | 167 | country = self.client.country('1.2.3.4') |
166 | | - get.assert_called_with('https://geoip.maxmind.com' |
167 | | - '/geoip/v2.0/country/1.2.3.4', |
168 | | - headers={'Accept': 'application/json'}, |
169 | | - auth=(42, 'abcdef123456')) |
| 168 | + args, kwargs = get.call_args |
| 169 | + self.assertEqual(args[0], 'https://geoip.maxmind.com' |
| 170 | + '/geoip/v2.0/country/1.2.3.4', |
| 171 | + 'correct URI is used') |
| 172 | + self.assertEqual(kwargs.get('headers').get('Accept'), |
| 173 | + 'application/json', |
| 174 | + 'correct Accept header') |
| 175 | + self.assertRegex(kwargs.get('headers').get('User-Agent'), |
| 176 | + '^GeoIP2 Python Client v', |
| 177 | + 'Correct User-Agent') |
| 178 | + self.assertEqual(kwargs.get('auth'), (42, 'abcdef123456')) |
170 | 179 |
|
171 | 180 | def test_city_ok(self, get): |
172 | 181 | self._setup_get(get, 'city', 200, self.country) |
|
0 commit comments