Example #1
0
    def test_remove_locations_from_special_events(self):
        city_parking_service = CityParkingService()

        for lot in city_parking_service.parking_data['lots']:
            lot['specialEvents'] = []
        city_parking_service.parking_data['lots'][0]['specialEvents'].append({
            'parkingLocation':
            'State Street Campus Garage',
            'eventVenue':
            'blah',
            'eventDatetime':
            None,
            'eventName':
            None,
            'parkingStartDatetime':
            None,
            'parkingEndDatetime':
            None,
            'webUrl':
            'http://',
        })

        city_parking_service.remove_locations_from_special_events()
        self.assertEquals(
            city_parking_service.parking_data['lots'][0]['specialEvents'][0]
            ['eventVenue'], 'blah')
        with self.assertRaises(KeyError):
            self.assertEquals(
                city_parking_service.parking_data['lots'][0]['specialEvents']
                [0]['parkingLocation'], 'State Street Campus Garage')
 def test_fill_city_parking_no_special_events(self):
     city_parking_service = CityParkingService()
     parking_avails = [{'name': 'State Street Campus Garage', 'openSpots': 5}]
     city_parking_service.fill_cityparking_data_obj(parking_avails)
     with self.assertRaises(KeyError):
         spec = city_parking_service.parking_data['lots'][0]['specialEvents']
     self.assertEquals(city_parking_service.parking_data['lots'][0]['openSpots'], 5)
Example #3
0
 def test_fill_city_parking_no_special_events(self):
     city_parking_service = CityParkingService()
     parking_avails = [{
         'name': 'State Street Campus Garage',
         'openSpots': 5
     }]
     city_parking_service.fill_cityparking_data_obj(parking_avails)
     with self.assertRaises(KeyError):
         spec = city_parking_service.parking_data['lots'][0][
             'specialEvents']
     self.assertEquals(
         city_parking_service.parking_data['lots'][0]['openSpots'], 5)
 def test_fill_city_parking_with_special_events(self):
     city_parking_service = CityParkingService()
     parking_avails = [{'name': 'State Street Campus Garage', 'openSpots': '5'}]
     spec_events = {'specialEvents': [{'parkingLocation': 'State Street Campus Garage',
                     'eventVenue': 'blah',
                     'eventDatetime': None,
                     'eventName': None,
                     'parkingStartDatetime': None,
                     'parkingEndDatetime': None,
                     'webUrl': 'http://'}]}
     city_parking_service.fill_cityparking_data_obj(parking_avails, spec_events)
     self.assertEquals(city_parking_service.parking_data['lots'][0]['openSpots'], '5')
     self.assertEquals(city_parking_service.parking_data['lots'][0]['specialEvents'][0]['eventVenue'], 'blah')
Example #5
0
    def get(self):
        lot_results = {'lots': []}
        city_lots = []
        campus_lots = []
        include_special_events = False

        # always include these headers
        self.response.headers['Content-Type'] = 'application/javascript'
        self.response.headers['Allow'] = 'GET'

        if self.request.get('expand') == 'specialevents':
            include_special_events = True

        logging.info(include_special_events)
        logging.info(city_lots)

        try:
            city_lots = CityParkingService().get_data(include_special_events)
            logging.debug('API: city_lots json response %s' % city_lots)

        except (ValueError, urlfetch.DownloadError, AttributeError) as e:
            logging.error('Failed to retrieve city data', str(e))
            self.response.status = 500
            self.response.out.write(
                json.dumps(
                    api_utils.buildErrorResponse(
                        '-1',
                        'There was a problem retrieving the city parking data')
                ))

        try:
            campus_lots = CampusParkingService().get_data(
                include_special_events)
            logging.debug('API: campus lots added, json response %s' %
                          campus_lots)
        except (ValueError, urlfetch.DownloadError, AttributeError) as e:
            logging.error('Failed to retrieve campus data', str(e))
            self.response.status = 500
            self.response.out.write(
                json.dumps(
                    api_utils.buildErrorResponse(
                        '-1',
                        'There was a problem retrieving the campus parking data'
                    )))

        lot_results['lots'] = city_lots + campus_lots

        #  encapsulate response in json or jsonp
        callback = self.request.get('callback')
        if callback is not '':
            self.response.headers['Content-Type'] = 'application/javascript'
            self.response.headers['Access-Control-Allow-Origin'] = '*'
            self.response.headers['Access-Control-Allow-Methods'] = 'GET'
            response_payload = callback + '(' + json.dumps(lot_results) + ');'
        else:
            self.response.headers['Content-Type'] = 'application/json'
            response_payload = json.dumps(lot_results)

        stathat.apiStatCount()
        self.response.out.write(response_payload)
Example #6
0
 def test_cityparking_html_parse_html_lotname(self):
     html = '<html><body><div id="availability">' \
            '<div class="dataRow"><div class="carParkName"><a href="../facilities/brayton.cfm">Brayton Lot</a></div><div class="spotsOpen">131</div></div>' \
            '<div class="dataRow rowShade"><div class="carParkName"><a href="../facilities/capSquareNorth.cfm">Capitol Square North Garage</a></div><div class="spotsOpen">345</div></div>' \
            '</div></body></html>'
     lot_details = CityParkingService().parse_availability_html(html)
     self.assertEquals(lot_details[0]['name'], 'Brayton Lot')
Example #7
0
 def test_cityparking_special_events_single_digit_hour_parse_html(self):
     html = '<html><body><table id="calendar"><tr></tr><tr></tr><tr class="rowshade"><td>5/16/2014</td><td> ' \
            'Overture Center Garage, State Street Capitol Garage</td><td>6:00 pm - 8:05 pm</td><td>Million Dollar ' \
            'Quartet</td><td>Overture Center - Overture Hall</td><td>blllkjdkjlslkdj ' \
            '1:00pm</td></tr></table></body></html>'
     se_data = CityParkingService().parse_special_events_html(html)
     self.assertEquals(se_data['specialEvents'][0]['eventDatetime'],
                       '2014-05-16T13:00:00')
    def test_remove_locations_from_special_events(self):
        city_parking_service = CityParkingService()

        for lot in city_parking_service.parking_data['lots']:
            lot['specialEvents'] = []
        city_parking_service.parking_data['lots'][0]['specialEvents'].append(
            {
                'parkingLocation': 'State Street Campus Garage',
                'eventVenue': 'blah',
                'eventDatetime': None,
                'eventName': None,
                'parkingStartDatetime': None,
                'parkingEndDatetime': None,
                'webUrl': 'http://',
            }
        )

        city_parking_service.remove_locations_from_special_events()
        self.assertEquals(city_parking_service.parking_data['lots'][0]['specialEvents'][0]['eventVenue'], 'blah')
        with self.assertRaises(KeyError):
            self.assertEquals(city_parking_service.parking_data['lots'][0]['specialEvents'][0]['parkingLocation'], 'State Street Campus Garage')
Example #9
0
 def test_fill_city_parking_with_special_events(self):
     city_parking_service = CityParkingService()
     parking_avails = [{
         'name': 'State Street Campus Garage',
         'openSpots': '5'
     }]
     spec_events = {
         'specialEvents': [{
             'parkingLocation': 'State Street Campus Garage',
             'eventVenue': 'blah',
             'eventDatetime': None,
             'eventName': None,
             'parkingStartDatetime': None,
             'parkingEndDatetime': None,
             'webUrl': 'http://'
         }]
     }
     city_parking_service.fill_cityparking_data_obj(parking_avails,
                                                    spec_events)
     self.assertEquals(
         city_parking_service.parking_data['lots'][0]['openSpots'], '5')
     self.assertEquals(
         city_parking_service.parking_data['lots'][0]['specialEvents'][0]
         ['eventVenue'], 'blah')
Example #10
0
 def test_cityparking_bad_special_events_bad_parse_html(self):
     bad_html = '<html><body><div id="availability"><div class="garbage"></div></div></body></html>'
     se_data = CityParkingService().parse_special_events_html(bad_html)
     self.assertEquals(se_data['specialEvents'], [])
Example #11
0
 def test_cityparking_bad_special_events_html_empty_html(self):
     se_data = CityParkingService().parse_special_events_html('')
     self.assertEquals(se_data['specialEvents'], [])
Example #12
0
 def test_cityparking_bad_city_special_events_url(self):
     html = CityParkingService().fetch_special_events_html(
         'http://cityofmadison---bad.com')
     self.assertIsNone(html)
Example #13
0
 def test_cityparking_bad_html_bad_parse_html(self):
     bad_html = '<html><body><div id="availability"><div class="datadRow"></div></div></body></html>'
     with self.assertRaises(ValueError):
         CityParkingService().parse_availability_html(bad_html)
Example #14
0
 def test_cityparking_bad_html_empty_html(self):
     with self.assertRaises(AttributeError):
         CityParkingService().parse_availability_html('')
Example #15
0
 def test_cityparking_bad_html_none(self):
     with self.assertRaises(TypeError):
         CityParkingService().parse_availability_html(None)
Example #16
0
 def test_cityparking_bad_city_avail_url(self):
     with self.assertRaises(urlfetch.DownloadError):
         CityParkingService().fetch_availability_html(
             'http://www.cityofmadisonbaddomain.com')