@@ -118,6 +118,47 @@ def test_template_directory(self):
118118 self .template .group_ids , self .template .dms_directory_ids .group_ids
119119 )
120120
121+ def test_template_directory_creation (self ):
122+ template = self .env ["dms.field.template" ].create (
123+ {
124+ "name" : "Users template" ,
125+ "storage_id" : self .storage .id ,
126+ "model_id" : self .env .ref ("base.model_res_users" ).id ,
127+ "group_ids" : [fields .Command .link (self .template .group_ids .id )],
128+ }
129+ )
130+ directory = template .with_context (
131+ res_model = template ._name ,
132+ res_id = template .id ,
133+ ).create_dms_directory ()
134+
135+ self .assertEqual (directory .storage_id , template .storage_id )
136+ self .assertEqual (directory .res_model , template ._name )
137+ self .assertEqual (directory .res_id , template .id )
138+ self .assertTrue (directory .is_root_directory )
139+ self .assertIn (template .group_ids , directory .group_ids )
140+ second_directory = template .with_context (
141+ res_model = template ._name ,
142+ res_id = template .id ,
143+ ).create_dms_directory ()
144+ self .assertEqual (second_directory , directory )
145+
146+ def test_template_directory_creation_is_idempotent (self ):
147+ directory = self .template .dms_directory_ids
148+ directory .group_ids = [fields .Command .clear ()]
149+ self .assertFalse (directory .group_ids )
150+
151+ template = self .env ["dms.field.template" ].with_context (
152+ res_model = self .template ._name ,
153+ res_id = self .template .id ,
154+ )
155+ first_directory = template .create_dms_directory ()
156+ second_directory = template .create_dms_directory ()
157+
158+ self .assertEqual (first_directory , directory )
159+ self .assertEqual (second_directory , directory )
160+ self .assertIn (self .template .group_ids , directory .group_ids )
161+
121162 @mute_logger ("odoo.models.unlink" )
122163 def test_creation_process_01 (self ):
123164 self .assertFalse (self .partner .dms_directory_ids )
0 commit comments