示例#1
0
 def format_res_data(self, reservation):
     res_data = {
         'start_time' : to_isostring(reservation.start_time),
         'end_time' : to_isostring(reservation.end_time),
         'vehicle' : {
             'id' : reservation.vehicle.id,
         }
     }
     
     if hasattr(reservation, 'liveid'):
         res_data['liveid'] = reservation.liveid
     if hasattr(reservation, 'logid'):
         res_data['logid'] = reservation.logid
     if hasattr(reservation.vehicle, 'model'):
         res_data['vehicle']['model'] = {
                 'name' : reservation.vehicle.model.name
             }
     if hasattr(reservation.vehicle, 'pod'):
         res_data['vehicle']['pod'] = {
                 'id' : reservation.vehicle.pod.id,
                 'name' : reservation.vehicle.pod.name
             }
     if hasattr(reservation, 'price'):
         res_data['price'] = {
                 'total_amount' : reservation.price.total_amount
             }
     if hasattr(reservation, 'memo'):
         res_data['memo'] = reservation.memo
     
     return res_data
示例#2
0
 def _clean_fetched_data(self, json_data, **defaults):
     allowed_error_codes = ('no_change_requested',)
     
     if self._is_error(json_data):
         if json_data['error']['code'] in allowed_error_codes:
             json_data = {'confirmation' : {
                 'reservation' : {
                     'start_time' : to_isostring(defaults['start_time']),
                     'end_time' : to_isostring(defaults['end_time']),
                     'liveid' : defaults['liveid'] }
             }}
         
         # All other errors should just be sent to the default handler.
         else:
             return json_data
     
     conf = json_data['confirmation']
     
     # convert all iso to datetime
     res_start = conf['reservation']['start_time']
     res_end   = conf['reservation']['end_time']
     conf['reservation']['start_time'] = from_isostring(res_start)
     conf['reservation']['end_time']   = from_isostring(res_end)
     
     return json_data
示例#3
0
 def _build_chooser_queries(self, reservation_json, status):
     res = reservation_json['reservation']
     
     cur_start = to_isostring(res['start_time'])
     cur_end = to_isostring(res['end_time'])
     old_start = to_isostring(res['old_start_time'])
     old_end = to_isostring(res['old_end_time'])
     
     queries = {}
     queries['choose_start_time_query'] = \
         self._construct_chooser_query('start_time',
             cur_start,
             { 'reservation' : res['liveid'],
               'vehicle' : res['vehicle']['id'],
               'vehicle_model' : res['vehicle']['model']['name'],
               'vehicle_pod' : res['vehicle']['pod']['name'],
               'memo' : res['memo'],
               'end_time' : cur_end,
               'status' : status,
               'old_start_time' : old_start,
               'old_end_time' : old_end })
     
     queries['choose_end_time_query'] = \
         self._construct_chooser_query('end_time',
             cur_end,
             { 'reservation' : res['liveid'],
               'start_time' : cur_start,
               'vehicle' : res['vehicle']['id'],
               'vehicle_model' : res['vehicle']['model']['name'],
               'vehicle_pod' : res['vehicle']['pod']['name'],
               'memo' : res['memo'],
               'status' : status,
               'old_start_time' : old_start,
               'old_end_time' : old_end })
     
     return queries
示例#4
0
 def testMakeChangeAndCancelAReservation(self):
     
     # This is a long test that will exercise the whole process of making,
     # checking, editing, and canceling a reservation.  It really is a long
     # test (on the order of 30 seconds), so make sure you're all unit-tested
     # up before running it; don't expect to make it a part of your regular
     # tests.
     
     session_cookie = self.sign_in_and_get_session_cookie()
     
     #######################################################################
     # First, make a reservation
     from pcs.wsgi_handlers.reservations import ReservationsJsonHandler
     handler = ReservationsJsonHandler()
     self.initialize_handler_for_session(handler, session_cookie)
     
     vehicleid = '96692246' # A Prius at 47th & Baltimore
     
     now = current_time()
     three_days = datetime.timedelta(days=3)
     later = now + three_days
     
     start_time = later.replace(hour=3, minute=00)
     end_time = later.replace(hour=3, minute=15)
     
     handler.request['vehicle'] = vehicleid
     handler.request['start_time'] = to_isostring(start_time)
     handler.request['end_time'] = to_isostring(end_time)
     handler.request['memo'] = 'reservation create test'
     
     handler.post()
     
     response_body = handler.response.out.getvalue()
     
     # I should get a confirmation
     response = json.loads(response_body)
     self.check_for_error(response)
     
     confirmation = response.get('confirmation', None)
     self.assert_(confirmation is not None)
     self.assertEqual(confirmation['reservation']['vehicle']['id'], vehicleid)
     
     liveid = confirmation['reservation'].get('liveid', None)
     self.assert_(liveid is not None, response_body)
     
     #######################################################################
     # Now, use the liveid from above to change the reservation
     from pcs.wsgi_handlers.reservations import ReservationJsonHandler
     handler = ReservationJsonHandler()
     self.initialize_handler_for_session(handler, session_cookie)
     
     start_time = later.replace(hour=3, minute=45)
     end_time = later.replace(hour=4, minute=00)
     
     handler.request['action'] = 'edit'
     handler.request['vehicle'] = vehicleid
     handler.request['start_time'] = to_isostring(start_time)
     handler.request['end_time'] = to_isostring(end_time)
     handler.request['memo'] = 'reservation modify test'
     
     handler.put(liveid)
     
     response_body = handler.response.out.getvalue()
     
     # I should get a confirmation
     response = json.loads(response_body)
     self.check_for_error(response)
     
     confirmation = response.get('confirmation', None)
     self.assert_(confirmation is not None)
     self.assertEqual(confirmation['reservation']['liveid'], liveid)
     self.assertEqual(confirmation['reservation']['vehicle']['id'], vehicleid)
     
     #######################################################################
     # Get the reservation information, using the same liveid
     from pcs.wsgi_handlers.reservations import ReservationJsonHandler
     handler = ReservationJsonHandler()
     self.initialize_handler_for_session(handler, session_cookie)
     
     handler.get(liveid)
     
     response_body = handler.response.out.getvalue()
     
     # I should get a reservation consistent with the one I just modified
     response = json.loads(response_body)
     self.check_for_error(response)
     
     reservation = response.get('reservation', None)
     self.assert_(reservation is not None)
     self.assertEqual(reservation['liveid'], liveid)
     self.assertEqual(reservation['vehicle']['id'], vehicleid)
     self.assertEqual(reservation['start_time'], to_isostring(start_time)[:16])
     self.assertEqual(reservation['end_time'], to_isostring(end_time)[:16])
     self.assertEqual(reservation['vehicle']['model']['name'], 'Prius Liftback')
     self.assertEqual(reservation['vehicle']['pod']['name'], '47th & Baltimore')
     self.assertEqual(reservation['vehicle']['pod']['id'], '30005')
     self.assertEqual(reservation['memo'], 'reservation modify test')
     
     #######################################################################
     # Now cancel the reservation
     handler = ReservationJsonHandler()
     self.initialize_handler_for_session(handler, session_cookie)
     
     handler.request['vehicle'] = vehicleid
     handler.request['start_time'] = to_isostring(start_time)
     handler.request['end_time'] = to_isostring(end_time)
     
     handler.delete(liveid)
     
     response_body = handler.response.out.getvalue()
     
     # I should get a confirmation
     response = json.loads(response_body)
     self.check_for_error(response)
     
     confirmation = response.get('confirmation', None)
     self.assert_(confirmation is not None)
     self.assertEqual(confirmation['reservation']['liveid'], liveid)
     self.assertEqual(confirmation['reservation']['vehicle']['id'], vehicleid)