Example #1
0
    def activated(self):
        """
        Function that presents the user interface. It is the 
        primary mechanim for user interactions to be responded to.
        If a user is validated, the appropriate class is instantiated
        and control passed to it.
        Also provides access to engineers via hidden option 9 for 
        access via bluetooth detection.
        """
        while self.running:

            os.system("clear")

            print("Welcome to Car Share System.\n")
            print("You are at Car ID: {car}\n\
            ".format(car=self.currentCar.get_car_id()))
            print("Please choose from the following options:\n \
                1. Unlock vehicle with username and password. \n \
                2. Unlock vehicle with face recognition. \n")
            # 9. Engineer Access (hidden option)
            user_choice = input("Please enter your selection as an integer: ")
            # pass the result to the Validation module that validates the credentials.
            # True is returned if the user was successful, and only after the
            # booking has been completed. False is immediately returned if invalid.
            user_validation = validation.ValidateUser(user_choice,
                                                      self.currentCar)
            isvalid = user_validation.validateCredentials()

            if not isvalid:
                # Invalid choice - pause, clear screen, flush keyboard input.
                print("Invalid Choice!")
                time.sleep(3)
                clear_util = utilities.HelperUtilities()
                clear_util.clear_keyboard()
Example #2
0
def dictionary_class_helper_false() -> agentdata.DictionaryConstructor:
    """
    This helper functions return dictionary class objects for testing purposes
    populated by incorrect values.
    The only elements that does not change from a valid dictionary is the action.
    To build tests that look at each element of the object,
    set the value directly, changing the object by one keyvalue at time via class level
    function calls.

    .. note:: This function returns an instantiation of a custom class - you must call the dictionary
        return function before passing to any socket calls.
    """
    # Set Data to be converted.
    date_to_use = (datetime.datetime.now() -
                   datetime.timedelta(days=365)).isoformat()
    car_name = "fabc123"
    test_data = agentdata.DictionaryConstructor(car_name, date_to_use)
    action = 1
    username = "******"
    password = "******"
    usertoken = "fabc123"
    test_data.set_action(1)
    test_data.set_username(username)
    test_data.set_password(password)
    test_data.set_usertoken(usertoken)
    # Call a location
    helper_utilities = utilities.HelperUtilities()
    location = helper_utilities.get_location()
    test_data.set_current_location(location)
    return test_data
Example #3
0
def dictionary_class_helper_true() -> agentdata.DictionaryConstructor:
    """
    This helper functions return dictionary class objects for testing purposes
    populated by correct values.
    To build tests that look at each element of the object,
    set the value directly, changing the object by one keyvalue at time via class level
    function calls.

    .. note:: This function returns an instantiation of a custom class - you must call the dictionary
        return function before passing to any socket calls.
    """
    # Set Data to be converted.
    date_to_use = datetime.datetime.now().isoformat()
    car_name = "car123"
    test_data = agentdata.DictionaryConstructor(car_name, date_to_use)
    action = 1
    username = "******"
    password = "******"
    usertoken = "5c0be87ed7434d69005f8bbd84cad8ae6abfd49121b4aaeeb4c1f4a2e2987711"
    test_data.set_action(1)
    test_data.set_username(username)
    test_data.set_password(password)
    test_data.set_usertoken(usertoken)
    # Call a location
    helper_utilities = utilities.HelperUtilities()
    location = helper_utilities.get_location()
    test_data.set_current_location(location)
    return test_data
Example #4
0
 def setUp(self):
     """
     Create a location to test on.
     """
     helper_utilities = utilities.HelperUtilities()
     self.location = helper_utilities.get_location()
     print("Test suite: {}".format(type(self).__name__))
Example #5
0
 def setUp(self):
     """
     Set Data to be converted and validated.
     """
     self.date_to_use = datetime.datetime.now()
     self.car_name = "car123"
     self.test_data = agentdata.DictionaryConstructor(
         self.car_name, self.date_to_use)
     self.action = 1
     self.username = "******"
     self.password = "******"
     self.usertoken = "abc123"
     self.test_data.set_action(1)
     self.test_data.set_username(self.username)
     self.test_data.set_password(self.password)
     self.test_data.set_usertoken(self.usertoken)
     # Call a location
     helper_utilities = utilities.HelperUtilities()
     self.location = helper_utilities.get_location()
     self.test_data.set_current_location(self.location)
     print("Test suite: {}".format(type(self).__name__))
    def terminate_booking(self):
        """
        Updating the Master Pi when the booking has been concluded.
        This constitutes Action 4 for communication purposes.
        """

        # Create a dictionary object.
        socket_dictionary_creator = DictionaryConstructor(
            self.car_id, 
            datetime.datetime.now().isoformat()
            )
            # Update with the details for the end of a booking
        socket_dictionary_creator.set_action(4)
        clearutil = utilities.HelperUtilities()
        location = clearutil.get_location()
        socket_dictionary_creator.set_current_location(location)
        #log.info(socket_dictionary)

        # Create a socket object and return the returned dictionary.
        socket_dict_tosend = socket_dictionary_creator.get_socket_dictionary()
        log.info(socket_dict_tosend)
        return self.validation_returner(socket_dict_tosend)
    def terminate_engineer(self, engineer_code: str):
        """
        Updates the master pi when an engineer concludes their
        work. 
        This constitutes Action 6 for communication purposes.
        """

        # Create a dictionary to send
        socket_dictionary_creator = DictionaryConstructor(
            self.car_id,
            datetime.datetime.now().isoformat()
        )
        # Update dictionary with appropriate information.
        socket_dictionary_creator.set_action(6)
        socket_dictionary_creator.set_engineer_code(engineer_code)
        clearutil = utilities.HelperUtilities()
        location = clearutil.get_location()
        socket_dictionary_creator.set_current_location(location)

        # Retrieve the dictionary and send it to the mp.
        socket_dict_tosend = socket_dictionary_creator.get_socket_dictionary()
        log.info("Engineer Code Socket Dict: {}".format(socket_dict_tosend))
        return self.validation_returner(socket_dict_tosend)
Example #8
0
    def unlock_car(self):
        """
        Perform functions for unlocking the car for an engineer.
        Presents a single option which is to conclude
        the work, requring the engineer has a QR code for ID 
        purposes. If the logout attempts fail after a set number of times,
        the car locks for security reasons.
        """

        current_username = self.unlocked_car["username"]
        print("Engineer Access.")
        print("Welcome {}.".format(current_username))

        # Loop exit variables.
        engineer_in_car = True
        logout_attempts = 0
        failed_logouts = 3

        # Loop through the GUI.
        while engineer_in_car:
            # current_username = self.unlocked_car["username"]
            # print("Engineer Access.")
            # print("Welcome {}".format(current_username))
            print("Please select from the following options:\n \
            1. End Maintenance and lock the vehicle.")
            user_choice = input("Enter your choice: ")

            if user_choice == "1":

                # Search for the engineers QR code and
                # if it is of valid type, return the vehicle.
                print("Please present your valid QR ID code.")
                qr_reader = qrreader.QRReader()
                engineer_code = qr_reader.read_qr_code()

                # If the code is returned, pass it to the socket.
                if engineer_code:
                    # TODO how do we update the master if the connection fails?
                    socket_connection = socketconnection.SocketConnection(
                        self.unlocked_car["car_id"])
                    # Pass in the qr code to the socket connection and await a return.
                    car_returned = socket_connection.terminate_engineer(
                        engineer_code)
                    engineer_in_car = False
                    try:
                        extracted_qrcode = extracted_barcode.data.decode(
                            "utf-8")
                        print("Thanks {} with ID {}.".format(
                            current_username, extracted_qrcode[1]))
                    except Exception as e:
                        pass
                    print("You have been logged out.")
                    time.sleep(3)
                elif logout_attempts >= failed_logouts:
                    print(
                        "Exceeded logout attempts - locking vehicle for security purposes."
                    )
                    time.sleep(3)
                    engineer_in_car = False
                else:
                    print("No valid code found.")
                    logout_attempts += 1
                    time.sleep(2)
                # if invalid, inform and loop.
            else:
                print("Invalid Choice!\n")
                time.sleep(3)
                clear_util = utilities.HelperUtilities()
                clear_util.clear_keyboard()
                # os.system("clear")
        return