def test_get_avl_cabs_fail(self, inputs): session = MockSession() session.query('').filter('')._all = self.dummy_routes_data inputs.side_effect = ['A', 'E', 8] test_class = Register() allow(test_class).show_avl_cabs.return_value(True) assert test_class.get_avl_cab(self.emp_id, session) is False
def test_show_avl_cabs_fail(self, inputs): session = MockSession() inputs.side_effect = ['AP-31-K-1899'] test_class = Register() allow(test_class).book_cab.return_value(True) assert test_class.show_avl_cabs( self.emp_id, self.dummy_avl_source_cabs, None, self.source, self.destination, session) is False
def test_book_cabs_fails(self): session = MockSession() session.query('').filter('')._first = self.dummy_source_route session.query('').filter('').update('') session.add('') session.commit() test_class = Register() allow(test_class).show_avl_cabs.return_value(True) assert test_class.book_cab(self.emp_id, self.cab_num, None, self.source, self.destination, session) is False
def add_routes(self, sess): """ Function to add routes. """ try: print("Add routes for the cab") Register().list_of_cabs() cab_number = input(Input.cab_number.value) no_of_Stops = int(input(Input.stops.value)) route_id = str(uuid.uuid4()) i = 0 while i != no_of_Stops: y = 0 stop_name = input(Input.stop_name.value) stage = int(input(Input.number_of_stops.value)) timing = input(Input.time_input.value) available_seat = session.query(cab).filter( cab.cab_number == cab_number).all() for row in available_seat: y = row.capacity route_of_car = routes(cab_number=cab_number, route_id=route_id, stop_name=stop_name, stage=stage, time=timing, available_seats=y, is_deleted="false") session.add(route_of_car) i += 1 session.commit() print(Input.routes_added.value) return True except exc.SQLAlchemyError as e: print("Error while adding routes : {}".format(e)) return False
def cab_booking(self): """ Cab booking functionality. """ if Register().get_avl_cab(self.emp_id, session): return True return False
def create_employee(self): """ Function to create employee. """ if Register().newUser("employee"): return True return False
def view_ride(self): """ Function to view rides. """ if Register().view_rides(self.emp_id): return True return False
def test_cancel_ride_success(self, view_bookings, time_diff, inputs, cancel_booking): view_bookings.return_value = self.dummy_upcoming time_diff.return_value = True inputs.return_value = 'test' cancel_booking.return_value = True assert Register().cancel_ride(self.emp_id) is True
def cancel_ride(self): """ Function to cancel ride. """ if Register().cancel_ride(self.emp_id): return True return False
def delete_routes(self): """ Function to delete the routes. """ try: Register().list_of_routes() route_id = input(Input.route_id.value) session.query(routes).filter(routes.route_id == route_id).update( {'is_deleted': True}) session.commit() print("Route is deleted") return True except exc.SQLAlchemyError as e: print("Error while deleting routes : {}".format(e)) return False
def delete_employee(self, sess): """ Function to delete the employee. """ try: print("Delete employee") Register().list_of_employee() username = input(Input.delete_username.value) session.query(User).filter(User.username == username).update( {'is_deleted': True}) session.commit() print(Input.employee_deleted.value) print(username) return True except exc.SQLAlchemyError as e: print("Error while deleting employee : {}".format(e)) return False
def update_employee(self, sess): """ Function to update the employee details. """ try: print("Update employee") Register().list_of_employee() username = input(Input.update_username.value) print(username) passwrd = input(Input.update_password.value) session.query(User).filter(User.username == username).update( {'password': passwrd}) session.commit() print(Input.password_updated.value) return True except exc.SQLAlchemyError as e: print("Error updating employee : {}".format(e)) return False
def employee_bookings(self, sess): """ Function to check the bookings of a particular employee. """ try: print("Bookings of a particular employee") Register().list_of_employee() emp_id = input(Input.emp_id.value) bookings = session.query(booking).filter( booking.emp_id == emp_id).all() df = pd.DataFrame(bookings) print(df) session.commit() return True except exc.SQLAlchemyError as e: print("Error with list : {}".format(e)) return False
def test_view_rides_success(self, upcoming, completed): assert Register().view_rides(self.emp_id) is True
def test_list_of_employee_success(self): session = MockSession() session.query('').filter('').all() assert Register().list_of_employee() is True
def test_newUser_success(self, inputs, encrypt_message): inputs.side_effect = ['test', 'test', 'test'] encrypt_message.return_value = 'test' session = MockSession() session.add('') assert Register().newUser('employee') is True
def test_view_bookings(self): sess = MockSession() sess.query('').filter('')._all = self.dummy_completed assert Register().view_bookings('123', sess) is self.dummy_completed
def test_cancel_booking(self): session = MockSession() session.query('').filter('').update('') assert Register().cancel_booking('test', session) is True
def test_ride_status_true(self): assert Register().ride_status('20:00') is True
def test_time_diff_true(self): assert Register().time_diff('20:00') is True
def test_cancel_ride_failure(self, view_bookings, time_diff): view_bookings.return_value = self.dummy_upcoming time_diff.return_value = False assert Register().cancel_ride(self.emp_id) is False
def test_upcoming_rides_success(self, ride_status, view_bookings): ride_status.return_value = True view_bookings.return_value = self.dummy_upcoming assert Register().upcoming_rides(self.emp_id) is True
def test_completed_rides_works(self, ride_status, view_bookings): ride_status.return_value = True view_bookings.return_value = self.dummy_completed assert Register().completed_rides('123') is True