Пример #1
0
    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()
Пример #2
0
    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)
Пример #3
0
    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)
Пример #4
0
    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 test_not_create_energy_transductor_wrong_serial_number(self):
        size = len(EnergyTransductor.objects.all())

        transductor = EnergyTransductor()
        transductor.serial_number = '123456789'
        transductor.ip_address = '1.1.1.1'
        transductor.broken = False
        transductor.active = True
        transductor.model = "EnergyTransductor"
        transductor.installation_date = datetime.now()

        with self.assertRaises(DataError):
            transductor.save()
    def test_not_create_energy_transductor_no_geolocation_longitude(self):
        size = len(EnergyTransductor.objects.all())

        transductor = EnergyTransductor()
        transductor.serial_number = '123456789'
        transductor.ip_address = '1.1.1.1'
        transductor.broken = False
        transductor.active = True
        transductor.model = "EnergyTransductor"
        transductor.firmware_version = '12.1.3215'
        transductor.physical_location = 'predio 2 sala 44'
        transductor.geolocation_latitude = -24.4556
        transductor.installation_date = datetime.now()

        with self.assertRaises(DataError):
            transductor.save()
Пример #7
0
    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 test_create_energy_transductor(self):
        size = len(EnergyTransductor.objects.all())

        energy_transductor = EnergyTransductor()
        energy_transductor.serial_number = '12345678'
        energy_transductor.ip_address = '1.1.1.1'
        energy_transductor.broken = False
        energy_transductor.active = True
        energy_transductor.model = "EnergyTransductor"
        energy_transductor.firmware_version = '12.1.3215'
        energy_transductor.physical_location = 'predio 2 sala 44'
        energy_transductor.geolocation_longitude = -24.4556
        energy_transductor.geolocation_latitude = -24.45996
        energy_transductor.installation_date = datetime.now()

        self.assertIsNone(energy_transductor.save())
        self.assertEqual(size + 1, len(EnergyTransductor.objects.all()))
Пример #9
0
    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()
Пример #10
0
    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)
Пример #11
0
    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()