def setUp(self): HOST, PORT = "localhost", 9999 # Creating Transductor Model and Energy Transductor t_model = TransductorModel() t_model.name = "TR 4020" t_model.transport_protocol = "UDP" t_model.serial_protocol = "Modbus RTU" t_model.register_addresses = [[4, 0], [68, 1]] t_model.save() transductor = EnergyTransductor() transductor.serie_number = "1" transductor.description = "Test" transductor.model = t_model transductor.ip_address = HOST transductor.save() # Setting instance attributes self.t_model = t_model self.transductor = transductor self.modbus_rtu = ModbusRTU(self.transductor) self.udp_protocol = UdpProtocol(serial_protocol=self.modbus_rtu, timeout=0.5, port=9999) # Starting UDP server via thread self.server = SocketServer.UDPServer((HOST, PORT), UDPHandler) self.server_thread = threading.Thread(target=self.server.serve_forever) self.server_thread.start()
def test_should_not_create_transductor_with_same_ip_address(self): t_model = self.t_model transductor = EnergyTransductor() transductor.serie_number = "2" transductor.description = "Test 2" transductor.creation_date = timezone.now() transductor.model = t_model transductor.ip_address = "111.111.111.111" self.assertRaises(IntegrityError, transductor.save)
def test_should_not_create_transductor_with_wrong_ip_address(self): t_model = self.t_model transductor = EnergyTransductor() transductor.serie_number = "1" transductor.description = "Test" transductor.creation_date = timezone.now() transductor.model = t_model transductor.ip_address = "1" self.assertRaises(ValidationError, transductor.full_clean)
def create_energy_transductor(self, serie_number, description, ip_address, t_model): transductor = EnergyTransductor() transductor.serie_number = serie_number transductor.description = description transductor.creation_date = timezone.now() transductor.ip_address = ip_address transductor.model = t_model transductor.save() return transductor
def setUp(self): t_model = TransductorModel() t_model.name = "TR 4020" t_model.internet_protocol = "UDP" t_model.serial_protocol = "Modbus RTU" t_model.register_addresses = [68, 70, 72, 74, 76, 78, 80, 82, 84, 88, 90, 92] t_model.save() transductor = EnergyTransductor() transductor.serie_number = "1" transductor.description = "Test" transductor.creation_date = timezone.now() transductor.model = t_model transductor.ip_address = "111.111.111.111" transductor.save()
def setUp(self): t_model = TransductorModel() t_model.name = "TR 4020" t_model.transport_protocol = "UDP" t_model.serial_protocol = "Modbus RTU" t_model.register_addresses = [[68, 0], [70, 1]] t_model.save() self.t_model = t_model transductor = EnergyTransductor() transductor.serie_number = "1" transductor.description = "Test" transductor.model = t_model transductor.ip_address = "111.111.111.111" transductor.save() self.transductor = transductor self.create_energy_measurements()
def setUp(self): t_model = TransductorModel() t_model.name = "TR 4020" t_model.transport_protocol = "UdpProtocol" t_model.serial_protocol = "ModbusRTU" t_model.register_addresses = [[4, 0], [68, 1]] t_model.measurements_type = "EnergyMeasurements" t_model.save() self.t_model = t_model transductor = EnergyTransductor() transductor.serie_number = "1" transductor.description = "Test" transductor.model = t_model transductor.ip_address = "111.111.111.111" transductor.broken = False transductor.save() self.transductor = transductor self.modbus_rtu = ModbusRTU(self.transductor)
def test_raise_exception_on_create_messages_with_wrong_address(self): wrong_address = [[4, 2]] t_model = TransductorModel() t_model.name = "Test Model" t_model.transport_protocol = "UDP" t_model.serial_protocol = "Modbus RTU" t_model.register_addresses = wrong_address t_model.save() transductor = EnergyTransductor() transductor.serie_number = "2" transductor.description = "Test 2" transductor.creation_date = timezone.now() transductor.model = t_model transductor.ip_address = "222.222.222.222" transductor.save() modbus = ModbusRTU(transductor) with self.assertRaises(RegisterAddressException): modbus.create_messages()