Exemplo n.º 1
0
 def test_get_success(self):
     trip = TripModel('Dash', [])
     trip.db_save()
     result = self.app.get('/trip/1')
     self.assertEqual(result.status_code, status.HTTP_200_OK)
     json_response = jsonify_response(result)
     self.assertEqual(json_response['id'], 1)
     self.assertEqual(json_response['dog'], 'Dash')
Exemplo n.º 2
0
    def post(self, date, cost):
        trip = TripModel.find_by_date_created(date=date)
        if not trip:
            trip = TripModel(0)
            try:
                trip.save_to_db()
            except:
                return {
                    'message': 'An error occurred while creating the trip'
                }, 500
        else:
            try:
                trip.mark_done(cost)
            except:
                return {
                    'message': 'An error occurred while completing the trip'
                }, 500

        return trip.json(), 201
Exemplo n.º 3
0
 def get(self, trip_id):
     trip = TripModel.find_by_id(trip_id=trip_id)
     if trip:
         return trip.json()
     return {'message': 'Trip not found for the specified date'}, 404
Exemplo n.º 4
0
 def get(self, trip_id):
     return TripModel.find_by_id(trip_id).json()
Exemplo n.º 5
0
 def get(self):
     trips = [trip.json() for trip in TripModel.all_trips()]
     return trips
Exemplo n.º 6
0
 def get(self):
     claims = get_jwt_claims()
     trips = [trip.json() for trip in TripModel.find_my_trips(claims)]
     return {'trips':trips}
Exemplo n.º 7
0
 def get(self,name):
     trips = [trip.json() for trip in TripModel.find_by_location(name)]
     if trips:
         return trips
     return {'message':'No trip found on this location'}
Exemplo n.º 8
0
 def post(self,name):
     claims = get_jwt_claims()
     data = Trip._trip_parser.parse_args()
     trip = TripModel(name,data['price'],data['days'],claims)
     trip.save_to_db()
     return {'trip': trip.json(),'message':'trip has been added to database'}
Exemplo n.º 9
0
 def test_constructor(self):
     trip = TripModel('Dash', [])
     self.assertEqual(trip.dog, 'Dash')
     self.assertEqual(trip.legs, [])
Exemplo n.º 10
0
 def test_json(self):
     trip = TripModel('Dash', [])
     json = trip.json()
     self.assertEqual(json['dog'], 'Dash')
Exemplo n.º 11
0
 def test_find_by_id(self):
     trip = TripModel('Dash', [])
     trip.db_save()
     trip2 = TripModel.find_by_id(trip.id)
     self.assertEqual(trip.id, trip2.id)
     self.assertEqual(trip.dog, trip2.dog)
Exemplo n.º 12
0
 def test_db_save(self):
     trip = TripModel('Dash', [])
     trip.db_save()
     self.assertEqual(trip.id, 1)