|
@@ -10,6 +10,7 @@ class ModbusSchemaTest(unittest.TestCase):
|
|
|
request = ModbusRawReadRequest(
|
|
request = ModbusRawReadRequest(
|
|
|
ip="192.168.75.248",
|
|
ip="192.168.75.248",
|
|
|
port=5512,
|
|
port=5512,
|
|
|
|
|
+ slave_id=1,
|
|
|
read={"function_code": 3, "address": 0, "quantity": 10},
|
|
read={"function_code": 3, "address": 0, "quantity": 10},
|
|
|
)
|
|
)
|
|
|
|
|
|
|
@@ -24,11 +25,22 @@ class ModbusSchemaTest(unittest.TestCase):
|
|
|
|
|
|
|
|
self.assertIn("port", str(context.exception))
|
|
self.assertIn("port", str(context.exception))
|
|
|
|
|
|
|
|
|
|
+ def test_slave_id_is_required(self):
|
|
|
|
|
+ with self.assertRaises(ValidationError) as context:
|
|
|
|
|
+ ModbusRawReadRequest(
|
|
|
|
|
+ ip="192.168.75.248",
|
|
|
|
|
+ port=5512,
|
|
|
|
|
+ read={"function_code": 3, "address": 0, "quantity": 10},
|
|
|
|
|
+ )
|
|
|
|
|
+
|
|
|
|
|
+ self.assertIn("slave_id", str(context.exception))
|
|
|
|
|
+
|
|
|
def test_ip_must_be_valid_address(self):
|
|
def test_ip_must_be_valid_address(self):
|
|
|
with self.assertRaises(ValidationError) as context:
|
|
with self.assertRaises(ValidationError) as context:
|
|
|
ModbusRawReadRequest(
|
|
ModbusRawReadRequest(
|
|
|
ip="not-an-ip",
|
|
ip="not-an-ip",
|
|
|
port=5512,
|
|
port=5512,
|
|
|
|
|
+ slave_id=1,
|
|
|
read={"function_code": 3, "address": 0, "quantity": 10},
|
|
read={"function_code": 3, "address": 0, "quantity": 10},
|
|
|
)
|
|
)
|
|
|
|
|
|