diff --git a/inrim_controllo_accessi_rfidglobal/models/Max5010_rfid_lib.py b/inrim_controllo_accessi_rfidglobal/models/Max5010_rfid_lib.py index c1f9bdf..76a8049 100644 --- a/inrim_controllo_accessi_rfidglobal/models/Max5010_rfid_lib.py +++ b/inrim_controllo_accessi_rfidglobal/models/Max5010_rfid_lib.py @@ -175,6 +175,7 @@ def post_request(self, path: str, body: dict) -> (dict, str): except Exception as e: msg = f"Exception {path}, Error: {e}" self.connction_error = True + logger.error(msg) return {}, msg def load_info(self) -> Device: diff --git a/inrim_controllo_accessi_rfidglobal/tests/common.py b/inrim_controllo_accessi_rfidglobal/tests/common.py index eb3419d..be27398 100644 --- a/inrim_controllo_accessi_rfidglobal/tests/common.py +++ b/inrim_controllo_accessi_rfidglobal/tests/common.py @@ -1,7 +1,6 @@ from odoo.tests import tagged from odoo.tests.common import TransactionCase - @tagged("post_install", "-at_install") class TestCommon(TransactionCase): diff --git a/inrim_controllo_accessi_rfidglobal/tests/test_inrim.py b/inrim_controllo_accessi_rfidglobal/tests/test_inrim.py index fc5f54e..341777f 100644 --- a/inrim_controllo_accessi_rfidglobal/tests/test_inrim.py +++ b/inrim_controllo_accessi_rfidglobal/tests/test_inrim.py @@ -61,22 +61,16 @@ def test_4(self): :return: I campi vengono scritti correttamente nei campi del lettore """ - def info(request, route): - return httpx.Response(200, json=self.info_data) - - def status(request, route): - return httpx.Response(200, json=self.status_data) - respx.post( 'http://local-host/info', ).mock( - side_effect=info + return_value=httpx.Response(200, json=self.info_data) ) respx.post( 'http://local-host/status', ).mock( - side_effect=status + return_value=httpx.Response(200, json=self.status_data) ) device = '10.10.10.1' @@ -90,6 +84,7 @@ def status(request, route): punto_accesso_id = self.env['ca.punto_accesso'].search([ ('ca_lettore_id.reader_ip', '=', device) ], limit=1) + self.assertEqual(device_id, punto_accesso_id.ca_lettore_id.device_id) self.assertEqual(self.status_data['diagnostic']['event_cnt'], punto_accesso_id.ca_lettore_id.available_events) @@ -104,30 +99,21 @@ def test_5(self): :return: I campi vengono scritti correttamente nei campi del lettore """ - def info(request, route): - return httpx.Response(200, json=self.info_data) - - def status(request, route): - return httpx.Response(200, json=self.status_data) - - def events(request, route): - return httpx.Response(200, json=self.read_events_data) - respx.post( 'http://local-host/info', ).mock( - side_effect=info + return_value=httpx.Response(200, json=self.info_data) ) respx.post( 'http://local-host/status', ).mock( - side_effect=status + return_value=httpx.Response(200, json=self.status_data) ) respx.post( 'http://local-host/read-events', ).mock( - side_effect=events + return_value=httpx.Response(200, json=self.read_events_data) ) device = '10.10.10.1' @@ -151,22 +137,16 @@ def test_6(self): :return: I metodi funzionano e restituiscono i risultati attesi """ - def info(request, route): - return httpx.Response(200, json=self.info_data) - - def status(request, route): - return httpx.Response(200, json=self.status_data) - respx.post( 'http://local-host/info', ).mock( - side_effect=info + return_value=httpx.Response(200, json=self.info_data) ) respx.post( 'http://local-host/status', ).mock( - side_effect=status + return_value=httpx.Response(200, json=self.status_data) ) device = '10.10.10.1' @@ -196,22 +176,16 @@ def test_7(self): :return: I metodi funzionano e restituiscono i risultati attesi """ - def info(request, route): - return httpx.Response(200, json=self.info_data) - - def status(request, route): - return httpx.Response(200, json=self.status_data) - respx.post( 'http://local-host/info', ).mock( - side_effect=info + return_value=httpx.Response(200, json=self.info_data) ) respx.post( 'http://local-host/status', ).mock( - side_effect=status + return_value=httpx.Response(200, json=self.status_data) ) device = '10.10.10.1' @@ -232,31 +206,22 @@ def test_8(self): :return: I metodi funzionano e restituiscono i risultati attesi """ - def info(request, route): - return httpx.Response(200, json=self.info_data) - - def status(request, route): - return httpx.Response(200, json=self.status_data_empty) - - def tagres(request, route): - return httpx.Response(200, json=self.res_add_tag) - respx.post( 'http://local-host/info', ).mock( - side_effect=info + return_value=httpx.Response(200, json=self.info_data) ) respx.post( 'http://local-host/status', ).mock( - side_effect=status + return_value=httpx.Response(200, json=self.status_data) ) respx.post( 'http://local-host/add-tags', ).mock( - side_effect=tagres + return_value=httpx.Response(200, json=self.res_add_tag) ) device = '10.10.10.1' @@ -277,31 +242,22 @@ def test_9(self): Aggiorna orologio di sistema del Reader """ - def info(request, route): - return httpx.Response(200, json=self.info_data) - - def status(request, route): - return httpx.Response(200, json=self.status_data) - - def clock(request, route): - return httpx.Response(200, json=self.res_add_tag) - respx.post( 'http://local-host/info', ).mock( - side_effect=info + return_value=httpx.Response(200, json=self.info_data) ) respx.post( 'http://local-host/status', ).mock( - side_effect=status + return_value=httpx.Response(200, json=self.status_data) ) respx.post( 'http://local-host/update-clock', ).mock( - side_effect=clock + return_value=httpx.Response(200, json=self.res_add_tag) ) device = '10.10.10.1' diff --git a/test-requirements.txt b/test-requirements.txt index e27e2a4..c98597f 100644 --- a/test-requirements.txt +++ b/test-requirements.txt @@ -1 +1,2 @@ -respx \ No newline at end of file +#respx +git+https://github.com/ndhansen/respx.git@master \ No newline at end of file