mirror of
https://github.com/bringout/oca-ocb-hw.git
synced 2026-04-19 03:02:00 +02:00
Move 7 IoT modules to oca-ocb-hw and 9 product modules to oca-product
🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
parent
e4803a70af
commit
b1d16a46bf
292 changed files with 19657 additions and 0 deletions
|
|
@ -0,0 +1,3 @@
|
|||
from . import test_iot_in
|
||||
from . import test_iot_multi_input
|
||||
from . import test_iot_controller
|
||||
|
|
@ -0,0 +1,10 @@
|
|||
from odoo import models
|
||||
|
||||
|
||||
class ResPartner(models.Model):
|
||||
_inherit = "res.partner"
|
||||
|
||||
def test_fake_iot_input(self, value):
|
||||
partner = self.browse(value)
|
||||
partner.message_post(body=str(value))
|
||||
return {}
|
||||
|
|
@ -0,0 +1,141 @@
|
|||
import json
|
||||
|
||||
from odoo.tests.common import HttpCase, tagged
|
||||
|
||||
|
||||
@tagged("post_install", "-at_install")
|
||||
class TestIotController(HttpCase):
|
||||
def setUp(self):
|
||||
super().setUp()
|
||||
self.device_identification = "test_device_name"
|
||||
self.passphrase = "password"
|
||||
self.system = self.env["iot.communication.system"].create(
|
||||
{"name": "Demo system"}
|
||||
)
|
||||
self.device = self.env["iot.device"].create(
|
||||
{
|
||||
"name": "Device",
|
||||
"communication_system_id": self.system.id,
|
||||
}
|
||||
)
|
||||
self.address_1 = "I0"
|
||||
self.serial = "testingdeviceserial"
|
||||
self.input_passphrase = "password"
|
||||
self.device_input_1 = self.env["iot.device.input"].create(
|
||||
{
|
||||
"name": "Input 1",
|
||||
"device_id": self.device.id,
|
||||
"address": self.address_1,
|
||||
"serial": self.serial,
|
||||
"passphrase": self.input_passphrase,
|
||||
"call_model_id": self.env.ref(
|
||||
"iot_input_oca.model_iot_device_input"
|
||||
).id,
|
||||
"call_function": "test_model_function",
|
||||
}
|
||||
)
|
||||
self.address_2 = "I1"
|
||||
self.env["iot.device.input"].create(
|
||||
{
|
||||
"name": "Input 2",
|
||||
"device_id": self.device.id,
|
||||
"address": self.address_2,
|
||||
"call_model_id": self.env.ref(
|
||||
"iot_input_oca.model_iot_device_input"
|
||||
).id,
|
||||
"call_function": "test_model_function",
|
||||
}
|
||||
)
|
||||
self.env["iot.device.input"].create(
|
||||
{
|
||||
"name": "Multi Input",
|
||||
"device_id": self.device.id,
|
||||
"serial": self.device_identification,
|
||||
"passphrase": self.passphrase,
|
||||
"call_function": "parse_multi_input",
|
||||
}
|
||||
)
|
||||
self.single_input_values = [{"input": self.address_1, "value": "test"}]
|
||||
self.values = json.dumps(
|
||||
[
|
||||
{"address": self.address_1, "value": "test value 1"},
|
||||
{
|
||||
"address": self.address_1,
|
||||
"value": 2.3,
|
||||
}, # Checking that nothing wrong happens with a non string
|
||||
{"address": self.address_2, "value": "test value 3"},
|
||||
]
|
||||
)
|
||||
|
||||
def test_single_controller(self):
|
||||
res = self.url_open(
|
||||
"/iot/%s/action" % self.serial,
|
||||
data={"passphrase": self.input_passphrase, "value": "123"},
|
||||
)
|
||||
self.assertEqual(res.json()["status"], "ok")
|
||||
|
||||
def test_single_controller_archived_device(self):
|
||||
self.device.write({"active": False})
|
||||
res = self.url_open(
|
||||
"/iot/%s/action" % self.serial,
|
||||
data={"passphrase": self.input_passphrase, "value": "123"},
|
||||
)
|
||||
self.assertEqual(res.json()["status"], "error")
|
||||
|
||||
def test_multi_controller_archived_device(self):
|
||||
self.device.write({"active": False})
|
||||
res = self.url_open(
|
||||
"/iot/%s/multi_input" % self.serial,
|
||||
data={"passphrase": self.input_passphrase, "values": self.values},
|
||||
)
|
||||
self.assertEqual(res.json()["status"], "error")
|
||||
|
||||
def test_multi_input_controller_error_passphrase(self):
|
||||
res = self.url_open(
|
||||
"/iot/%s/multi_input" % self.device_identification,
|
||||
data={"values": self.values},
|
||||
).json()
|
||||
self.assertEqual(res["status"], "error")
|
||||
|
||||
def test_multi_input_controller_error_values(self):
|
||||
res = self.url_open(
|
||||
"/iot/%s/multi_input" % self.device_identification,
|
||||
data={"passphrase": self.passphrase},
|
||||
).json()
|
||||
self.assertEqual(res["status"], "error")
|
||||
|
||||
def test_multi_input_controller_syntax_error(self):
|
||||
res = self.url_open(
|
||||
"/iot/%s/multi_input" % self.device_identification,
|
||||
data={"passphrase": self.passphrase, "values": "{}"},
|
||||
).json()
|
||||
self.assertEqual(res["status"], "error")
|
||||
|
||||
def test_multi_input_controller_malformed_error(self):
|
||||
res = self.url_open(
|
||||
"/iot/%s/multi_input" % self.device_identification,
|
||||
data={"passphrase": self.passphrase, "values": "{1234}"},
|
||||
).json()
|
||||
self.assertEqual(res["status"], "error")
|
||||
|
||||
def test_multi_input_controller(self):
|
||||
res = self.url_open(
|
||||
"/iot/%s/multi_input" % self.device_identification,
|
||||
data={"passphrase": self.passphrase, "values": self.values},
|
||||
)
|
||||
result = res.json()
|
||||
for response in result:
|
||||
self.assertEqual(response["status"], "ok")
|
||||
|
||||
def test_multi_input_controller_unauthorized_iot_exists(self):
|
||||
res = self.url_open(
|
||||
"/iot/%s/check" % self.serial, data={"passphrase": self.input_passphrase}
|
||||
).json()
|
||||
self.assertEqual(res["state"], True)
|
||||
|
||||
def test_multi_input_controller_unauthorized_iot_no_exists(self):
|
||||
res = self.url_open(
|
||||
"/iot/%s/check" % self.passphrase,
|
||||
data={"passphrase": self.input_passphrase},
|
||||
).json()
|
||||
self.assertEqual(res["state"], False)
|
||||
|
|
@ -0,0 +1,122 @@
|
|||
from odoo.exceptions import ValidationError
|
||||
from odoo.tests.common import TransactionCase
|
||||
|
||||
|
||||
class TestIotIn(TransactionCase):
|
||||
@classmethod
|
||||
def setUpClass(cls):
|
||||
super().setUpClass()
|
||||
cls.serial = "testingdeviceserial"
|
||||
cls.passphrase = "password"
|
||||
cls.system = cls.env["iot.communication.system"].create({"name": "Demo system"})
|
||||
cls.device = cls.env["iot.device"].create(
|
||||
{"name": "Device", "communication_system_id": cls.system.id}
|
||||
)
|
||||
cls.device_input = cls.env["iot.device.input"].create(
|
||||
{
|
||||
"name": "Input",
|
||||
"device_id": cls.device.id,
|
||||
"active": True,
|
||||
"serial": cls.serial,
|
||||
"passphrase": cls.passphrase,
|
||||
"call_model_id": cls.env.ref("iot_input_oca.model_iot_device_input").id,
|
||||
"call_function": "test_input_device",
|
||||
}
|
||||
)
|
||||
cls.iot = cls.env["iot.device.input"]
|
||||
|
||||
def test_device_action_count_ids(self):
|
||||
self.assertEqual(self.device.input_count, 1)
|
||||
|
||||
def _get_devices(self):
|
||||
action = self.device.action_show_input()
|
||||
devices = self.env[action["res_model"]]
|
||||
if action["res_id"]:
|
||||
devices = devices.browse(action["res_id"])
|
||||
else:
|
||||
devices = devices.search(action["domain"])
|
||||
return devices
|
||||
|
||||
def test_device_action(self):
|
||||
devices = self._get_devices()
|
||||
self.assertEqual(devices, self.device_input)
|
||||
device_input_02 = self.env["iot.device.input"].create(
|
||||
{
|
||||
"name": "Input",
|
||||
"device_id": self.device.id,
|
||||
"active": True,
|
||||
"serial": self.serial + self.serial,
|
||||
"passphrase": self.passphrase,
|
||||
"call_model_id": self.env.ref(
|
||||
"iot_input_oca.model_iot_device_input"
|
||||
).id,
|
||||
"call_function": "test_input_device",
|
||||
}
|
||||
)
|
||||
devices = self._get_devices()
|
||||
self.assertIn(self.device_input, devices)
|
||||
self.assertIn(device_input_02, devices)
|
||||
|
||||
def test_device_error_wrong_serial(self):
|
||||
self.assertFalse(
|
||||
self.iot.get_device(
|
||||
serial=self.serial + self.serial, passphrase=self.passphrase
|
||||
)
|
||||
)
|
||||
|
||||
def test_device_error_wrong_passphrase(self):
|
||||
self.assertFalse(
|
||||
self.iot.get_device(
|
||||
serial=self.serial, passphrase=self.passphrase + self.passphrase
|
||||
)
|
||||
)
|
||||
|
||||
def test_device_error_archived(self):
|
||||
self.device_input.active = False
|
||||
self.assertFalse(
|
||||
self.iot.get_device(serial=self.serial, passphrase=self.passphrase)
|
||||
)
|
||||
|
||||
def test_device_error_missing_data(self):
|
||||
with self.assertRaises(ValidationError):
|
||||
self.iot.get_device(serial=False, passphrase=self.passphrase)
|
||||
|
||||
def test_error_execution_without_device(self):
|
||||
res = self.iot.call_device(value="hello")
|
||||
self.assertEqual(res["status"], "error")
|
||||
|
||||
def test_device_input_calling(self):
|
||||
iot = self.iot.get_device(serial=self.serial, passphrase=self.passphrase)
|
||||
self.assertEqual(iot, self.device_input)
|
||||
self.assertEqual(0, self.device_input.action_count)
|
||||
args = "hello"
|
||||
res = iot.call_device(value=args)
|
||||
self.assertEqual(res, {"status": "ok", "value": args})
|
||||
self.assertTrue(self.device_input.action_ids)
|
||||
self.assertEqual(self.device_input.action_ids.args, str([args]))
|
||||
self.assertEqual(self.device_input.action_ids.res, str(res))
|
||||
self.assertEqual(1, self.device_input.action_count)
|
||||
|
||||
def test_device_input_calling_with_lang(self):
|
||||
devices = self._get_devices()
|
||||
self.assertEqual(devices, self.device_input)
|
||||
device_input_lang = self.env["iot.device.input"].create(
|
||||
{
|
||||
"name": "Input",
|
||||
"lang": "en_US",
|
||||
"device_id": self.device.id,
|
||||
"active": True,
|
||||
"serial": self.serial + self.serial,
|
||||
"passphrase": self.passphrase,
|
||||
"call_model_id": self.env.ref(
|
||||
"iot_input_oca.model_iot_device_input"
|
||||
).id,
|
||||
"call_function": "test_input_device",
|
||||
}
|
||||
)
|
||||
devices = self._get_devices()
|
||||
self.assertIn(self.device_input, devices)
|
||||
self.assertIn(device_input_lang, devices)
|
||||
args = "hello"
|
||||
res = device_input_lang.call_device(value=args)
|
||||
self.assertEqual(res, {"status": "ok", "value": args})
|
||||
|
|
@ -0,0 +1,196 @@
|
|||
from odoo.tests.common import TransactionCase
|
||||
from odoo.tools import mute_logger
|
||||
|
||||
|
||||
class TestIotIn(TransactionCase):
|
||||
@classmethod
|
||||
def setUpClass(cls):
|
||||
super().setUpClass()
|
||||
cls.device_identification = "test_device_name"
|
||||
cls.passphrase = "password"
|
||||
|
||||
cls.system = cls.env["iot.communication.system"].create({"name": "Demo system"})
|
||||
cls.device = cls.env["iot.device"].create(
|
||||
{
|
||||
"name": "Device",
|
||||
"communication_system_id": cls.system.id,
|
||||
}
|
||||
)
|
||||
cls.address_1 = "I0"
|
||||
cls.device_input_1 = cls.env["iot.device.input"].create(
|
||||
{
|
||||
"name": "Input 1",
|
||||
"device_id": cls.device.id,
|
||||
"address": cls.address_1,
|
||||
"call_model_id": cls.env.ref("iot_input_oca.model_iot_device_input").id,
|
||||
"call_function": "test_model_function",
|
||||
}
|
||||
)
|
||||
cls.address_2 = "I1"
|
||||
cls.env["iot.device.input"].create(
|
||||
{
|
||||
"name": "Input 2",
|
||||
"device_id": cls.device.id,
|
||||
"address": cls.address_2,
|
||||
"call_model_id": cls.env.ref("iot_input_oca.model_iot_device_input").id,
|
||||
"call_function": "test_model_function",
|
||||
}
|
||||
)
|
||||
cls.env["iot.device.input"].create(
|
||||
{
|
||||
"name": "Multi Input",
|
||||
"device_id": cls.device.id,
|
||||
"serial": cls.device_identification,
|
||||
"passphrase": cls.passphrase,
|
||||
"call_function": "parse_multi_input",
|
||||
}
|
||||
)
|
||||
cls.single_input_values = [{"input": cls.address_1, "value": "test"}]
|
||||
cls.iot = cls.env["iot.device.input"]
|
||||
|
||||
def test_multi_input_error_wrong_identification(self):
|
||||
iot = self.iot.get_device(
|
||||
serial=self.device_identification + self.device_identification,
|
||||
passphrase=self.passphrase,
|
||||
)
|
||||
# device not found -> result is error
|
||||
self.assertEqual(
|
||||
iot.call_device(values=self.single_input_values)["status"],
|
||||
"error",
|
||||
)
|
||||
|
||||
def test_multi_input_error_no_inputs(self):
|
||||
iot = self.iot.get_device(
|
||||
serial=self.device_identification, passphrase=self.passphrase
|
||||
)
|
||||
self.assertEqual(
|
||||
iot.call_device(values=[])["status"],
|
||||
"ko",
|
||||
)
|
||||
|
||||
def test_multi_input_non_existing_address(self):
|
||||
non_existing_address = "I3"
|
||||
iot = self.iot.get_device(
|
||||
serial=self.device_identification, passphrase=self.passphrase
|
||||
)
|
||||
for response in iot.call_device(
|
||||
values=[{"address": non_existing_address, "value": "test value 1"}],
|
||||
)["result"]:
|
||||
self.assertEqual(response["status"], "error")
|
||||
|
||||
@mute_logger("odoo.addons.iot_input_oca.models.iot_device_input")
|
||||
def test_error_missing_parameter(self):
|
||||
iot = self.iot.get_device(
|
||||
serial=self.device_identification, passphrase=self.passphrase
|
||||
)
|
||||
for response in iot.call_device(values=[{"address": self.address_1}])["result"]:
|
||||
self.assertEqual(response["status"], "ko")
|
||||
|
||||
@mute_logger("odoo.addons.iot_input_oca.models.iot_device_input")
|
||||
def test_error_with_extra_args(self):
|
||||
|
||||
iot = self.iot.get_device(
|
||||
serial=self.device_identification, passphrase=self.passphrase
|
||||
)
|
||||
for response in iot.call_device(
|
||||
values=[{"address": self.address_1, "uuid": "abc"}],
|
||||
)["result"]:
|
||||
self.assertEqual(response["status"], "ko")
|
||||
self.assertTrue("uuid" in response)
|
||||
|
||||
def test_error_no_address_with_extra_args(self):
|
||||
iot = self.iot.get_device(
|
||||
serial=self.device_identification, passphrase=self.passphrase
|
||||
)
|
||||
for response in iot.call_device(values=[{"uuid": "abc"}])["result"]:
|
||||
self.assertEqual(response["status"], "error")
|
||||
self.assertTrue("uuid" in response)
|
||||
|
||||
def test_error_no_address(self):
|
||||
iot = self.iot.get_device(
|
||||
serial=self.device_identification, passphrase=self.passphrase
|
||||
)
|
||||
for response in iot.call_device(values=[{"value": "test value"}])["result"]:
|
||||
self.assertEqual(response["status"], "error")
|
||||
|
||||
def test_correct_one_input(self):
|
||||
iot = self.iot.get_device(
|
||||
serial=self.device_identification, passphrase=self.passphrase
|
||||
)
|
||||
for response in iot.call_device(
|
||||
values=[{"address": self.address_1, "value": "test"}],
|
||||
)["result"]:
|
||||
self.assertEqual(response["status"], "ok")
|
||||
|
||||
def test_correct_two_inputs(self):
|
||||
iot = self.iot.get_device(
|
||||
serial=self.device_identification, passphrase=self.passphrase
|
||||
)
|
||||
for response in iot.call_device(
|
||||
values=[
|
||||
{"address": self.address_1, "value": "test value 1"},
|
||||
{
|
||||
"address": self.address_1,
|
||||
"value": 2.3,
|
||||
}, # Checking that nothing wrong happens with a non string
|
||||
{"address": self.address_2, "value": "test value 3"},
|
||||
],
|
||||
)["result"]:
|
||||
self.assertEqual(response["status"], "ok")
|
||||
|
||||
def test_correct_with_extra_args(self):
|
||||
iot = self.iot.get_device(
|
||||
serial=self.device_identification, passphrase=self.passphrase
|
||||
)
|
||||
response_with_uuid = [
|
||||
{"address": self.address_1, "value": "test value 1", "uuid": "abc"},
|
||||
{"address": self.address_1, "value": "test value 2", "uuid": "def"},
|
||||
{"address": self.address_2, "value": "test value 3", "uuid": "ghi"},
|
||||
]
|
||||
for response in iot.call_device(values=response_with_uuid)["result"]:
|
||||
self.assertTrue(response["uuid"])
|
||||
self.assertEqual(
|
||||
response["message"],
|
||||
[x for x in response_with_uuid if x["uuid"] == response["uuid"]][0][
|
||||
"value"
|
||||
],
|
||||
)
|
||||
|
||||
def test_error_archived_device(self):
|
||||
self.device.active = False
|
||||
iot = self.iot.get_device(
|
||||
serial=self.device_identification, passphrase=self.passphrase
|
||||
)
|
||||
self.assertEqual(
|
||||
iot.call_device(
|
||||
values=[{"address": self.address_1, "value": "test"}],
|
||||
)["status"],
|
||||
"error",
|
||||
)
|
||||
|
||||
def test_error_archived_device_input(self):
|
||||
self.device_input_1.active = False
|
||||
iot = self.iot.get_device(
|
||||
serial=self.device_identification, passphrase=self.passphrase
|
||||
)
|
||||
for result in iot.call_device(
|
||||
values=[{"address": self.address_1, "value": "test"}],
|
||||
)["result"]:
|
||||
self.assertEqual(
|
||||
result["status"],
|
||||
"error",
|
||||
)
|
||||
|
||||
def test_error_archived_device_input_extra_args(self):
|
||||
self.device_input_1.active = False
|
||||
iot = self.iot.get_device(
|
||||
serial=self.device_identification, passphrase=self.passphrase
|
||||
)
|
||||
for result in iot.call_device(
|
||||
values=[{"address": self.address_1, "value": "test", "uuid": "ghi"}],
|
||||
)["result"]:
|
||||
self.assertEqual(
|
||||
result["status"],
|
||||
"error",
|
||||
)
|
||||
self.assertEqual(result["uuid"], "ghi")
|
||||
Loading…
Add table
Add a link
Reference in a new issue