1
1
from django .test import TestCase
2
2
3
3
from openarchiefbeheer .accounts .tests .factories import UserFactory
4
+ from openarchiefbeheer .zaken .tests .factories import ZaakFactory
4
5
5
6
from ..constants import ListRole
6
- from ..utils import process_new_assignees
7
- from .factories import DestructionListAssigneeFactory , DestructionListFactory
7
+ from ..utils import process_new_assignees , resync_items_and_zaken
8
+ from .factories import (
9
+ DestructionListAssigneeFactory ,
10
+ DestructionListFactory ,
11
+ DestructionListItemFactory ,
12
+ )
8
13
9
14
10
15
class UtilsTest (TestCase ):
@@ -29,3 +34,34 @@ def test_process_assignees(self):
29
34
self .assertEqual (2 , new_assignees .count ())
30
35
self .assertEqual (users [0 ].pk , new_assignees [0 ].user .pk )
31
36
self .assertEqual (users [1 ].pk , new_assignees [1 ].user .pk )
37
+
38
+ def test_resync_zaken (self ):
39
+ ZaakFactory .create (url = "http://zaken.nl/1" )
40
+ ZaakFactory .create (url = "http://zaken.nl/2" )
41
+ item1 = DestructionListItemFactory .create (_zaak_url = "http://zaken.nl/1" )
42
+ item2 = DestructionListItemFactory .create (_zaak_url = "http://zaken.nl/2" )
43
+
44
+ resync_items_and_zaken ()
45
+
46
+ item1 .refresh_from_db ()
47
+ item2 .refresh_from_db ()
48
+
49
+ self .assertIsNotNone (item1 .zaak )
50
+ self .assertEqual (item1 .zaak .url , "http://zaken.nl/1" )
51
+ self .assertIsNotNone (item2 .zaak )
52
+ self .assertEqual (item2 .zaak .url , "http://zaken.nl/2" )
53
+
54
+ def test_resync_zaken_missing (self ):
55
+ ZaakFactory .create (url = "http://zaken.nl/1" )
56
+ ZaakFactory .create (url = "http://zaken.nl/2" )
57
+ item1 = DestructionListItemFactory .create (_zaak_url = "http://zaken.nl/1" )
58
+ item2 = DestructionListItemFactory .create (_zaak_url = "http://zaken.nl/3" )
59
+
60
+ resync_items_and_zaken ()
61
+
62
+ item1 .refresh_from_db ()
63
+ item2 .refresh_from_db ()
64
+
65
+ self .assertIsNotNone (item1 .zaak )
66
+ self .assertEqual (item1 .zaak .url , "http://zaken.nl/1" )
67
+ self .assertIsNone (item2 .zaak )
0 commit comments