1
1
# Copyright 2019 Camptocamp SA
2
2
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
3
3
4
- from odoo import exceptions
4
+ from freezegun import freeze_time
5
+
6
+ from odoo import exceptions , fields
5
7
from odoo .tools import mute_logger
6
8
7
9
from .common import VerticalLiftCase
@@ -23,3 +25,45 @@ def test_lift_commands(self):
23
25
"command" : "0|test|1" ,
24
26
}
25
27
)
28
+
29
+ @mute_logger ("odoo.addons.stock_vertical_lift.models.vertical_lift_command" )
30
+ def test_lift_commands_autovacuum (self ):
31
+ command_obj = self .env ["vertical.lift.command" ]
32
+ param_obj = self .env ["ir.config_parameter" ].sudo ()
33
+ param_key = "stock_vertical_lift.delete_command_after_days"
34
+
35
+ # Create 1 new command for the test
36
+ vals = {"name" : "Test" , "command" : "Test" , "shuttle_id" : self .shuttle .id }
37
+ command = command_obj .create (vals )
38
+ create_date = command .create_date .date ()
39
+
40
+ # Test 1: param ``stock_vertical_lift.delete_command_after_days`` not set
41
+ # => command not deleted
42
+ param_obj .search ([("key" , "=" , param_key )]).unlink ()
43
+ command_obj ._autovacuum_commands ()
44
+ self .assertTrue (command .exists ())
45
+
46
+ # Test 2: param ``stock_vertical_lift.delete_command_after_days`` set, but
47
+ # the given value is not an integer
48
+ # => command not deleted
49
+ param_obj .set_param (param_key , "asd" )
50
+ command_obj ._autovacuum_commands ()
51
+ self .assertTrue (command .exists ())
52
+
53
+ # Test 3: param ``stock_vertical_lift.delete_command_after_days`` set, but
54
+ # the command is created later than the time limit (limit is 10 days, method is
55
+ # executed 5 days after the command creation)
56
+ # => command not deleted
57
+ param_obj .set_param (param_key , 10 )
58
+ with freeze_time (fields .Date .add (create_date , days = 5 )):
59
+ command_obj ._autovacuum_commands ()
60
+ self .assertTrue (command .exists ())
61
+
62
+ # Test 4: param ``stock_vertical_lift.delete_command_after_days`` set, and
63
+ # the command is created earlier than the time limit (limit is 10 days, method
64
+ # is executed 15 days after the command creation)
65
+ # => command not deleted
66
+ param_obj .set_param (param_key , 10 )
67
+ with freeze_time (fields .Date .add (create_date , days = 15 )):
68
+ command_obj ._autovacuum_commands ()
69
+ self .assertFalse (command .exists ())
0 commit comments