44import taskw .task
55
66from bugwarrior import db
7+ from bugwarrior .types import CollectedIssue
78
89from .base import ConfigTest
910
@@ -58,19 +59,8 @@ def test_handles_missing_tags(self):
5859
5960
6061class TestSynchronize (ConfigTest ):
61- def test_synchronize (self ):
62- def remove_non_deterministic_keys (tasks ):
63- for status in ['pending' , 'completed' ]:
64- for task in tasks [status ]:
65- del task ['modified' ]
66- del task ['entry' ]
67- del task ['uuid' ]
68- task ['tags' ] = sorted (task ['tags' ])
69- return tasks
70-
71- def get_tasks (tw ):
72- return remove_non_deterministic_keys (tw .load_tasks ())
73-
62+ def setUp (self ):
63+ super ().setUp ()
7464 self .config = {
7565 'general' : {
7666 'targets' : ['my_service' ],
@@ -84,10 +74,38 @@ def get_tasks(tw):
8474 'token' : 'abc123' ,
8575 },
8676 }
87- bwconfig = self .validate ()
77+ self .bwconfig = self .validate ()
78+ self .tw = taskw .TaskWarrior (self .taskrc )
79+
80+ def synchronize (self , issues_data ):
81+
82+ issue_generator = [
83+ CollectedIssue (
84+ taskwarrior_data = copy .deepcopy (issue_data ),
85+ target = "my_service" ,
86+ identifier = "abcd" ,
87+ )
88+ for issue_data in issues_data
89+ ]
90+ db .synchronize (iter (issue_generator ), self .bwconfig )
91+
92+ def remove_non_deterministic_keys (self , tasks ):
93+ for status in ['pending' , 'completed' ]:
94+ for task in tasks [status ]:
95+ del task ['modified' ]
96+ del task ['entry' ]
97+ del task ['uuid' ]
98+ task ['tags' ] = sorted (task ['tags' ])
8899
89- tw = taskw .TaskWarrior (self .taskrc )
90- self .assertEqual (tw .load_tasks (), {'completed' : [], 'pending' : []})
100+ return tasks
101+
102+ def get_tasks (self ):
103+
104+ return self .remove_non_deterministic_keys (self .tw .load_tasks ())
105+
106+ def test_synchronize (self ):
107+
108+ self .assertEqual (self .tw .load_tasks (), {'completed' : [], 'pending' : []})
91109
92110 issue = {
93111 'description' : 'Blah blah blah. ☃' ,
@@ -96,7 +114,6 @@ def get_tasks(tw):
96114 'githuburl' : 'https://example.com' ,
97115 'priority' : 'M' ,
98116 'tags' : ['foo' ],
99- 'target' : 'my_service' ,
100117 }
101118 duplicate_issue = copy .deepcopy (issue )
102119 duplicate_issue ['tags' ] = ['bar' ]
@@ -107,11 +124,10 @@ def get_tasks(tw):
107124 # These should be de-duplicated in db.synchronize before
108125 # writing out to taskwarrior.
109126 # https://github.com/ralphbean/bugwarrior/issues/601
110- issue_generator = iter ((copy .deepcopy (issue ), duplicate_issue ))
111- db .synchronize (issue_generator , bwconfig )
127+ self .synchronize ([issue , duplicate_issue ])
112128
113129 self .assertEqual (
114- get_tasks (tw ),
130+ self . get_tasks (),
115131 {
116132 'completed' : [],
117133 'pending' : [
@@ -135,11 +151,10 @@ def get_tasks(tw):
135151
136152 # Change static field
137153 issue ['project' ] = 'other_project'
138-
139- db .synchronize (iter ((copy .deepcopy (issue ),)), bwconfig )
154+ self .synchronize ([issue ])
140155
141156 self .assertEqual (
142- get_tasks (tw ),
157+ self . get_tasks (),
143158 {
144159 'completed' : [],
145160 'pending' : [
@@ -159,11 +174,11 @@ def get_tasks(tw):
159174 )
160175
161176 # TEST CLOSED ISSUE.
162- db .synchronize (iter (()), bwconfig )
177+ self .synchronize ([] )
163178
164- completed_tasks = tw .load_tasks ()
179+ completed_tasks = self . tw .load_tasks ()
165180
166- tasks = remove_non_deterministic_keys (copy .deepcopy (completed_tasks ))
181+ tasks = self . remove_non_deterministic_keys (copy .deepcopy (completed_tasks ))
167182 del tasks ['completed' ][0 ]['end' ]
168183 self .assertEqual (
169184 tasks ,
@@ -186,14 +201,14 @@ def get_tasks(tw):
186201 )
187202
188203 # TEST REOPENED ISSUE
189- db .synchronize (iter (( copy . deepcopy ( issue ),)), bwconfig )
204+ self .synchronize ([ issue ] )
190205
191- tasks = tw .load_tasks ()
206+ tasks = self . tw .load_tasks ()
192207 self .assertEqual (
193208 completed_tasks ['completed' ][0 ]['uuid' ], tasks ['pending' ][0 ]['uuid' ]
194209 )
195210
196- tasks = remove_non_deterministic_keys (tasks )
211+ tasks = self . remove_non_deterministic_keys (tasks )
197212 self .assertEqual (
198213 tasks ,
199214 {
0 commit comments