@@ 132-202 (lines=71) @@ | ||
129 | "waiting for data validation") |
|
130 | ||
131 | ||
132 | class NoValidateViewTest(TestMixin, TestCase): |
|
133 | @patch('validation.views.ValidateTask.delay') |
|
134 | def setUp(self, my_validation): |
|
135 | # call base methods |
|
136 | super(NoValidateViewTest, self).setUp() |
|
137 | ||
138 | # get a submission object |
|
139 | submission = Submission.objects.get(pk=1) |
|
140 | ||
141 | # track submission ID |
|
142 | self.submission_id = submission.id |
|
143 | ||
144 | # get the url for dashboard |
|
145 | self.url = reverse('validation:validate') |
|
146 | ||
147 | # track my patched function |
|
148 | self.my_validation = my_validation |
|
149 | ||
150 | def __common_stuff(self, status): |
|
151 | """Common function for statuses""" |
|
152 | ||
153 | # get submission |
|
154 | submission = Submission.objects.get(pk=self.submission_id) |
|
155 | ||
156 | # update status and save |
|
157 | submission.status = status |
|
158 | submission.save() |
|
159 | ||
160 | # call valiate views with cyrrent status WAITING |
|
161 | response = self.client.post( |
|
162 | self.url, { |
|
163 | 'submission_id': self.submission_id |
|
164 | } |
|
165 | ) |
|
166 | ||
167 | # assert redirect |
|
168 | url = reverse('submissions:detail', kwargs={'pk': self.submission_id}) |
|
169 | self.assertRedirects(response, url) |
|
170 | ||
171 | # get number of call (equal to first call) |
|
172 | self.assertEqual(self.my_validation.call_count, 0) |
|
173 | ||
174 | def test_submission_waiting(self): |
|
175 | """check no validation with submission status WAITING""" |
|
176 | ||
177 | # valutate status and no function called |
|
178 | self.__common_stuff(WAITING) |
|
179 | ||
180 | def test_submission_ready(self): |
|
181 | """check no validation with submission status READY""" |
|
182 | ||
183 | # valutate status and no function called |
|
184 | self.__common_stuff(READY) |
|
185 | ||
186 | def test_submission_error(self): |
|
187 | """check no validation with submission status ERROR""" |
|
188 | ||
189 | # valutate status and no function called |
|
190 | self.__common_stuff(ERROR) |
|
191 | ||
192 | def test_submission_submitted(self): |
|
193 | """check no validation with submission status SUBMITTED""" |
|
194 | ||
195 | # valutate status and no function called |
|
196 | self.__common_stuff(SUBMITTED) |
|
197 | ||
198 | def test_submission_completed(self): |
|
199 | """check no validation with submission status COMPLETED""" |
|
200 | ||
201 | # valutate status and no function called |
|
202 | self.__common_stuff(COMPLETED) |
|
203 | ||
204 | ||
205 | class InvalidValidateViewTest(TestMixin, TestCase): |
@@ 328-394 (lines=67) @@ | ||
325 | # --- check status before submission |
|
326 | ||
327 | ||
328 | class NoSubmitViewTest(TestMixin, MessageMixinTestCase, TestCase): |
|
329 | """No submission if status is not OK""" |
|
330 | ||
331 | @patch('biosample.views.SplitSubmissionTask.delay') |
|
332 | def setUp(self, my_submit): |
|
333 | # call base methods |
|
334 | super(NoSubmitViewTest, self).setUp() |
|
335 | ||
336 | # get a submission object |
|
337 | submission = Submission.objects.get(pk=1) |
|
338 | ||
339 | # track submission ID |
|
340 | self.submission_id = submission.id |
|
341 | ||
342 | # set URL |
|
343 | self.url = reverse('biosample:submit') |
|
344 | ||
345 | # track my patched function |
|
346 | self.my_submit = my_submit |
|
347 | ||
348 | def __common_stuff(self, status): |
|
349 | """Common function for statuses""" |
|
350 | ||
351 | # get submission |
|
352 | submission = Submission.objects.get(pk=self.submission_id) |
|
353 | ||
354 | # update status and save |
|
355 | submission.status = status |
|
356 | submission.save() |
|
357 | ||
358 | # call valiate views with cyrrent status WAITING |
|
359 | response = self.client.post( |
|
360 | self.url, { |
|
361 | 'submission_id': self.submission_id |
|
362 | } |
|
363 | ) |
|
364 | ||
365 | # assert redirect |
|
366 | url = reverse('submissions:detail', kwargs={'pk': self.submission_id}) |
|
367 | self.assertRedirects(response, url) |
|
368 | ||
369 | # get number of call (equal to first call) |
|
370 | self.assertEqual(self.my_submit.call_count, 0) |
|
371 | ||
372 | def test_submission_waiting(self): |
|
373 | """check no submission with submission status WAITING""" |
|
374 | ||
375 | # valutate status and no function called |
|
376 | self.__common_stuff(WAITING) |
|
377 | ||
378 | def test_submission_error(self): |
|
379 | """check no submission with submission status ERROR""" |
|
380 | ||
381 | # valutate status and no function called |
|
382 | self.__common_stuff(ERROR) |
|
383 | ||
384 | def test_submission_submitted(self): |
|
385 | """check no submission with submission status SUBMITTED""" |
|
386 | ||
387 | # valutate status and no function called |
|
388 | self.__common_stuff(SUBMITTED) |
|
389 | ||
390 | def test_submission_completed(self): |
|
391 | """check no submission with submission status COMPLETED""" |
|
392 | ||
393 | # valutate status and no function called |
|
394 | self.__common_stuff(COMPLETED) |
|
395 | ||
396 | ||
397 | # errors with form |