def update_vehicle(self, id, model, quantity, price, manufacture_year,
                       manufacture_month, manufacture_date):
        update_msg = {
            "data_type": "vehicle",
            "action": "update",
            "port": self.my_port,
            "id": id
        }
        if model is not None:
            update_msg["model"] = model

        if quantity is not None:
            update_msg["quantity"] = quantity

        if price is not None:
            update_msg["price"] = price

        if manufacture_year is not None:
            update_msg["manufacture_year"] = manufacture_year

        if manufacture_month is not None:
            update_msg["manufacture_month"] = manufacture_month

        if manufacture_date is not None:
            update_msg["manufacture_date"] = manufacture_date

        if self.engineers is not None:
            update_msg["engineers"] = self.engineers

        print(f"Asking server to update vehicle: {update_msg}")
        send_message("localhost", self.server_port, update_msg)
 def delete_vehicle(self, model):
     del_msg = {
         "data_type": "vehicle",
         "action": "delete",
         "port": self.my_port,
         "model": model
     }
     print(f"Asking server to delete vehicle: {del_msg}")
     send_message("localhost", self.server_port, del_msg)
 def read_assigned_engineers(self, model):
     read_msg = {
         "data_type": "vehicle_engineers",
         "action": "read",
         "port": self.my_port,
         "model": model
     }
     print(
         f"Asking server to read assigned engineers for model {model} vehicles"
     )
     send_message("localhost", self.server_port, read_msg)
Esempio n. 4
0
 def add_engineer(self, name, birth_year, birth_month, birth_date):
     add_msg = {
         "data_type": "engineer",
         "action": "add",
         "port": self.my_port,
         "name": name,
         "birth_year": birth_year,
         "birth_month": birth_month,
         "birth_date": birth_date
     }
     print(f"Asking server to add engineer: {add_msg}")
     send_message("localhost", self.server_port, add_msg)
 def add_new_vehicle(self, model, quantity, price, manufacture_year,
                     manufacture_month, manufacture_date):
     add_msg = {
         "data_type": "vehicle",
         "action": "add",
         "port": self.my_port,
         "model": model,
         "quantity": quantity,
         "price": price,
         "manufacture_year": manufacture_year,
         "manufacture_month": manufacture_month,
         "manufacture_date": manufacture_date
     }
     print(f"Asking server to add vehicle: {add_msg}")
     send_message("localhost", self.server_port, add_msg)
    def test_invalid_messages(self, data_type, action, entry_list):
        curr_test_input = "Input for current test:\n" + \
                          f"Data Type: {data_type}\n" + \
                          f"Action: {action}\n" + \
                          f"Entries: {entry_list}\n"
        slash.logger.error(curr_test_input)

        msg = {
            "data_type": data_type,
            "action": action,
            "port": self.my_port,
        }
        for entry in entry_list:
            msg[entry] = None

        send_message("localhost", self.server_port, msg)

        server_response = self.get_server_response()
        assert server_response

        status = self.check_server_status(server_response)
        assert not status  # Expect to error-out with invalid messages
    def test_delete_valid_vehicle(self, model):
        curr_test_input = "Input for current test:\n" + \
                          f"Model: {model}\n"
        slash.logger.error(curr_test_input)

        del_msg = {
            "data_type": "vehicle",
            "action": "delete",
            "port": self.my_port,
            "model": model
        }
        print(f"Asking server to delete vehicle: {del_msg}")
        send_message("localhost", self.server_port, del_msg)

        server_response = self.get_server_response()
        assert server_response

        status = self.check_server_status(server_response)

        assert status

        # Ensure that a read for this vehicle is null
        read_msg = {
            "data_type": "vehicle",
            "action": "read",
            "port": self.my_port,
            "model": model
        }

        send_message("localhost", self.server_port, read_msg)

        read_response = self.get_server_response()
        assert server_response

        read_status = self.check_server_status(read_response)
        assert not read_status  # expect the read request to error out since we just deleted the vehicle
Esempio n. 8
0
    def test_add_valid_engineer(self, name, birth_year, birth_month,
                                birth_date):
        curr_test_input = "Current test input:\n" + \
                          f"Name: {name}\n" + \
                          f"Birth Year: {birth_year}\n" + \
                          f"Birth Month: {birth_month}\n" + \
                          f"Birth Date: {birth_date}\n" + \
                          f"Vehicles: {self.vehicles}\n"
        slash.logger.error(curr_test_input)

        self.add_engineer(name, birth_year, birth_month, birth_date)

        server_response = self.get_server_response()
        assert server_response

        status = self.check_server_status(server_response)
        assert status

        missing_entry_msg = "Server response marked as success, but is missing an entry for engineer \"{}\""
        try:
            new_name = server_response["name"]
        except:
            slash.logger.error(missing_entry_msg.format("name"))
            assert False
        assert new_name == name

        try:
            new_year = server_response["birth_year"]
        except:
            slash.logger.error(missing_entry_msg.format("birth_year"))
            assert False
        assert new_year == birth_year

        try:
            new_month = server_response["birth_month"]
        except:
            slash.logger.error(missing_entry_msg.format("birth_month"))
            assert False
        assert new_month == birth_month

        try:
            new_date = server_response["birth_date"]
        except:
            slash.logger.error(missing_entry_msg.format("birth_date"))
            assert False
        assert new_date == birth_date

        try:
            new_server_port = server_response["port"]
        except:
            slash.logger.error(missing_entry_msg.format("port"))
            assert False

        assign_vehicles_msg = {"response": "y", "vehicles": self.vehicles}

        if self.vehicles is None:
            assign_vehicles_msg["response"] = "n"

        send_message("localhost", new_server_port, assign_vehicles_msg)
        print(f"Asking server to assign vehicles: {assign_vehicles_msg}")

        if self.vehicles is not None:
            vehicle_assign_response = self.get_server_response()
            assert vehicle_assign_response

            vehicle_assign_status = self.check_server_status(
                vehicle_assign_response)
            assert vehicle_assign_status

            try:
                assigned = vehicle_assign_response["assigned"]
            except:
                slash.logger.error(
                    "Server assign vehicle response did not include an entry for \"assigned\" vehicles"
                )
                assert False

            try:
                unassigned = vehicle_assign_response["unassigned"]
            except:
                slash.logger.error(
                    "Server assign vehicle response did not include an entry for \"unassigned\" vehicles"
                )
                assert False

            for model in assigned:
                assert model in self.default_vehicle_models

            for model in unassigned:
                assert model not in self.default_vehicle_models
 def request_db_reset(self):
     msg = {"action": "reset"}
     send_message("localhost", self.server_port, msg)
    def test_add_valid_vehicle(self, model, quantity, price, manufacture_year,
                               manufacture_month, manufacture_date):
        curr_test_input = "Input for current test:\n" + \
                          f"Model: {model}\n" + \
                          f"Quantity: {quantity}\n" + \
                          f"Price: {price}\n" + \
                          f"Manufacture Year: {manufacture_year}\n" + \
                          f"Manufacture Month: {manufacture_month}\n" + \
                          f"Manufacture Date: {manufacture_date}\n" + \
                          f"Engineers: {self.engineers}"
        slash.logger.error(curr_test_input)
        self.add_new_vehicle(model, quantity, price, manufacture_year,
                             manufacture_month, manufacture_date)

        server_response = self.get_server_response()
        assert server_response

        status = self.check_server_status(server_response)

        assert status

        if model in self.default_vehicle_models:
            print("model is already in the database")
            assert status == "updated"

        else:
            assign_engins_msg = {"response": "y", "engineers": self.engineers}

            if self.engineers is None:
                assign_engins_msg["response"] = "n"

            try:
                new_server_port = server_response["port"]
            except:
                print("No port entry")
                slash.logger.error(
                    "Server vehicle add response did not inclue an entry \"port\" to let us know where to send assign engineer response"
                )
                assert False

            missing_response_msg = "Server vehicle add response marked success but did not include an entry for \"{entry_name}\""
            try:
                server_model = server_response["model"]
                assert server_model == model
            except:
                slash.logger.error(missing_response_msg.format("model"))
                assert False

            try:
                server_quantity = server_response["quantity"]
                assert server_quantity == quantity
            except:
                slash.logger.error(missing_response_msg.format("quantity"))
                assert False

            try:
                server_price = server_response["price"]
                assert server_price == price
            except:
                slash.logger.error(missing_response_msg.format("price"))
                assert False

            try:
                server_manufacture_year = server_response["manufacture_year"]
                assert server_manufacture_year == manufacture_year
            except:
                slash.logger.error(
                    missing_response_msg.format("manufacture_year"))
                assert False

            try:
                server_manufacture_month = server_response["manufacture_month"]
                assert server_manufacture_month == manufacture_month
            except:
                slash.logger.error(
                    missing_response_msg.format("manufacture_month"))
                assert False

            try:
                server_manufacture_date = server_response["manufacture_date"]
                assert server_manufacture_date == manufacture_date
            except:
                slash.logger.error(
                    missing_response_msg.format("manufacture_date"))
                assert False

            print(
                f"Sending engineer assignment message to server: {assign_engins_msg}"
            )
            refused = True
            timeout_counter = 0
            timeout_max = 20
            while refused:
                if timeout_counter > timeout_max:
                    slash.logger.error(
                        f"Server timed out too many times when trying to send assign engineers message to new port {new_server_port}"
                    )
                    assert False
                try:
                    send_message("localhost", new_server_port,
                                 assign_engins_msg)
                    refused = False
                except:
                    timeout_counter += 1
                    continue

            if self.engineers is not None:
                server_response = self.get_server_response()
                status = self.check_server_status(server_response)
                assert status
                try:
                    assigned = server_response["assigned"]
                except:
                    slash.logger.error(
                        "Server engineer assignment response did not include an entry \"assigned\" for successfully assigned engineers."
                    )
                    assert False

                try:
                    unassigned = server_response["unassigned"]
                except:
                    slash.logger.error(
                        "Server engineer assignment response did not include an entry \"unassigned\" for unsuccessfully assigned engineers."
                    )
                    assert False

                for name in assigned:
                    assert name in self.default_engineer_names

                for name in unassigned:
                    assert name not in self.default_engineer_names