Exemplo n.º 1
0
 def test_fill_campusparking_with_special_events(self):
     campus_parking_service = CampusParkingService()
     parking_avails = [{
         'name': 'University Avenue Ramp',
         'openSpots': 5,
         'shortName': '020'
     }]
     spec_events = {
         'specialEvents': [{
             'parkingLocations': ['20'],
             'eventVenue': 'blah',
             'eventDatetime': None,
             'eventName': None,
             'parkingStartDatetime': None,
             'parkingEndDatetime': None,
             'webUrl': 'http://'
         }]
     }
     campus_parking_service.fill_campusparking_data_obj(
         parking_avails, spec_events)
     self.assertEquals(
         campus_parking_service.parking_data['lots'][0]['openSpots'], 5)
     self.assertEquals(
         campus_parking_service.parking_data['lots'][0]['specialEvents'][0]
         ['eventVenue'], 'blah')
 def test_fill_campusparking_no_special_events(self):
     campus_parking_service = CampusParkingService()
     parking_avails = [{'name': 'University Avenue Ramp', 'openSpots': 5, 'shortName': '020'}]
     campus_parking_service.fill_campusparking_data_obj(parking_avails)
     with self.assertRaises(KeyError):  # special events should be None
         spec = campus_parking_service.parking_data['lots'][0]['specialEvents']
     self.assertEquals(campus_parking_service.parking_data['lots'][0]['openSpots'], 5)
Exemplo n.º 3
0
 def test_fill_campusparking_no_special_events(self):
     campus_parking_service = CampusParkingService()
     parking_avails = [{
         'name': 'University Avenue Ramp',
         'openSpots': 5,
         'shortName': '020'
     }]
     campus_parking_service.fill_campusparking_data_obj(parking_avails)
     with self.assertRaises(KeyError):  # special events should be None
         spec = campus_parking_service.parking_data['lots'][0][
             'specialEvents']
     self.assertEquals(
         campus_parking_service.parking_data['lots'][0]['openSpots'], 5)
Exemplo n.º 4
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)
Exemplo n.º 5
0
 def test_campusparking_special_events_parse_html(self):
     html = '<table id="event2" class="event-item" border="0" cellspacing="0">' \
            '<tbody><tr><th class="event-head">06/12/2014:&nbsp;&nbsp;WIAA Softball</th></tr>' \
            '<tr><td>Times lots will be impacted:</td><td>7:00 a.m. </td></tr>' \
            '<tr><td>Event Parking Available in Lots:</td><td>60, 76</td></tr>' \
            '</tbody></table>'
     se_data = CampusParkingService().parse_special_events_html(html)
     self.assertEquals(se_data['specialEvents'][0]['eventDatetime'],
                       '2014-06-12T07:00:00')
 def test_fill_campusparking_with_special_events(self):
     campus_parking_service = CampusParkingService()
     parking_avails = [{'name': 'University Avenue Ramp', 'openSpots': 5, 'shortName': '020'}]
     spec_events = {
         'specialEvents': [
             {
                 'parkingLocations': ['20'],
                 'eventVenue': 'blah',
                 'eventDatetime': None,
                 'eventName': None,
                 'parkingStartDatetime': None,
                 'parkingEndDatetime': None,
                 'webUrl': 'http://'
             }
         ]
     }
     campus_parking_service.fill_campusparking_data_obj(parking_avails, spec_events)
     self.assertEquals(campus_parking_service.parking_data['lots'][0]['openSpots'], 5)
     self.assertEquals(campus_parking_service.parking_data['lots'][0]['specialEvents'][0]['eventVenue'], 'blah')
    def test_remove_campus_locations_from_special_events(self):
        campus_parking_service = CampusParkingService()

        for lot in campus_parking_service.parking_data['lots']:
            lot['specialEvents'] = []
        campus_parking_service.parking_data['lots'][0]['specialEvents'].append(
            {
                'parkingLocations': ['20'],
                'eventVenue': 'blah',
                'eventDatetime': None,
                'eventName': None,
                'parkingStartDatetime': None,
                'parkingEndDatetime': None,
                'webUrl': 'http://'
            }
        )

        campus_parking_service.remove_locations_from_special_events()
        self.assertEquals(campus_parking_service.parking_data['lots'][0]['specialEvents'][0]['eventVenue'], 'blah')
        with self.assertRaises(KeyError):
            self.assertEquals(campus_parking_service.parking_data['lots'][0]['specialEvents'][0]['parkingLocations'], ['20'])
Exemplo n.º 8
0
    def test_remove_campus_locations_from_special_events(self):
        campus_parking_service = CampusParkingService()

        for lot in campus_parking_service.parking_data['lots']:
            lot['specialEvents'] = []
        campus_parking_service.parking_data['lots'][0]['specialEvents'].append(
            {
                'parkingLocations': ['20'],
                'eventVenue': 'blah',
                'eventDatetime': None,
                'eventName': None,
                'parkingStartDatetime': None,
                'parkingEndDatetime': None,
                'webUrl': 'http://'
            })

        campus_parking_service.remove_locations_from_special_events()
        self.assertEquals(
            campus_parking_service.parking_data['lots'][0]['specialEvents'][0]
            ['eventVenue'], 'blah')
        with self.assertRaises(KeyError):
            self.assertEquals(
                campus_parking_service.parking_data['lots'][0]['specialEvents']
                [0]['parkingLocations'], ['20'])
Exemplo n.º 9
0
 def test_campusparking_bad_special_events_bad_parse_html(self):
     bad_html = '<html><body><table class="event-item"></body></html>'
     se_data = CampusParkingService().parse_special_events_html(bad_html)
     self.assertEquals(se_data['specialEvents'], [])
Exemplo n.º 10
0
 def test_campusparking_bad_city_special_events_url(self):
     html = CampusParkingService().fetch_special_events_html(
         'http://campus---bad.com')
     self.assertIsNone(html)
Exemplo n.º 11
0
 def test_campusparking_bad_special_events_html_empty_html(self):
     se_data = CampusParkingService().parse_special_events_html('')
     self.assertEquals(se_data['specialEvents'], [])
Exemplo n.º 12
0
 def test_campusparking_html_parse_html_lotname(self):
     html = '<html><body><table id="ctl00_ctl00_central_block_right_navi_cnt_gvName"><tr></tr><tr><td></td><td>020 UNIVERSITY AVE RAMP</td><td>5</td></tr></table></body></html>'
     lot_details = CampusParkingService().parse_availability_html(html)
     self.assertEquals(lot_details[0]['shortName'], '020')
Exemplo n.º 13
0
 def test_campusparking_bad_html_bad_avail_parse_html(self):
     bad_html = '<html><body><table id="ctl00_ctl00_central_block_right_navi_cnt_gvName"><tr></tr><tr><td></td></tr></table></body></html>'
     with self.assertRaises(IndexError):
         CampusParkingService().parse_availability_html(bad_html)
Exemplo n.º 14
0
 def test_campusparking_bad_avail_html_empty_html(self):
     with self.assertRaises(AttributeError):
         CampusParkingService().parse_availability_html('')
Exemplo n.º 15
0
 def test_campusparking_bad_avail_html_none(self):
     with self.assertRaises(TypeError):
         CampusParkingService().parse_availability_html(None)
Exemplo n.º 16
0
 def test_campusparking_bad_campus_avail_url(self):
     with self.assertRaises(urlfetch.DownloadError):
         CampusParkingService().fetch_availability_html(
             'http://www.campusofmadisonbaddomain.com')