Code Duplication    Length = 71-71 lines in 2 locations

django-data/image/excel/tests/test_helpers.py 1 location

@@ 121-191 (lines=71) @@
118
        self.assertEqual(len(not_found), 0)
119
120
121
class ExcelMixin(WebSocketMixin, BaseExcelMixin):
122
    """Common tests for Excel classes"""
123
124
    def test_upload_template(self):
125
        """Testing uploading and importing data from excel template to UID"""
126
127
        # assert upload
128
        self.assertTrue(upload_template(self.submission))
129
130
        # reload submission
131
        self.submission.refresh_from_db()
132
133
        # assert submission messages
134
        self.assertEqual(
135
            self.submission.status,
136
            LOADED)
137
138
        self.assertIn(
139
            "Template import completed for submission",
140
            self.submission.message)
141
142
        # assert data into database
143
        self.assertTrue(db_has_data())
144
        self.assertTrue(Animal.objects.exists())
145
        self.assertTrue(Sample.objects.exists())
146
147
        # check async message called
148
        message = 'Loaded'
149
        notification_message = (
150
            'Template import completed for submission: 1')
151
        validation_message = {
152
            'animals': 3, 'samples': 3,
153
            'animal_unkn': 3, 'sample_unkn': 3,
154
            'animal_issues': 0, 'sample_issues': 0}
155
156
        self.check_message(message, notification_message, validation_message)
157
158
    def check_errors(self, my_check, message, notification_message):
159
        """Common stuff for error in excel template loading"""
160
161
        self.assertFalse(upload_template(self.submission))
162
163
        # reload submission
164
        self.submission.refresh_from_db()
165
166
        # test my mock method called
167
        self.assertTrue(my_check.called)
168
169
        # reload submission
170
        self.submission = Submission.objects.get(pk=1)
171
172
        self.assertEqual(
173
            self.submission.status,
174
            ERROR)
175
176
        # check for two distinct messages
177
        self.assertIn(
178
            message,
179
            self.submission.message)
180
181
        self.assertNotIn(
182
            "Template import completed for submission",
183
            self.submission.message)
184
185
        # assert data into database
186
        self.assertFalse(db_has_data())
187
        self.assertFalse(Animal.objects.exists())
188
        self.assertFalse(Sample.objects.exists())
189
190
        # check async message called
191
        self.check_message('Error', notification_message)
192
193
194
class UploadTemplateTestCase(ExcelMixin, TestCase):

django-data/image/crbanim/tests/test_helpers.py 1 location

@@ 29-99 (lines=71) @@
26
from .common import BaseTestCase
27
28
29
class CRBAnimMixin(WebSocketMixin):
30
    """Common test for CRBanim classes"""
31
32
    def test_upload_crbanim(self):
33
        """Testing uploading and importing data from crbanim to UID"""
34
35
        # assert upload
36
        self.assertTrue(upload_crbanim(self.submission))
37
38
        # reload submission
39
        self.submission.refresh_from_db()
40
41
        # assert submission messages
42
        self.assertEqual(
43
            self.submission.status,
44
            LOADED)
45
46
        self.assertIn(
47
            "CRBAnim import completed for submission",
48
            self.submission.message)
49
50
        # assert data into database
51
        self.assertTrue(db_has_data())
52
        self.assertTrue(Animal.objects.exists())
53
        self.assertTrue(Sample.objects.exists())
54
55
        # check async message called
56
        message = 'Loaded'
57
        notification_message = (
58
            'CRBAnim import completed for submission: 1')
59
        validation_message = {
60
            'animals': 1, 'samples': 2,
61
            'animal_unkn': 1, 'sample_unkn': 2,
62
            'animal_issues': 0, 'sample_issues': 0}
63
64
        self.check_message(message, notification_message, validation_message)
65
66
    def check_errors(self, my_check, message, notification_message):
67
        """Common stuff for error in crbanim loading"""
68
69
        self.assertFalse(upload_crbanim(self.submission))
70
71
        # reload submission
72
        self.submission.refresh_from_db()
73
74
        # test my mock method called
75
        self.assertTrue(my_check.called)
76
77
        # reload submission
78
        self.submission = Submission.objects.get(pk=1)
79
80
        self.assertEqual(
81
            self.submission.status,
82
            ERROR)
83
84
        # check for two distinct messages
85
        self.assertIn(
86
            message,
87
            self.submission.message)
88
89
        self.assertNotIn(
90
            "CRBAnim import completed for submission",
91
            self.submission.message)
92
93
        # assert data into database
94
        self.assertFalse(db_has_data())
95
        self.assertFalse(Animal.objects.exists())
96
        self.assertFalse(Sample.objects.exists())
97
98
        # check async message called
99
        self.check_message('Error', notification_message)
100
101
102
class CRBAnimReaderTestCase(BaseTestCase, TestCase):