4
4
5
5
from unittest .mock import MagicMock , patch
6
6
7
+ from odoo .exceptions import AccessError
7
8
from odoo .tests .common import TransactionCase
8
9
9
10
@@ -16,53 +17,75 @@ def setUp(self):
16
17
"voxel_enabled" : True ,
17
18
}
18
19
)
20
+ voxel_xml_report_msg = (
21
+ "Error reading document INV_20250131_200845_553.xml from folder Inbox"
22
+ )
23
+ processing_error_msg = (
24
+ "Processing error: Error reading document "
25
+ "INV_20250131_200845_553.xml from folder Inbox"
26
+ )
19
27
self .mixin = self .env ["voxel.mixin" ].create (
20
28
{
21
29
"voxel_state" : "not_sent" ,
22
- # 'company_id': self.company.id,
30
+ "voxel_xml_report" : voxel_xml_report_msg ,
31
+ "voxel_filename" : "INV_20250131_200845_553.xml" ,
32
+ "processing_error" : processing_error_msg ,
23
33
}
24
34
)
25
35
26
36
@patch ("odoo.addons.edi_voxel_oca.models.voxel_mixin.requests.put" )
27
37
def test_send_voxel_report_success (self , mock_put ):
28
38
mock_put .return_value .status_code = 200
29
- self .mixin ._send_voxel_report ("Outbox" , "test.xml" , b"<xml></xml>" )
39
+ self .mixin ._send_voxel_report (
40
+ "Outbox" , "INV_20241231_200845_553.xml" , b"<xml></xml>"
41
+ )
30
42
self .assertEqual (self .mixin .voxel_state , "sent" , "Voxel state should be 'sent'" )
31
43
32
44
@patch ("odoo.addons.edi_voxel_oca.models.voxel_mixin.requests.put" )
33
45
def test_send_voxel_report_failure (self , mock_put ):
34
46
mock_put .return_value .status_code = 500
35
- with self .assertRaises (Exception ) as context :
36
- self .mixin ._send_voxel_report ("Outbox" , "test.xml" , b"<xml></xml>" )
37
- self .assertTrue ("specific error message" in str (context .exception ))
47
+ with self .assertRaises (AccessError ) as context :
48
+ self .mixin .with_delay ()._send_voxel_report (
49
+ "Outbox" , "INV_20241231_200845_553.xml" , b"<xml></xml>"
50
+ )
51
+ self .assertTrue (
52
+ "Queue jobs must be created by calling 'with_delay()'"
53
+ in str (context .exception )
54
+ )
38
55
self .assertEqual (
39
56
self .mixin .voxel_state , "sent_errors" , "Voxel state should be 'sent_errors'"
40
57
)
41
58
42
59
@patch ("odoo.addons.edi_voxel_oca.models.voxel_mixin.requests.get" )
43
60
def test_list_voxel_document_filenames (self , mock_get ):
44
61
mock_get .return_value .status_code = 200
45
- mock_get .return_value .content = b"test1.xml\n test2.xml\n "
62
+ mock_get .return_value .content = (
63
+ b"INV_20250113_200845_555.xml\n INV_20250113_200847_557.xml\n "
64
+ )
46
65
filenames = self .mixin ._list_voxel_document_filenames ("Outbox" , self .company )
47
66
self .assertEqual (
48
67
filenames ,
49
- ["test1 .xml" , "test2 .xml" ],
68
+ ["INV_20250113_200845_555 .xml" , "INV_20250113_200847_557 .xml" ],
50
69
"Filenames should match the expected list" ,
51
70
)
52
71
53
72
@patch ("odoo.addons.edi_voxel_oca.models.voxel_mixin.requests.get" )
54
73
def test_read_voxel_document (self , mock_get ):
55
74
mock_get .return_value .status_code = 200
56
75
mock_get .return_value .content = b"<xml></xml>"
57
- content = self .mixin ._read_voxel_document ("Inbox" , self .company , "test.xml" )
76
+ content = self .mixin ._read_voxel_document (
77
+ "Inbox" , self .company , "INV_20241231_200845_553.xml"
78
+ )
58
79
self .assertEqual (
59
80
content , "<xml></xml>" , "Content should match the expected XML"
60
81
)
61
82
62
83
@patch ("odoo.addons.edi_voxel_oca.models.voxel_mixin.requests.delete" )
63
84
def test_delete_voxel_document (self , mock_delete ):
64
85
mock_delete .return_value .status_code = 200
65
- self .mixin ._delete_voxel_document ("Inbox" , "test.xml" , self .company )
86
+ self .mixin ._delete_voxel_document (
87
+ "Inbox" , "INV_20241231_200845_553.xml" , self .company
88
+ )
66
89
mock_delete .assert_called_once ()
67
90
68
91
def test_get_voxel_filename (self ):
0 commit comments