예제 #1
0
    def test_get_venue_coords_bad_http_response(self):
        api_url_re = re.compile('https://api.mapbox.com/geocoding/(.*)')
        responses.add(responses.GET, api_url_re, status=401)

        # Should default to DC coords if API request bombed
        coords = get_venue_coords(city='Boston', state='MA')
        self.assertEqual(coords, '-77.039628,38.898238')
예제 #2
0
    def test_get_venue_coords_bad_mapbox_response(self):
        api_url_re = re.compile('https://api.mapbox.com/geocoding/(.*)')
        data_json = {'error': 'Failed to find location'}
        responses.add(responses.GET, api_url_re, json=data_json)

        # Should default to DC coords if MapBox returns bad JSON
        self.assertEqual(get_venue_coords(), '-77.039628,38.898238')
    def test_get_venue_coords_bad_mapbox_response(self):
        api_url_re = re.compile('https://api.mapbox.com/geocoding/(.*)')
        data_json = {'error': 'Failed to find location'}
        responses.add(responses.GET, api_url_re, json=data_json)

        # Should default to DC coords if MapBox returns bad JSON
        self.assertEqual(get_venue_coords(), '-77.039628,38.898238')
    def test_get_venue_coords_bad_http_response(self):
        api_url_re = re.compile('https://api.mapbox.com/geocoding/(.*)')
        responses.add(responses.GET, api_url_re, status=401)

        # Should default to DC coords if API request bombed
        coords = get_venue_coords(city='Boston', state='MA')
        self.assertEqual(coords, '-77.039628,38.898238')
예제 #5
0
    def location_image_url(self, scale='2', size='276x155', zoom='12'):
        if not self.venue_coords:
            self.venue_coords = get_venue_coords(self.venue_city,
                                                 self.venue_state)
        api_url = 'https://api.mapbox.com/styles/v1/mapbox/streets-v11/static'
        static_map_image_url = '{}/{},{}/{}?access_token={}'.format(
            api_url, self.venue_coords, zoom, size,
            settings.MAPBOX_ACCESS_TOKEN)

        return static_map_image_url
    def test_get_venue_coords_broken_api_format(self):
        api_url_re = re.compile('https://api.mapbox.com/geocoding/(.*)')
        data_json = {
            'features': [{
                'new_geometry': {
                    'coordinates': ['123.456', '321.654']
                }
            }]
        }
        responses.add(responses.GET, api_url_re, json=data_json)

        coords = get_venue_coords(city='Boston', state='MA')
        self.assertEqual(coords, '-77.039628,38.898238')
예제 #7
0
    def location_image_url(self, scale='2', size='276x155', zoom='12'):
        if not self.venue_coords:
            self.venue_coords = get_venue_coords(
                self.venue_city, self.venue_state
            )
        api_url = 'https://api.mapbox.com/styles/v1/mapbox/streets-v11/static'
        static_map_image_url = '{}/{},{}/{}?access_token={}'.format(
            api_url,
            self.venue_coords,
            zoom,
            size,
            settings.MAPBOX_ACCESS_TOKEN
        )

        return static_map_image_url
예제 #8
0
    def test_get_venue_coords_broken_api_format(self):
        api_url_re = re.compile('https://api.mapbox.com/geocoding/(.*)')
        data_json = {
            'features': [{
                'new_geometry': {
                    'coordinates': [
                        '123.456',
                        '321.654'
                    ]
                }
            }]
        }
        responses.add(responses.GET, api_url_re, json=data_json)

        coords = get_venue_coords(city='Boston', state='MA')
        self.assertEqual(coords, '-77.039628,38.898238')
예제 #9
0
 def save(self, *args, **kwargs):
     self.venue_coords = get_venue_coords(self.venue_city, self.venue_state)
     return super(EventPage, self).save(*args, **kwargs)
예제 #10
0
 def save(self, *args, **kwargs):
     self.venue_coords = get_venue_coords(self.venue_city, self.venue_state)
     return super(EventPage, self).save(*args, **kwargs)
예제 #11
0
 def test_get_venue_coords_default_venue_coords_when_empty(self):
     # Should default to DC coords if no city/state provided
     self.assertEqual(get_venue_coords(city='', state=''), '-77.039628,38.898238')
예제 #12
0
 def test_get_venue_coords_no_mapbox_token(self):
     # Should default to DC coords if no mapbox token was provided
     self.assertEqual(get_venue_coords(), '-77.039628,38.898238')
예제 #13
0
def forwards(apps, schema_editor):
    EventPage = apps.get_model('v1', 'EventPage')
    for page in EventPage.objects.all():
        page.venue_coords = get_venue_coords(page.venue_city, page.venue_state)
        page.save()
예제 #14
0
 def test_get_venue_coords_default_venue_coords_when_empty(self):
     # Should default to DC coords if no city/state provided
     self.assertEqual(get_venue_coords(city='', state=''),
                      '-77.039628,38.898238')
예제 #15
0
 def test_get_venue_coords_no_mapbox_token(self):
     # Should default to DC coords if no mapbox token was provided
     self.assertEqual(get_venue_coords(), '-77.039628,38.898238')