def test_geocode_servererror(self):
        response = Mock()
        response.status_code = 500
        get = Mock(return_value=response)

        with self.patch('get', get):
            func = geocode.GeoCodeService().geocode
            error = geocode.InvalidResponse
            self.assertRaises(error, func, 'query')
    def geocoordinates(self, data):
        latitude = data.get('latitude', None)
        longitude = data.get('longitude', None)
        if latitude and longitude:
            return GEOSGeometry('POINT(%s %s)' % (longitude, latitude))

        query = data.get('query', None)
        if query is not None:
            try:
                return geocode.GeoCodeService().geocode(query)
            except geocode.ServiceError:
                return None
    def test_geocode_zeroresults(self):
        response = Mock()
        response.status_code = 200
        response.json = Mock(return_value={
            'results': [],
            'status': 'ZERO_RESULTS'
        })
        get = Mock(return_value=response)

        with self.patch('get', get):
            func = geocode.GeoCodeService().geocode
            error = geocode.ZeroResuls
            self.assertRaises(error, func, 'query')