# Path: api/v2/parking/parking.py
# class ParkingHandler(webapp.RequestHandler):
#     def post(self):
#         self.response.headers['Content-Type'] = 'application/javascript'
#         self.response.headers['Allow'] = 'GET'
#         self.response.status = 405  # method not allowed
#         self.response.out.write(
#             json.dumps(
#                 api_utils.buildErrorResponse('-1', 'The API does not support POST requests')
#             )
#         )
# 
#     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)


import sys
import os
import webapp2
import webtest
import unittest
import datetime
from google.appengine.ext import testbed
from api.v2.parking.parking import ParkingHandler


# set up relative paths to app dependencies
sys.path.append(os.path.realpath('../../../'))
sys.path.append(os.path.realpath('../../'))
sys.path.append(os.path.realpath('../../v2'))
sys.path.append(os.path.realpath('../../v2/parking'))




class ParkingIntegrationTests(unittest.TestCase):
    def setUp(self):
        self.testbed = testbed.Testbed()
        self.testbed.activate()

        # declare the service stubs
        self.testbed.init_urlfetch_stub()
        self.testbed.init_memcache_stub()


# Path: api/v2/parking/parking.py
# class ParkingHandler(webapp.RequestHandler):
#     def post(self):
#         self.response.headers['Content-Type'] = 'application/javascript'
#         self.response.headers['Allow'] = 'GET'
#         self.response.status = 405  # method not allowed
#         self.response.out.write(
#             json.dumps(
#                 api_utils.buildErrorResponse('-1', 'The API does not support POST requests')
#             )
#         )
# 
#     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)


# Path: api/v2/tests/test_integ_parking.py
import sys
import os
import webapp2
import webtest
import unittest
import datetime
from google.appengine.ext import testbed
from api.v2.parking.parking import ParkingHandler



# set up relative paths to app dependencies
sys.path.append(os.path.realpath('../../../'))
sys.path.append(os.path.realpath('../../'))
sys.path.append(os.path.realpath('../../v2'))
sys.path.append(os.path.realpath('../../v2/parking'))




class ParkingIntegrationTests(unittest.TestCase):
    def setUp(self):
        self.testbed = testbed.Testbed()
        self.testbed.activate()

        # declare the service stubs
        self.testbed.init_urlfetch_stub()
        self.testbed.init_memcache_stub()


        app = webapp2.WSGIApplication([('/parking/v2/lots', ParkingHandler)])