Example #1
0
    def test_register_ride(self):
        ''' '''

        params = Parameters(args=['Odense', 'Copenhagen', '2018-10-01', '4'])
        params.parse()
        self.assertEqual(register_ride(params=params), None)

        logging.info('Test passed for: register_ride')
Example #2
0
    def test_register_return_trip(self):
        ''' '''

        params = Parameters(args=['2018-10-01'])
        params.parse()
        self.assertEqual(register_return_trip(params=params), None)

        logging.info('Test passed for: register_return_trip')
Example #3
0
def handle_request(req: str):
    ''' Handles user requests.'''

    cmd_list = req.split(' ')

    cmd = cmd_list[0] # Get the cmd indicator, [S, C, R].

    cmd_list.pop(0) # Remove cmd indicator.

    args = cmd_list[:] # Make a new list, to reset indexing.

    params = Parameters(args=args)
    params.parse()

    # Create ride.
    if cmd in CMDs.create_ride:
        
        try:
            register_ride(params=params)

        except Exception as e:
            logging.error(
                f'Registering trip failed: {e}'
            )

    # Retrieve ride(s).
    elif cmd in CMDs.retrieve_ride:

        try:
            res = retrieve_rides(params=params)
            print_out(txt=res)
            
        except Exception as e:
            logging.error(
                f'Retreiving data failed: {e}'
            )

    # Create return ride.
    elif cmd in CMDs.create_return_ride:

        try:
            register_return_trip(params=params)

        except Exception as e:
            logging.error(
                f'Registering return trip failed: {e}'
            )