|
142
|
1 |
import logging |
|
|
2 |
|
|
|
3 |
from django.contrib.auth import get_user_model |
|
|
4 |
from django.test import TestCase |
|
|
5 |
from protocols.models import (Metacategory, MetacategoryRevision, Protocol, |
|
|
6 |
ProtocolRevision) |
|
|
7 |
from protocols.serializers import ProtocolRevisionSerializer |
|
|
8 |
|
|
|
9 |
logger = logging.getLogger(__name__) |
|
|
10 |
|
|
|
11 |
class ManagerTest(TestCase): |
|
|
12 |
|
|
|
13 |
def setUp(self): |
|
|
14 |
User = get_user_model() |
|
|
15 |
self.user1 = User.objects.create_user( |
|
|
16 |
username='user1', |
|
|
17 |
email='user1@email.com', |
|
|
18 |
password='hiddenpassword' |
|
|
19 |
) |
|
|
20 |
|
|
|
21 |
self.user2 = User.objects.create_user( |
|
|
22 |
username='user2', |
|
|
23 |
email='user2@email.com', |
|
|
24 |
password='hiddenpassword' |
|
|
25 |
) |
|
|
26 |
|
|
|
27 |
|
|
|
28 |
def test_create_new_protocol_new_categories(self): |
|
|
29 |
|
|
|
30 |
protocol_nb = Protocol.objects.all().count() |
|
|
31 |
protocol_rev_nb = ProtocolRevision.objects.all().count() |
|
|
32 |
metacategory_nb = Metacategory.objects.all().count() |
|
|
33 |
metacategory_rev_nb = MetacategoryRevision.objects.all().count() |
|
|
34 |
|
|
|
35 |
revision_def = { |
|
|
36 |
'title': 'protocol1', |
|
|
37 |
'description': 'Protocol nº1', |
|
|
38 |
'owner': 'admin', |
|
|
39 |
'metacategories' : [{ |
|
|
40 |
'title': 'Important', |
|
|
41 |
'label': 'important', |
|
|
42 |
'description': "Important.", |
|
|
43 |
'color': '#F1C40F', |
|
|
44 |
'version': 1, |
|
|
45 |
'has_comment': False |
|
|
46 |
}, { |
|
|
47 |
'title': 'Mot-clé', |
|
|
48 |
'label': 'mot-cle', |
|
|
49 |
'description': "Mot-clé.", |
|
|
50 |
'color': '#2ECC71', |
|
|
51 |
'version': 1, |
|
|
52 |
'has_comment': False |
|
|
53 |
}, { |
|
|
54 |
'title': 'Commentaire', |
|
|
55 |
'label': 'commentaire', |
|
|
56 |
'description': "Commentaire.", |
|
|
57 |
'color': '#3498DB', |
|
|
58 |
'version': 1, |
|
|
59 |
'has_comment': True |
|
|
60 |
}] |
|
|
61 |
} |
|
|
62 |
|
|
|
63 |
protocol_revision = Protocol.objects.create_new_revision(None, revision_def, None) |
|
|
64 |
|
|
|
65 |
self.assertEqual(protocol_nb+1, Protocol.objects.all().count()) |
|
|
66 |
self.assertEqual(protocol_rev_nb+1, ProtocolRevision.objects.all().count()) |
|
|
67 |
self.assertEqual(metacategory_nb+3, Metacategory.objects.all().count()) |
|
|
68 |
self.assertEqual(metacategory_rev_nb+3, MetacategoryRevision.objects.all().count()) |
|
|
69 |
|
|
|
70 |
|
|
|
71 |
def test_no_create_new_protocol(self): |
|
|
72 |
|
|
|
73 |
revision_def = { |
|
|
74 |
'title': 'protocol1', |
|
|
75 |
'description': 'Protocol nº1', |
|
|
76 |
'owner': 'admin', |
|
|
77 |
'metacategories' : [{ |
|
|
78 |
'title': 'Important', |
|
|
79 |
'label': 'important', |
|
|
80 |
'description': "Important.", |
|
|
81 |
'color': '#F1C40F', |
|
|
82 |
'version': 1, |
|
|
83 |
'has_comment': False |
|
|
84 |
}, { |
|
|
85 |
'title': 'Mot-clé', |
|
|
86 |
'label': 'mot-cle', |
|
|
87 |
'description': "Mot-clé.", |
|
|
88 |
'color': '#2ECC71', |
|
|
89 |
'version': 1, |
|
|
90 |
'has_comment': False |
|
|
91 |
}, { |
|
|
92 |
'title': 'Commentaire', |
|
|
93 |
'label': 'commentaire', |
|
|
94 |
'description': "Commentaire.", |
|
|
95 |
'color': '#3498DB', |
|
|
96 |
'version': 1, |
|
|
97 |
'has_comment': True |
|
|
98 |
}] |
|
|
99 |
} |
|
|
100 |
|
|
|
101 |
protocol_revision = Protocol.objects.create_new_revision(None, revision_def, None) |
|
|
102 |
|
|
|
103 |
serializer = ProtocolRevisionSerializer(protocol_revision) |
|
|
104 |
|
|
|
105 |
protocol_nb = Protocol.objects.all().count() |
|
|
106 |
protocol_rev_nb = ProtocolRevision.objects.all().count() |
|
|
107 |
metacategory_nb = Metacategory.objects.all().count() |
|
|
108 |
metacategory_rev_nb = MetacategoryRevision.objects.all().count() |
|
|
109 |
|
|
|
110 |
protocol_revision = Protocol.objects.create_new_revision(protocol_revision.protocol.ext_id, serializer.data, None) |
|
|
111 |
|
|
|
112 |
self.assertEqual(protocol_nb, Protocol.objects.all().count()) |
|
|
113 |
self.assertEqual(metacategory_nb, Metacategory.objects.all().count()) |
|
|
114 |
self.assertEqual(metacategory_rev_nb, MetacategoryRevision.objects.all().count()) |
|
|
115 |
|
|
|
116 |
self.assertEqual(protocol_rev_nb, ProtocolRevision.objects.all().count()) |
|
|
117 |
|
|
|
118 |
def test_create_new_protocol_title(self): |
|
|
119 |
|
|
|
120 |
revision_def = { |
|
|
121 |
'title': 'protocol1', |
|
|
122 |
'description': 'Protocol nº1', |
|
|
123 |
'owner': 'admin', |
|
|
124 |
'metacategories' : [{ |
|
|
125 |
'title': 'Important', |
|
|
126 |
'label': 'important', |
|
|
127 |
'description': "Important.", |
|
|
128 |
'color': '#F1C40F', |
|
|
129 |
'version': 1, |
|
|
130 |
'has_comment': False |
|
|
131 |
}, { |
|
|
132 |
'title': 'Mot-clé', |
|
|
133 |
'label': 'mot-cle', |
|
|
134 |
'description': "Mot-clé.", |
|
|
135 |
'color': '#2ECC71', |
|
|
136 |
'version': 1, |
|
|
137 |
'has_comment': False |
|
|
138 |
}, { |
|
|
139 |
'title': 'Commentaire', |
|
|
140 |
'label': 'commentaire', |
|
|
141 |
'description': "Commentaire.", |
|
|
142 |
'color': '#3498DB', |
|
|
143 |
'version': 1, |
|
|
144 |
'has_comment': True |
|
|
145 |
}] |
|
|
146 |
} |
|
|
147 |
|
|
|
148 |
protocol_revision = Protocol.objects.create_new_revision(None, revision_def, None) |
|
|
149 |
|
|
|
150 |
serializer = ProtocolRevisionSerializer(protocol_revision) |
|
|
151 |
|
|
|
152 |
protocol_nb = Protocol.objects.all().count() |
|
|
153 |
protocol_rev_nb = ProtocolRevision.objects.all().count() |
|
|
154 |
metacategory_nb = Metacategory.objects.all().count() |
|
|
155 |
metacategory_rev_nb = MetacategoryRevision.objects.all().count() |
|
|
156 |
|
|
|
157 |
new_data = dict(serializer.data) |
|
|
158 |
new_data['title'] = 'protocol1-bis' |
|
|
159 |
protocol_revision = Protocol.objects.create_new_revision(protocol_revision.protocol.ext_id, new_data, None) |
|
|
160 |
|
|
|
161 |
self.assertEqual(protocol_nb, Protocol.objects.all().count()) |
|
|
162 |
self.assertEqual(metacategory_nb, Metacategory.objects.all().count()) |
|
|
163 |
self.assertEqual(metacategory_rev_nb, MetacategoryRevision.objects.all().count()) |
|
|
164 |
|
|
|
165 |
self.assertEqual(protocol_rev_nb+1, ProtocolRevision.objects.all().count()) |
|
|
166 |
|
|
|
167 |
|
|
|
168 |
def test_create_new_protocol_revision_new_categories(self): |
|
|
169 |
|
|
|
170 |
revision_def = { |
|
|
171 |
'title': 'protocol1', |
|
|
172 |
'description': 'Protocol nº1', |
|
|
173 |
'owner': 'admin', |
|
|
174 |
'metacategories' : [{ |
|
|
175 |
'title': 'Important', |
|
|
176 |
'label': 'important', |
|
|
177 |
'description': "Important.", |
|
|
178 |
'color': '#F1C40F', |
|
|
179 |
'version': 1, |
|
|
180 |
'has_comment': False |
|
|
181 |
}, { |
|
|
182 |
'title': 'Mot-clé', |
|
|
183 |
'label': 'Mot-cle', |
|
|
184 |
'description': "Mot-clé.", |
|
|
185 |
'color': '#2ECC71', |
|
|
186 |
'version': 1, |
|
|
187 |
'has_comment': False |
|
|
188 |
}, { |
|
|
189 |
'title': 'Commentaire', |
|
|
190 |
'label': 'commentaire', |
|
|
191 |
'description': "Commentaire.", |
|
|
192 |
'color': '#3498DB', |
|
|
193 |
'version': 1, |
|
|
194 |
'has_comment': True |
|
|
195 |
}] |
|
|
196 |
} |
|
|
197 |
|
|
|
198 |
protocol_revision = Protocol.objects.create_new_revision(None, revision_def, None) |
|
|
199 |
|
|
|
200 |
protocol_nb = Protocol.objects.all().count() |
|
|
201 |
protocol_rev_nb = ProtocolRevision.objects.all().count() |
|
|
202 |
metacategory_nb = Metacategory.objects.all().count() |
|
|
203 |
metacategory_rev_nb = MetacategoryRevision.objects.all().count() |
|
|
204 |
|
|
|
205 |
revision_def = { |
|
|
206 |
'version': protocol_revision.version, |
|
|
207 |
'title': 'protocol1', |
|
|
208 |
'description': 'Protocol nº1 bis', |
|
|
209 |
'owner': 'admin', |
|
|
210 |
'metacategories' : [{ |
|
|
211 |
'title': 'Important', |
|
|
212 |
'label': 'important', |
|
|
213 |
'description': "Important.", |
|
|
214 |
'color': '#F1C40F', |
|
|
215 |
'version': 1, |
|
|
216 |
'has_comment': False |
|
|
217 |
}, { |
|
|
218 |
'title': 'Mot-clé', |
|
|
219 |
'label': 'Mot-cle', |
|
|
220 |
'description': "Mot-clé.", |
|
|
221 |
'color': '#2ECC71', |
|
|
222 |
'version': 1, |
|
|
223 |
'has_comment': False |
|
|
224 |
}, { |
|
|
225 |
'title': 'Commentaire', |
|
|
226 |
'label': 'commentaire', |
|
|
227 |
'description': "Commentaire.", |
|
|
228 |
'color': '#3498DB', |
|
|
229 |
'version': 1, |
|
|
230 |
'has_comment': True |
|
|
231 |
}] |
|
|
232 |
} |
|
|
233 |
|
|
|
234 |
protocol_revision = Protocol.objects.create_new_revision(protocol_revision.protocol.ext_id, revision_def, None) |
|
|
235 |
|
|
|
236 |
self.assertEqual(protocol_nb, Protocol.objects.all().count()) |
|
|
237 |
self.assertEqual(protocol_rev_nb+1, ProtocolRevision.objects.all().count()) |
|
|
238 |
self.assertEqual(metacategory_nb+3, Metacategory.objects.all().count()) |
|
|
239 |
self.assertEqual(metacategory_rev_nb+3, MetacategoryRevision.objects.all().count()) |
|
|
240 |
|
|
|
241 |
self.assertEqual(protocol_revision.description, 'Protocol nº1 bis') |
|
|
242 |
|
|
|
243 |
|
|
|
244 |
def test_create_new_protocol_revision_no_categories_revisions(self): |
|
|
245 |
|
|
|
246 |
metacategory1 = Metacategory.objects.create( |
|
|
247 |
app=None, |
|
|
248 |
title="Important base", |
|
|
249 |
label="important-base", |
|
|
250 |
description="Important base.", |
|
|
251 |
color="#F1C41F", |
|
|
252 |
has_comment=False, |
|
|
253 |
is_default=False |
|
|
254 |
) |
|
|
255 |
metacategory_revision1 = MetacategoryRevision.objects.create( |
|
|
256 |
base=metacategory1, |
|
|
257 |
title="Important", |
|
|
258 |
label="important", |
|
|
259 |
description="Important.", |
|
|
260 |
color="#F1C40F", |
|
|
261 |
has_comment=False |
|
|
262 |
) |
|
|
263 |
|
|
|
264 |
metacategory2 = Metacategory.objects.create( |
|
|
265 |
app=None, |
|
|
266 |
title="Mot-clé base", |
|
|
267 |
label="Mot-cle-base", |
|
|
268 |
description="Mot-clé base.", |
|
|
269 |
color="#2ECC72", |
|
|
270 |
has_comment=False, |
|
|
271 |
is_default=False |
|
|
272 |
) |
|
|
273 |
metacategory_revision2 = MetacategoryRevision.objects.create( |
|
|
274 |
base=metacategory2, |
|
|
275 |
title="Mot-clé", |
|
|
276 |
label="mot-cle", |
|
|
277 |
description="Mot-clé.", |
|
|
278 |
color="#2ECC71", |
|
|
279 |
has_comment=False |
|
|
280 |
) |
|
|
281 |
|
|
|
282 |
metacategory3 = Metacategory.objects.create( |
|
|
283 |
app=None, |
|
|
284 |
title="Commentaire base", |
|
|
285 |
label="commentaire-base", |
|
|
286 |
description="Commentaire base.", |
|
|
287 |
color="#3498DC", |
|
|
288 |
has_comment=False, |
|
|
289 |
is_default=False |
|
|
290 |
) |
|
|
291 |
metacategory_revision3 = MetacategoryRevision.objects.create( |
|
|
292 |
base=metacategory3, |
|
|
293 |
title="Commentaire", |
|
|
294 |
label="commentaire", |
|
|
295 |
description="Commentaire.", |
|
|
296 |
color="#3498DB", |
|
|
297 |
has_comment=True |
|
|
298 |
) |
|
|
299 |
|
|
|
300 |
revision_def = { |
|
|
301 |
'title': 'protocol1', |
|
|
302 |
'description': 'Protocol nº1', |
|
|
303 |
'owner': 'admin', |
|
|
304 |
'metacategories' : [{ |
|
|
305 |
'id': str(metacategory_revision1.ext_id), |
|
|
306 |
'base': str(metacategory1.ext_id), |
|
|
307 |
'title': 'Important', |
|
|
308 |
'label': 'important', |
|
|
309 |
'description': "Important.", |
|
|
310 |
'color': '#F1C40F', |
|
|
311 |
'version': 1, |
|
|
312 |
'has_comment': False |
|
|
313 |
}, { |
|
|
314 |
'id': str(metacategory_revision2.ext_id), |
|
|
315 |
'base': str(metacategory2.ext_id), |
|
|
316 |
'title': 'Mot-clé', |
|
|
317 |
'label': 'mot-cle', |
|
|
318 |
'description': "Mot-clé.", |
|
|
319 |
'color': '#2ECC71', |
|
|
320 |
'version': 1, |
|
|
321 |
'has_comment': False |
|
|
322 |
}, { |
|
|
323 |
'id': str(metacategory_revision3.ext_id), |
|
|
324 |
'base': str(metacategory3.ext_id), |
|
|
325 |
'title': 'Commentaire', |
|
|
326 |
'label': 'commentaire', |
|
|
327 |
'description': "Commentaire.", |
|
|
328 |
'color': '#3498DB', |
|
|
329 |
'version': 1, |
|
|
330 |
'has_comment': True |
|
|
331 |
}] |
|
|
332 |
} |
|
|
333 |
|
|
|
334 |
protocol_nb = Protocol.objects.all().count() |
|
|
335 |
protocol_rev_nb = ProtocolRevision.objects.all().count() |
|
|
336 |
metacategory_nb = Metacategory.objects.all().count() |
|
|
337 |
metacategory_rev_nb = MetacategoryRevision.objects.all().count() |
|
|
338 |
|
|
|
339 |
protocol_revision = Protocol.objects.create_new_revision(None, revision_def, None) |
|
|
340 |
|
|
|
341 |
self.assertEqual(protocol_nb+1, Protocol.objects.all().count()) |
|
|
342 |
self.assertEqual(protocol_rev_nb+1, ProtocolRevision.objects.all().count()) |
|
|
343 |
self.assertEqual(metacategory_nb, Metacategory.objects.all().count()) |
|
|
344 |
self.assertEqual(metacategory_rev_nb, MetacategoryRevision.objects.all().count()) |
|
|
345 |
|
|
|
346 |
|
|
|
347 |
|
|
|
348 |
def test_create_new_protocol_revision_one_categories_revisions(self): |
|
|
349 |
|
|
|
350 |
metacategory1 = Metacategory.objects.create( |
|
|
351 |
app=None, |
|
|
352 |
title="Important base", |
|
|
353 |
label="important-base", |
|
|
354 |
description="Important base.", |
|
|
355 |
color="#F1C41F", |
|
|
356 |
has_comment=False, |
|
|
357 |
is_default=False |
|
|
358 |
) |
|
|
359 |
metacategory_revision1 = MetacategoryRevision.objects.create( |
|
|
360 |
base=metacategory1, |
|
|
361 |
title="Important", |
|
|
362 |
label="important", |
|
|
363 |
description="Important.", |
|
|
364 |
color="#F1C40F", |
|
|
365 |
has_comment=False |
|
|
366 |
) |
|
|
367 |
|
|
|
368 |
metacategory2 = Metacategory.objects.create( |
|
|
369 |
app=None, |
|
|
370 |
title="Mot-clé base", |
|
|
371 |
label="mot-cle-base", |
|
|
372 |
description="Mot-clé base.", |
|
|
373 |
color="#2ECC72", |
|
|
374 |
has_comment=False, |
|
|
375 |
is_default=False |
|
|
376 |
) |
|
|
377 |
metacategory_revision2 = MetacategoryRevision.objects.create( |
|
|
378 |
base=metacategory2, |
|
|
379 |
title="Mot-clé", |
|
|
380 |
label="mot-cle", |
|
|
381 |
description="Mot-clé.", |
|
|
382 |
color="#2ECC71", |
|
|
383 |
has_comment=False |
|
|
384 |
) |
|
|
385 |
|
|
|
386 |
metacategory3 = Metacategory.objects.create( |
|
|
387 |
app=None, |
|
|
388 |
title="Commentaire base", |
|
|
389 |
label="commentaire-base", |
|
|
390 |
description="Commentaire base.", |
|
|
391 |
color="#3498DC", |
|
|
392 |
has_comment=False, |
|
|
393 |
is_default=False |
|
|
394 |
) |
|
|
395 |
metacategory_revision3 = MetacategoryRevision.objects.create( |
|
|
396 |
base=metacategory3, |
|
|
397 |
title="Commentaire", |
|
|
398 |
label="commentaire", |
|
|
399 |
description="Commentaire.", |
|
|
400 |
color="#3498DB", |
|
|
401 |
has_comment=True |
|
|
402 |
) |
|
|
403 |
|
|
|
404 |
revision_def = { |
|
|
405 |
'title': 'protocol1', |
|
|
406 |
'description': 'Protocol nº1', |
|
|
407 |
'owner': 'admin', |
|
|
408 |
'metacategories' : [{ |
|
|
409 |
'id': str(metacategory_revision1.ext_id), |
|
|
410 |
'base': str(metacategory1.ext_id), |
|
|
411 |
'title': 'Important', |
|
|
412 |
'label': 'important', |
|
|
413 |
'description': "Important.", |
|
|
414 |
'color': '#F1C40F', |
|
|
415 |
'version': 1, |
|
|
416 |
'has_comment': False |
|
|
417 |
}, { |
|
|
418 |
'id': str(metacategory_revision2.ext_id), |
|
|
419 |
'base': str(metacategory2.ext_id), |
|
|
420 |
'title': 'Mot-clé', |
|
|
421 |
'label': 'mot-cle', |
|
|
422 |
'description': "Mot-clé.", |
|
|
423 |
'color': '#2ECC71', |
|
|
424 |
'version': 1, |
|
|
425 |
'has_comment': False |
|
|
426 |
}, { |
|
|
427 |
'id': str(metacategory_revision3.ext_id), |
|
|
428 |
'base': str(metacategory3.ext_id), |
|
|
429 |
'title': 'Commentaire amélioré', |
|
|
430 |
'label': 'commentaire-ameliore', |
|
|
431 |
'description': "Commentaire.", |
|
|
432 |
'color': '#3498DB', |
|
|
433 |
'version': 1, |
|
|
434 |
'has_comment': True |
|
|
435 |
}] |
|
|
436 |
} |
|
|
437 |
|
|
|
438 |
protocol_nb = Protocol.objects.all().count() |
|
|
439 |
protocol_rev_nb = ProtocolRevision.objects.all().count() |
|
|
440 |
metacategory_nb = Metacategory.objects.all().count() |
|
|
441 |
metacategory_rev_nb = MetacategoryRevision.objects.all().count() |
|
|
442 |
|
|
|
443 |
protocol_revision = Protocol.objects.create_new_revision(None, revision_def, None) |
|
|
444 |
|
|
|
445 |
self.assertEqual(protocol_nb+1, Protocol.objects.all().count()) |
|
|
446 |
self.assertEqual(protocol_rev_nb+1, ProtocolRevision.objects.all().count()) |
|
|
447 |
self.assertEqual(metacategory_nb, Metacategory.objects.all().count()) |
|
|
448 |
self.assertEqual(metacategory_rev_nb+1, MetacategoryRevision.objects.all().count()) |
|
|
449 |
|
|
|
450 |
def test_create_with_revision(self): |
|
|
451 |
metacategory1 = Metacategory.objects.create_with_revision( |
|
|
452 |
app=self.user1, |
|
|
453 |
title="Important base", |
|
|
454 |
label="important-base", |
|
|
455 |
description="Important base.", |
|
|
456 |
color="#F1C41F", |
|
|
457 |
has_comment=False, |
|
|
458 |
is_default=False |
|
|
459 |
) |
|
|
460 |
|
|
|
461 |
self.assertEqual(1, metacategory1.revisions.count()) |
|
|
462 |
self.assertEqual(5, MetacategoryRevision.objects.all().count()) # There are the 4 created by default |
|
|
463 |
revision = metacategory1.revisions.all()[0] |
|
|
464 |
self.assertEqual(metacategory1.title, revision.title) |
|
|
465 |
self.assertEqual(metacategory1.description, revision.description) |
|
|
466 |
self.assertEqual(metacategory1.color, revision.color) |
|
|
467 |
self.assertEqual(metacategory1.has_comment, revision.has_comment) |
|
|
468 |
|
|
|
469 |
|
|
|
470 |
def test_create_new_protocol_default(self): |
|
|
471 |
metacategory1 = Metacategory.objects.create_with_revision( |
|
|
472 |
app=None, |
|
|
473 |
title="Important base", |
|
|
474 |
label="important_base", |
|
|
475 |
description="Important base.", |
|
|
476 |
color="#F1C41F", |
|
|
477 |
has_comment=False, |
|
|
478 |
is_default=True |
|
|
479 |
) |
|
|
480 |
|
|
|
481 |
metacategory2 = Metacategory.objects.create_with_revision( |
|
|
482 |
app=None, |
|
|
483 |
title="Mot-clé base", |
|
|
484 |
label="mot-clef-base", |
|
|
485 |
description="Mot-clé base.", |
|
|
486 |
color="#2ECC72", |
|
|
487 |
has_comment=False, |
|
|
488 |
is_default=True |
|
|
489 |
) |
|
|
490 |
|
|
|
491 |
metacategory3 = Metacategory.objects.create_with_revision( |
|
|
492 |
app=None, |
|
|
493 |
title="Commentaire base", |
|
|
494 |
label="commentaire-base", |
|
|
495 |
description="Commentaire base.", |
|
|
496 |
color="#3498DC", |
|
|
497 |
has_comment=False, |
|
|
498 |
is_default=True |
|
|
499 |
) |
|
|
500 |
|
|
|
501 |
metacategory4 = Metacategory.objects.create_with_revision( |
|
|
502 |
app=None, |
|
|
503 |
title="Commentaire base", |
|
|
504 |
label="commentaire-base", |
|
|
505 |
description="Commentaire base.", |
|
|
506 |
color="#3498DC", |
|
|
507 |
has_comment=False, |
|
|
508 |
is_default=False |
|
|
509 |
) |
|
|
510 |
|
|
|
511 |
protocol = Protocol.objects.create_from_default('Default', 'Default protocol', 'admin', None) |
|
|
512 |
|
|
|
513 |
self.assertEqual(3, Protocol.objects.count()) # 1 protocol for each user (group) + 1 |
|
|
514 |
self.assertEqual(3, ProtocolRevision.objects.count()) # 1 protocol rev for each user (group) + 1 |
|
|
515 |
|
|
|
516 |
self.assertEqual(1, protocol.revisions.count()) |
|
|
517 |
protocol_revision = protocol.revisions.all()[0] |
|
|
518 |
self.assertEqual(7, protocol_revision.metacategories.count()) # There are the 4 created by default |
|
|
519 |
title_set = set([mc.title for mc in protocol_revision.metacategories.all()]) |
|
|
520 |
self.assertEqual(set(['trouble', 'important', 'commentaire', 'mot-clef', "Mot-clé base","Commentaire base","Important base"]), title_set) |
|
|
521 |
|
|
|
522 |
|
|
|
523 |
def test_create_new_protocol_default_revision(self): |
|
|
524 |
metacategory1 = Metacategory.objects.create_with_revision( |
|
|
525 |
app=None, |
|
|
526 |
title="Important base", |
|
|
527 |
label="important-base", |
|
|
528 |
description="Important base.", |
|
|
529 |
color="#F1C41F", |
|
|
530 |
has_comment=False, |
|
|
531 |
is_default=True |
|
|
532 |
) |
|
|
533 |
|
|
|
534 |
metacategory_revision1 = MetacategoryRevision.objects.create( |
|
|
535 |
base=metacategory1, |
|
|
536 |
title="Important", |
|
|
537 |
label="important", |
|
|
538 |
description="Important.", |
|
|
539 |
color="#F1C40F", |
|
|
540 |
has_comment=False |
|
|
541 |
) |
|
|
542 |
|
|
|
543 |
|
|
|
544 |
metacategory2 = Metacategory.objects.create_with_revision( |
|
|
545 |
app=None, |
|
|
546 |
title="Mot-clé base", |
|
|
547 |
label="mot-clef-base", |
|
|
548 |
description="Mot-clé base.", |
|
|
549 |
color="#2ECC72", |
|
|
550 |
has_comment=False, |
|
|
551 |
is_default=True |
|
|
552 |
) |
|
|
553 |
|
|
|
554 |
metacategory_revision2 = MetacategoryRevision.objects.create( |
|
|
555 |
base=metacategory2, |
|
|
556 |
title="Mot-clé", |
|
|
557 |
label="mot-clef", |
|
|
558 |
description="Mot-clé.", |
|
|
559 |
color="#2ECC71", |
|
|
560 |
has_comment=False |
|
|
561 |
) |
|
|
562 |
|
|
|
563 |
metacategory3 = Metacategory.objects.create_with_revision( |
|
|
564 |
app=None, |
|
|
565 |
title="Commentaire base", |
|
|
566 |
label="commentaire-base", |
|
|
567 |
description="Commentaire base.", |
|
|
568 |
color="#3498DC", |
|
|
569 |
has_comment=False, |
|
|
570 |
is_default=True |
|
|
571 |
) |
|
|
572 |
|
|
|
573 |
metacategory_revision3 = MetacategoryRevision.objects.create( |
|
|
574 |
base=metacategory3, |
|
|
575 |
title="Commentaire", |
|
|
576 |
label="commentaire", |
|
|
577 |
description="Commentaire.", |
|
|
578 |
color="#3498DB", |
|
|
579 |
has_comment=True |
|
|
580 |
) |
|
|
581 |
|
|
|
582 |
|
|
|
583 |
protocol = Protocol.objects.create_from_default('Default', 'Default protocol', 'admin', None) |
|
|
584 |
|
|
|
585 |
self.assertEqual(3, Protocol.objects.count()) # 1 protocol for each user (group) + 1 |
|
|
586 |
self.assertEqual(3, ProtocolRevision.objects.count()) # 1 protocol rev for each user (group) + 1 |
|
|
587 |
|
|
|
588 |
self.assertEqual(1, protocol.revisions.count()) |
|
|
589 |
protocol_revision = protocol.revisions.all()[0] |
|
|
590 |
self.assertEqual(7, protocol_revision.metacategories.count()) # There are the 4 created by default |
|
|
591 |
title_set = set([mc.title for mc in protocol_revision.metacategories.all()]) |
|
|
592 |
self.assertEqual(set(['trouble', 'important', 'commentaire', 'mot-clef', 'Mot-clé base', 'Commentaire base', 'Important base']), title_set) |
|
|
593 |
|
|
|
594 |
|
|
|
595 |
def test_create_new_protocol_default_user(self): |
|
|
596 |
metacategory1 = Metacategory.objects.create_with_revision( |
|
|
597 |
app=None, |
|
|
598 |
title="Important base", |
|
|
599 |
label="important-base", |
|
|
600 |
description="Important base.", |
|
|
601 |
color="#F1C41F", |
|
|
602 |
has_comment=False, |
|
|
603 |
is_default=True |
|
|
604 |
) |
|
|
605 |
|
|
|
606 |
metacategory2 = Metacategory.objects.create_with_revision( |
|
|
607 |
app=None, |
|
|
608 |
title="Mot-clé base", |
|
|
609 |
label="mot-clef-base", |
|
|
610 |
description="Mot-clé base.", |
|
|
611 |
color="#2ECC72", |
|
|
612 |
has_comment=False, |
|
|
613 |
is_default=True |
|
|
614 |
) |
|
|
615 |
|
|
|
616 |
metacategory3 = Metacategory.objects.create_with_revision( |
|
|
617 |
app=None, |
|
|
618 |
title="Commentaire base", |
|
|
619 |
label="commentaire-base", |
|
|
620 |
description="Commentaire base.", |
|
|
621 |
color="#3498DC", |
|
|
622 |
has_comment=False, |
|
|
623 |
is_default=True |
|
|
624 |
) |
|
|
625 |
|
|
|
626 |
metacategory1bis = Metacategory.objects.create_with_revision( |
|
|
627 |
app=self.user2, |
|
|
628 |
title="Important base bis", |
|
|
629 |
label="important-base-bis", |
|
|
630 |
description="Important base bis.", |
|
|
631 |
color="#F1C41F", |
|
|
632 |
has_comment=False, |
|
|
633 |
is_default=True |
|
|
634 |
) |
|
|
635 |
|
|
|
636 |
metacategory2bis = Metacategory.objects.create_with_revision( |
|
|
637 |
app=self.user2, |
|
|
638 |
title="Mot-clé base bis", |
|
|
639 |
label="mot-cle-base-bis", |
|
|
640 |
description="Mot-clé base bis.", |
|
|
641 |
color="#2ECC72", |
|
|
642 |
has_comment=False, |
|
|
643 |
is_default=True |
|
|
644 |
) |
|
|
645 |
|
|
|
646 |
|
|
|
647 |
protocol = Protocol.objects.create_from_default('Default', 'Default protocol', 'admin', None) |
|
|
648 |
|
|
|
649 |
self.assertEqual(3, Protocol.objects.count()) # 1 protocol for each user (group) + 1 |
|
|
650 |
self.assertEqual(3, ProtocolRevision.objects.count()) # 1 protocol rev for each user (group) + 1 |
|
|
651 |
|
|
|
652 |
self.assertEqual(1, protocol.revisions.count()) |
|
|
653 |
protocol_revision = protocol.revisions.all()[0] |
|
|
654 |
self.assertEqual(7, protocol_revision.metacategories.count()) # There are the 4 created by default |
|
|
655 |
title_set = set([mc.title for mc in protocol_revision.metacategories.all()]) |
|
|
656 |
self.assertEqual(set(['trouble', 'important', 'commentaire', 'mot-clef', 'Mot-clé base', 'Commentaire base', 'Important base']), title_set) |