Code Duplication    Length = 94-97 lines in 2 locations

django-data/image/animals/tests/test_tasks.py 1 location

@@ 22-118 (lines=97) @@
19
from ..tasks import BatchDeleteAnimals
20
21
22
class BatchDeleteAnimalsTest(
23
        AnimalFeaturesMixin, WebSocketMixin, TestCase):
24
25
    def setUp(self):
26
        # calling base methods
27
        super().setUp()
28
29
        # get a submission object
30
        self.submission = Submission.objects.get(pk=1)
31
        self.submission_id = self.submission.id
32
33
        # setting animals to delete
34
        self.animal_ids = [
35
            'ANIMAL:::ID:::132713',
36
            'ANIMAL:::ID:::son',
37
            'ANIMAL:::ID:::mother']
38
39
        # setting tasks
40
        self.my_task = BatchDeleteAnimals()
41
42
    def test_on_failure(self):
43
        """Testing on failure methods"""
44
45
        exc = Exception("Test")
46
        task_id = "test_task_id"
47
        args = [self.submission_id, self.animal_ids]
48
        kwargs = {}
49
        einfo = ExceptionInfo
50
51
        # call on_failure method
52
        self.my_task.on_failure(exc, task_id, args, kwargs, einfo)
53
54
        # check submission status and message
55
        self.submission.refresh_from_db()
56
57
        # check submission.state changed
58
        self.assertEqual(self.submission.status, ERROR)
59
        self.assertEqual(
60
            self.submission.message,
61
            "Error in animal batch delete: Test")
62
63
        # test email sent
64
        self.assertGreater(len(mail.outbox), 0)
65
66
        # read email
67
        email = mail.outbox[0]
68
69
        self.assertEqual(
70
            "Error in animal batch delete for submission: 1",
71
            email.subject)
72
73
        self.check_message(
74
            message='Error',
75
            notification_message='Error in animal batch delete: Test')
76
77
    def test_delete_animal(self):
78
        # calling task and delete a animal
79
        res = self.my_task.run(
80
            submission_id=self.submission_id,
81
            animal_ids=self.animal_ids)
82
83
        self.assertEqual(res, "success")
84
85
        # no animals
86
        n_animals = Animal.objects.count()
87
        self.assertEqual(n_animals, 0)
88
89
        # updating validation messages
90
91
        # calling a WebSocketMixin method
92
        # no validation message since no data in validation table
93
        self.check_message(
94
            message=STATUSES.get_value_display(NEED_REVISION),
95
            notification_message=(
96
                "You've removed %s "
97
                "animals. Rerun validation please!" % len(self.animal_ids)))
98
99
    def test_delete_animal_not_exists(self):
100
        # calling task and delete a animal
101
        res = self.my_task.run(
102
            submission_id=self.submission_id,
103
            animal_ids=["meow"])
104
105
        self.assertEqual(res, "success")
106
107
        # all animals remain
108
        n_animals = Animal.objects.count()
109
        self.assertEqual(n_animals, 3)
110
111
        # updating validation messages
112
113
        # calling a WebSocketMixin method
114
        # no validation message since no data in validation table
115
        self.check_message(
116
            message=STATUSES.get_value_display(NEED_REVISION),
117
            notification_message=(
118
                "You've removed 0 animals. It wasn't possible to find records "
119
                "with these ids: meow. Rerun validation please!")
120
        )
121

django-data/image/samples/tests/test_tasks.py 1 location

@@ 22-115 (lines=94) @@
19
from ..tasks import BatchDeleteSamples
20
21
22
class BatchDeleteSamplesTest(
23
        SampleFeaturesMixin, WebSocketMixin, TestCase):
24
25
    def setUp(self):
26
        # calling base methods
27
        super().setUp()
28
29
        # get a submission object
30
        self.submission = Submission.objects.get(pk=1)
31
        self.submission_id = self.submission.id
32
33
        # setting samples to delete
34
        self.sample_ids = ['Siems_0722_393449']
35
36
        # setting tasks
37
        self.my_task = BatchDeleteSamples()
38
39
    def test_on_failure(self):
40
        """Testing on failure methods"""
41
42
        exc = Exception("Test")
43
        task_id = "test_task_id"
44
        args = [self.submission_id, self.sample_ids]
45
        kwargs = {}
46
        einfo = ExceptionInfo
47
48
        # call on_failure method
49
        self.my_task.on_failure(exc, task_id, args, kwargs, einfo)
50
51
        # check submission status and message
52
        self.submission.refresh_from_db()
53
54
        # check submission.state changed
55
        self.assertEqual(self.submission.status, ERROR)
56
        self.assertEqual(
57
            self.submission.message,
58
            "Error in sample batch delete: Test")
59
60
        # test email sent
61
        self.assertGreater(len(mail.outbox), 0)
62
63
        # read email
64
        email = mail.outbox[0]
65
66
        self.assertEqual(
67
            "Error in sample batch delete for submission: 1",
68
            email.subject)
69
70
        self.check_message(
71
            message='Error',
72
            notification_message='Error in sample batch delete: Test')
73
74
    def test_delete_sample(self):
75
        # calling task and delete a sample
76
        res = self.my_task.run(
77
            submission_id=self.submission.id,
78
            sample_ids=self.sample_ids)
79
80
        self.assertEqual(res, "success")
81
82
        # no samples
83
        n_samples = Sample.objects.count()
84
        self.assertEqual(n_samples, 0)
85
86
        # updating validation messages
87
88
        # calling a WebSocketMixin method
89
        # no validation message since no data in validation table
90
        self.check_message(
91
            message=STATUSES.get_value_display(NEED_REVISION),
92
            notification_message=(
93
                "You've removed %s "
94
                "samples. Rerun validation please!" % len(self.sample_ids)))
95
96
    def test_delete_samples_not_exists(self):
97
        # calling task and delete a animal
98
        res = self.my_task.run(
99
            submission_id=self.submission_id,
100
            sample_ids=["meow"])
101
102
        self.assertEqual(res, "success")
103
104
        # all samples remain
105
        n_samples = Sample.objects.count()
106
        self.assertEqual(n_samples, 1)
107
108
        # updating validation messages
109
110
        # calling a WebSocketMixin method
111
        # no validation message since no data in validation table
112
        self.check_message(
113
            message=STATUSES.get_value_display(NEED_REVISION),
114
            notification_message=(
115
                "You've removed 0 samples. It wasn't possible to find records "
116
                "with these ids: meow. Rerun validation please!")
117
        )
118