def test_filter_airline_schedule(self): '''List/Filter Airline Flight Schedule - Valid''' reservation_factory.create_single_flight(airline='WT') response = self.client.get(reverse('airlines-schedule', kwargs={ 'version': 'v1', 'pk': 'WT' }), HTTP_AUTHORIZATION=utils.generate_token( self.super_user)) payload = response.data.get('payload') self.assertTrue(response.data.get('success')) self.assertGreaterEqual(len(payload), 1)
def setUp(self): self.user = user_factory.create_user(email='*****@*****.**', password='******', username='******', first_name='example', last_name='demo') self.user1 = user_factory.create_user(email='*****@*****.**', password='******', username='******', first_name='User', last_name='User1') self.user2 = user_factory.create_user(email='*****@*****.**', password='******', username='******', first_name='User', last_name='User2') self.super_user = user_factory.create_user( email='*****@*****.**', password='******', username='******', first_name='Admin', last_name='User', user_type='super_staff') self.flight = create_single_flight() self.flight1, self.flight2 = create_return_flight() self.return_ticket_reservation = make_reservation_return( user_account=self.user.account, first_flight=self.flight1, return_flight=self.flight2, ) self.single_ticket_reservation = make_reservation_single( user_account=self.user1.account, flight=self.flight, ) self.valid_reservation_data = { 'first_flight': self.flight.id, 'flight_class': Reservation.ECONOMY_CLASS, 'ticket_type': Reservation.ONE_WAY, } self.valid_reservation_data_return = { 'first_flight': self.flight1.id, 'return_flight': self.flight2.id, 'flight_class': Reservation.BUSINESS_CLASS, 'ticket_type': Reservation.RETURN, }
def test_book_single_flight_for_user_when_return_airport_different(self): '''Book Flight for User Account - Invalid :- When Return Flight Lands in different city''' reservation_data = self.valid_reservation_data.copy() return_flight = create_single_flight( flight_number='0192', departure_airport='LOS', arrival_airport='JFK', expected_departure=timezone.now() + timedelta(days=1), expected_arrival=timezone.now() + timedelta(days=1, hours=12) ) reservation_data['return_flight'] = return_flight.id reservation_data['ticket_type'] = Reservation.RETURN response = self.client.post( reverse( 'account-reservations-reservations', kwargs={ 'version': 'v1', 'pk': self.user.account.id } ), data=reservation_data, HTTP_AUTHORIZATION=utils.generate_token(self.user) ) self.assertFalse(response.data.get('success')) self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST) self.assertEqual( response.data.get('errors').get('return_flight')['message'], 'Return Flight must land in same city as first flight.', ) self.assertEqual( response.data.get('errors').get('return_flight')['type'], 'invalid' ) self.assertEqual( response.data.get('errors').get('first_flight')['message'], 'Return Flight must land in same city as first flight.', ) self.assertEqual( response.data.get('errors').get('first_flight')['type'], 'invalid' )
def setUp(self): self.user = user_factory.create_user( email='*****@*****.**', password='******', username='******', first_name='example', last_name='demo' ) self.super_user = user_factory.create_user( email='*****@*****.**', password='******', username='******', first_name='Admin', last_name='User', user_type='super_staff' ) self.flight = create_single_flight() self.valid_reservation_data = { 'first_flight': self.flight.id, 'flight_class': Reservation.BUSINESS_CLASS, 'ticket_type': Reservation.ONE_WAY, }
def test_reservation_reminder(self): '''Reservation Reminder Mail - Multiple Reservations''' flight = reservation_factory.create_single_flight( expected_departure=timezone.now()) reservation_factory.make_reservation_single( user_account=self.user, flight=flight, ) reservation_factory.make_reservation_single( user_account=self.user1, flight=flight, ) command_return = call_command('reservation-reminders') self.assertEqual(len(mail.outbox), 2) self.assertEqual( mail.outbox[0].from_email, 'Flight Booking Reservations <reservartions@{}>'.format( settings.EMAIL_DOMAIN_URL)) self.assertEqual(command_return, 'Done! All Reminder Emails sent.')
def test_make_reservation_when_return_flight_before_first(self): '''Make Reservation For self - Invalid :- When Return Flight Takes off before First Flight Lands''' reservation_data = self.valid_reservation_data.copy() return_flight = create_single_flight( flight_number='0036', departure_airport='LOS', arrival_airport='LHR', expected_arrival=timezone.now() + timedelta(hours=12), expected_departure=timezone.now() + timedelta(hours=6)) reservation_data['return_flight'] = return_flight.id reservation_data['ticket_type'] = Reservation.RETURN response = self.client.post(reverse('reservations-list', kwargs={ 'version': 'v1', }), data=reservation_data, HTTP_AUTHORIZATION=utils.generate_token( self.user)) self.assertFalse(response.data.get('success')) self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST) self.assertEqual( response.data.get('errors').get('return_flight')['message'], 'Return Flight cannot take off before First Flight lands.', ) self.assertEqual( response.data.get('errors').get('return_flight')['type'], 'invalid') self.assertEqual( response.data.get('errors').get('first_flight')['message'], 'Return Flight cannot take off before First Flight lands.', ) self.assertEqual( response.data.get('errors').get('first_flight')['type'], 'invalid')