예제 #1
0
    def setUp(self):
        self.propulsion_key = SettingsKeys.PROPULSION
        self.udp_key = SettingsKeys.UDP

        # key, data
        self.propulsion_serial_port = (SettingsSerialEntity.PORT, "/dev/ttyUSB0")
        self.propulsion_serial_baudrate = (SettingsSerialEntity.BAUDRATE, 115200)
        self.propulsion_serial_channel = (SettingsSerialEntity.CHANNEL, "propulsion")

        self.udp_server_ip = (SettingsUDPEntity.IP, "127.0.0.1")
        self.udp_server_port = (SettingsUDPEntity.PORT, 5000)
        self.udp_server_channel = (SettingsUDPEntity.CHANNEL, "UDPServer")

        #compare
        self.propulsion_dict = {}
        add_to_dict(self.propulsion_dict, *self.propulsion_serial_port)
        add_to_dict(self.propulsion_dict, *self.propulsion_serial_baudrate)
        add_to_dict(self.propulsion_dict, *self.propulsion_serial_channel)

        self.udp_dict = {}
        add_to_dict(self.udp_dict, *self.udp_server_ip)
        add_to_dict(self.udp_dict, *self.udp_server_port)
        add_to_dict(self.udp_dict, *self.udp_server_channel)

        #serial and udp entities
        self.propulsion_entity = SettingsSerialEntity(key=self.propulsion_key)
        self.udp_entity = SettingsUDPEntity(key=self.udp_key)
예제 #2
0
    def setUp(self):
        self.propulsion_settings = SettingsSerialEntity(
            SettingsKeys.PROPULSION)
        self.manipulator_settings = SettingsSerialEntity(
            SettingsKeys.MANIPULATOR)
        self.udp_settings = SettingsUDPEntity(SettingsKeys.UDP)
        self.settings_list = [
            self.propulsion_settings, self.manipulator_settings,
            self.udp_settings
        ]

        self.mock_settings_manager = SettingsManagerMock(
            "test_settings.json", self.settings_list)
        self.mock_settings_manager.save()
        self.mock_settings_manager.load()
        self.json_str_test = self.mock_settings_manager.json_string
        self.json_dict_test = json.loads(self.json_str_test)

        self.loader_params = {
            SettingsKeys.PROPULSION: SettingsSerialEntity,
            SettingsKeys.MANIPULATOR: SettingsSerialEntity,
            SettingsKeys.UDP: SettingsUDPEntity,
            SettingsKeys.CONTAINERS: SettingsSerialEntity
        }
        self.loader = SettingsLoader("test_settings.json", self.loader_params)
        self.loader._file_exists = MagicMock(return_value=True)
        self.loader._open_file_get_json_dict = MagicMock(
            return_value=self.json_dict_test)
예제 #3
0
class TestSettingsManager(unittest.TestCase):
    def setUp(self):
        self.propulsion_key = SettingsKeys.PROPULSION
        self.udp_key = SettingsKeys.UDP

        # key, data
        self.propulsion_serial_port = (SettingsSerialEntity.PORT, "/dev/ttyUSB0")
        self.propulsion_serial_baudrate = (SettingsSerialEntity.BAUDRATE, 115200)
        self.propulsion_serial_channel = (SettingsSerialEntity.CHANNEL, "propulsion")

        self.udp_server_ip = (SettingsUDPEntity.IP, "127.0.0.1")
        self.udp_server_port = (SettingsUDPEntity.PORT, 5000)
        self.udp_server_channel = (SettingsUDPEntity.CHANNEL, "UDPServer")

        #compare
        self.propulsion_dict = {}
        add_to_dict(self.propulsion_dict, *self.propulsion_serial_port)
        add_to_dict(self.propulsion_dict, *self.propulsion_serial_baudrate)
        add_to_dict(self.propulsion_dict, *self.propulsion_serial_channel)

        self.udp_dict = {}
        add_to_dict(self.udp_dict, *self.udp_server_ip)
        add_to_dict(self.udp_dict, *self.udp_server_port)
        add_to_dict(self.udp_dict, *self.udp_server_channel)

        #serial and udp entities
        self.propulsion_entity = SettingsSerialEntity(key=self.propulsion_key)
        self.udp_entity = SettingsUDPEntity(key=self.udp_key)

    def test_load_default_settings(self):
        manager = SettingsManagerMock("settings.json")
        manager.add_entity(self.propulsion_entity)
        manager.load()
        data = self.propulsion_entity.get_settings_entity_dict()
        self.assertDictEqual(self.propulsion_entity.default_settings,
                             data[SettingsKeys.PROPULSION])

    def test_save_default_settings(self):
        manager = SettingsManagerMock("settings.json")
        manager.add_entity(self.propulsion_entity)
        manager.add_entity(self.udp_entity)
        manager.save()
        self.assertTrue(manager.json_string)

    def test_settings_manager(self):
        manager = SettingsManager("test_settings.json")
        manager.add_entity(self.propulsion_entity)
        manager.add_entity(self.udp_entity)
        manager.save()
        manager.load()
        self.assertTrue((self.udp_entity.get_settings_entity_dict() and
                        self.propulsion_entity.get_settings_entity_dict()))

    def test_getting_propulsion_from_entities_list(self):
        entities = [self.udp_entity, self.propulsion_entity]
        entity = get_settings_entity_from_list(entities, SettingsKeys.PROPULSION)
        self.assertEqual(self.propulsion_entity, entity)
예제 #4
0
    def __init__(self):
        super(Main, self).__init__()
        self.propulsion_settings = SettingsSerialEntity(
            SettingsKeys.PROPULSION)
        self.manipulator_settings = SettingsSerialEntity(
            SettingsKeys.MANIPULATOR)
        self.containers_settings = SettingsSerialEntity(
            SettingsKeys.CONTAINERS)

        self.udp_settings = SettingsUDPEntity(SettingsKeys.UDP)
        self.tcp_updater_settings = SettingsUpdaterTCPServer(
            SettingsKeys.TCP_UPDATER_SERVER)
        self.updater_settings = SettingsUpdaterEntity(SettingsKeys.UPDATER)
        self.settings_entities = [
            self.propulsion_settings, self.manipulator_settings,
            self.udp_settings, self.tcp_updater_settings,
            self.updater_settings, self.containers_settings
        ]

        self.settings_manager = SettingsManager("settings.json")
        self.settings_manager.add_entity(self.settings_entities)
        self.settings_manager.load()

        device_wholesaler = DeviceWholesale(self, [
            self.propulsion_settings, self.manipulator_settings,
            self.containers_settings
        ])

        self.devices = device_wholesaler.sell_all()
        self.controller = DispatchController(self.devices)
        self.server = UDPReceiver.UDPReceiver(
            controller=self.controller,
            udp_sett_entity=self.udp_settings).register(self)
        self.tcp_updater = UpdaterTCPServer(
            self.tcp_updater_settings).register(self)

        self._register_udp_server_as_observer_to_devices()
예제 #5
0
 def test_get_udp_existing_entry(self):
     udp_entity = SettingsUDPEntity(key=self.udp_key)
     udp_entity.add_entry(*self.udp_server_ip)
     self.assertEqual(self.udp_dict[SettingsUDPEntity.IP],
                      udp_entity.get_entry(SettingsUDPEntity.IP))
예제 #6
0
 def test_create_udp_entity_and_check_correctness(self):
     udp_entity = SettingsUDPEntity(key=self.udp_key)
     udp_entity.add_entry(*self.udp_server_ip)
     udp_entity.add_entry(*self.udp_server_port)
     udp_entity.add_entry(*self.udp_server_channel)
     self.assertDictEqual(self.udp_dict, udp_entity.settings)
예제 #7
0
 def test_get_udp_non_existing_entry(self):
     udp_entity = SettingsUDPEntity(key=self.udp_key)
     self.assertTrue(udp_entity.get_entry(SettingsUDPEntity.IP))
예제 #8
0
 def create_udp_server_settings_entity(self):
     udp_server = SettingsUDPEntity(key=self.udp_key)
     udp_server.add_entries(self.udp_dict)
     return udp_server