Exemplo n.º 1
0
 def setUp(self):
     self.lat1 = 37.63983
     self.long1 = -123.173825
     self.lat2 = 37.929824
     self.long2 = -122.28178
     mock_response = requests.Response()
     mock_response._content = json.dumps({
         "features": [{
             "bounds": [self.lat1, self.long1, self.lat2, self.long2],
             "centroid": [37.759715, -122.693976],
             "id":
             "4oFkxX7RcUdirjtaenEQIV",
             "properties": {
                 "boundary_type": "city",
                 "boundary_type_string": "City/Place",
                 "context": {
                     "us_state": "CA",
                     "us_state_name": "California"
                 },
                 "name": "San Francisco",
                 "source": "tiger.census.gov"
             },
             "type":
             "Feature"
         }]
     }).encode('utf-8')
     ua.Airship._request = mock.Mock()
     ua.Airship._request.side_effect = [mock_response]
     airship = ua.Airship('key', 'secret')
     self.l = ua.LocationFinder(airship)
Exemplo n.º 2
0
 def test_date_ranges(self):
     expected_resp = [{
         'unit': 'hours',
         'cutoff': '2015-10-01 15'
     }, {
         'unit': 'days',
         'cutoff': '2015-10-01'
     }, {
         'unit': 'weeks',
         'cutoff': '2015-W10'
     }, {
         'unit': 'months',
         'cutoff': '2015-10'
     }, {
         'unit': 'years',
         'cutoff': '2015-10'
     }]
     with mock.patch.object(ua.Airship, '_request') as mock_request:
         mock_response = requests.Response()
         mock_response._content = json.dumps(expected_resp).encode('utf-8')
         mock_request.return_value = mock_response
         airship = ua.Airship('key', 'secret')
         location = ua.LocationFinder(airship)
         actual_resp = location.date_ranges()
         self.assertEqual(actual_resp, expected_resp)