|
1
|
|
|
#!/usr/bin/env python3 |
|
2
|
|
|
# -*- coding: utf-8 -*- |
|
3
|
|
|
""" |
|
4
|
|
|
Created on Mon Sep 9 17:24:54 2019 |
|
5
|
|
|
|
|
6
|
|
|
@author: Paolo Cozzi <[email protected]> |
|
7
|
|
|
""" |
|
8
|
|
|
|
|
9
|
|
|
from django.test import TestCase |
|
10
|
|
|
|
|
11
|
|
|
from image_app.models import Submission, Sample |
|
12
|
|
|
from common.constants import NEED_REVISION, STATUSES |
|
13
|
|
|
from common.tests import WebSocketMixin |
|
14
|
|
|
|
|
15
|
|
|
from .common import SampleFeaturesMixin |
|
16
|
|
|
from ..tasks import BatchDeleteSamples |
|
17
|
|
|
|
|
18
|
|
|
|
|
19
|
|
|
class BatchDeleteSamplesTest( |
|
20
|
|
|
SampleFeaturesMixin, WebSocketMixin, TestCase): |
|
21
|
|
|
|
|
22
|
|
|
def setUp(self): |
|
23
|
|
|
# calling base methods |
|
24
|
|
|
super().setUp() |
|
25
|
|
|
|
|
26
|
|
|
# get a submission object |
|
27
|
|
|
self.submission = Submission.objects.get(pk=1) |
|
28
|
|
|
|
|
29
|
|
|
# setting tasks |
|
30
|
|
|
self.my_task = BatchDeleteSamples() |
|
31
|
|
|
|
|
32
|
|
|
def test_delete_sample(self): |
|
33
|
|
|
sample_ids = ['Siems_0722_393449'] |
|
34
|
|
|
|
|
35
|
|
|
# calling task and delete a sample |
|
36
|
|
|
res = self.my_task.run( |
|
37
|
|
|
submission_id=self.submission.id, |
|
38
|
|
|
sample_ids=sample_ids) |
|
39
|
|
|
|
|
40
|
|
|
self.assertEqual(res, "success") |
|
41
|
|
|
|
|
42
|
|
|
# no samples |
|
43
|
|
|
n_samples = Sample.objects.count() |
|
44
|
|
|
self.assertEqual(n_samples, 0) |
|
45
|
|
|
|
|
46
|
|
|
# updating validation messages |
|
47
|
|
|
|
|
48
|
|
|
# calling a WebSocketMixin method |
|
49
|
|
|
# no validation message since no data in validation table |
|
50
|
|
|
self.check_message( |
|
51
|
|
|
message=STATUSES.get_value_display(NEED_REVISION), |
|
52
|
|
|
notification_message=( |
|
53
|
|
|
"You've removed %s " |
|
54
|
|
|
"samples. Rerun validation please!" % len(sample_ids))) |
|
55
|
|
|
|