Skip to content

Commit

Permalink
[FIX] tests
Browse files Browse the repository at this point in the history
  • Loading branch information
archetipo committed Dec 2, 2024
1 parent 8803a41 commit d024f39
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 62 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
1 change: 0 additions & 1 deletion inrim_controllo_accessi_rfidglobal/tests/common.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
from odoo.tests import tagged
from odoo.tests.common import TransactionCase


@tagged("post_install", "-at_install")
class TestCommon(TransactionCase):

Expand Down
76 changes: 16 additions & 60 deletions inrim_controllo_accessi_rfidglobal/tests/test_inrim.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -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)
Expand All @@ -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'
Expand All @@ -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'
Expand Down Expand Up @@ -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'
Expand All @@ -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'
Expand All @@ -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'
Expand Down
3 changes: 2 additions & 1 deletion test-requirements.txt
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
respx
#respx
git+https://github.com/ndhansen/respx.git@master

0 comments on commit d024f39

Please sign in to comment.