def get(self, rideid): ''' class method which allow user retrieve a siingle ride''' ride_by_id = Ride.get_ride(rides, int(rideid)) if ride_by_id: return make_response(jsonify({'ride': ride_by_id})), 200 return make_response( jsonify({'message': 'ride you specified does not exist'})), 404
def test_ride_class(client): distance = 2 start_time = "2020-06-19T13:01:17.031Z" duration = 9000 new_ride = Ride(distance, start_time, duration) assert new_ride.distance == distance assert new_ride.start_time == start_time assert new_ride.duration == duration
def post(self): ''' class method which allows user to sign up''' dest = request.json.get('destination') date = request.json.get('date') time = request.json.get('time') meet_p = request.json.get('meetpoint') charges = request.json.get('charges') if dest and date and time and meet_p and charges: try: date = datetime.strptime(date, '%d-%m-%Y').date() except ValueError: return make_response( jsonify( {'message': 'enter date in the format of dd-mm-YYYY'})), 409 if date < date.today(): return make_response( jsonify({ 'message': 'rides can only be of the present and the future' })), 409 if Ride.does_ride_exist(rides, dest, time): return make_response( jsonify({ 'message': 'you are already offering a ride to this destination on this date' })), 409 id_count = 1 for item in rides: id_count += 1 ride = Ride(dest, date, time, meet_p, charges) ride_dict = Ride.serialize_ride(ride, id_count) rides.append(ride_dict) return make_response( jsonify({ 'message': 'succesfully created ride to {} on {}'.format( ride_dict['destination'], ride_dict['date']) })), 201 return make_response( jsonify( {'message': 'ensure you have provide all required details'})), 400
def delete(self, rideid): '''cancel ride''' ride_by_id = Ride.get_ride(rides, int(rideid)) if ride_by_id: rides.remove(ride_by_id[0]) return make_response( jsonify({'details of cancelled ride': ride_by_id[0]})), 200 return make_response( jsonify({ 'message': 'the ride you are trying to cancel does not exist' })), 404
def post(self, rideid): '''method which handles join ride''' ride_by_id = Ride.get_ride(rides, int(rideid)) if not ride_by_id: return make_response( jsonify({ 'message': 'the ride tou are looking for nolonger exists.' })), 404 join_ride = { 'ride_id': rideid, 'phone_contact': '072-111-1111', 'username': '******' } joins_for_a_ride.append(join_ride) return make_response( jsonify({ 'message': 'you have succefully sent a join request, you will receive notification soon' })), 201
def test_get_human_readable_ride_duration(client, duration, expected_readable_duration): distance = 2 start_time = "2020-06-19T13:41:17.031Z" new_ride = Ride(distance, start_time, duration) assert new_ride.get_human_readable_duration() == expected_readable_duration
def test_calculate_ride_cost(client, ride_cost_per_mile, distance, start_time, duration, expected_cost): new_ride = Ride(distance, start_time, duration) assert new_ride.calculate_ride_cost() == expected_cost
def test_is_night_hour(client, start_time, expected_result): new_ride = Ride(1, start_time, 3000) assert new_ride.is_night_hour() == expected_result
def test_get_end_time_ride(client, start_time, duration, expected_end_time): new_ride = Ride(2, start_time, duration) assert new_ride.get_end_time() == expected_end_time