|
1
|
|
|
#!/usr/bin/env python3 |
|
2
|
|
|
# -*- coding: utf-8 -*- |
|
3
|
|
|
""" |
|
4
|
|
|
Created on Mon May 7 16:23:17 2018 |
|
5
|
|
|
|
|
6
|
|
|
@author: Paolo Cozzi <[email protected]> |
|
7
|
|
|
""" |
|
8
|
|
|
|
|
9
|
|
|
from unittest.mock import patch |
|
10
|
|
|
|
|
11
|
|
|
from django.test import TestCase |
|
12
|
|
|
|
|
13
|
|
|
from image_app.models import ( |
|
14
|
|
|
DictBreed, DictSpecie, DictCountry, DictUberon, DictDevelStage, |
|
15
|
|
|
DictPhysioStage) |
|
16
|
|
|
from common.constants import OBO_URL, GOOD, HIGH |
|
17
|
|
|
|
|
18
|
|
|
from ..helpers import ( |
|
19
|
|
|
annotate_breed, annotate_specie, annotate_country, annotate_uberon, |
|
20
|
|
|
annotate_dictdevelstage, annotate_dictphysiostage) |
|
21
|
|
|
|
|
22
|
|
|
|
|
23
|
|
|
class TestAnnotateBreed(TestCase): |
|
24
|
|
|
"""A class to test annotate breeds""" |
|
25
|
|
|
|
|
26
|
|
|
fixtures = [ |
|
27
|
|
|
"image_app/dictbreed", |
|
28
|
|
|
"image_app/dictcountry", |
|
29
|
|
|
"image_app/dictspecie" |
|
30
|
|
|
] |
|
31
|
|
|
|
|
32
|
|
|
def setUp(self): |
|
33
|
|
|
# get a breed object |
|
34
|
|
|
self.breed = DictBreed.objects.get(pk=1) |
|
35
|
|
|
|
|
36
|
|
|
# erase attributes |
|
37
|
|
|
self.breed.mapped_breed = None |
|
38
|
|
|
self.breed.mapped_breed_term = None |
|
39
|
|
|
self.breed.confidence = None |
|
40
|
|
|
self.breed.save() |
|
41
|
|
|
|
|
42
|
|
|
@patch("zooma.helpers.use_zooma") |
|
43
|
|
|
def test_annotate_breed(self, my_zooma): |
|
44
|
|
|
"""Testing annotate breed""" |
|
45
|
|
|
|
|
46
|
|
|
my_zooma.return_value = { |
|
47
|
|
|
'type': 'breed', |
|
48
|
|
|
'confidence': 'Good', |
|
49
|
|
|
'text': 'Bentheim Black Pied', |
|
50
|
|
|
'ontologyTerms': '%s/LBO_0000347' % (OBO_URL) |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
|
|
# call my method |
|
54
|
|
|
annotate_breed(self.breed) |
|
55
|
|
|
|
|
56
|
|
|
self.assertTrue(my_zooma.called) |
|
57
|
|
|
|
|
58
|
|
|
# ensure annotation |
|
59
|
|
|
self.breed.refresh_from_db() |
|
60
|
|
|
|
|
61
|
|
|
self.assertEqual(self.breed.mapped_breed, "Bentheim Black Pied") |
|
62
|
|
|
self.assertEqual(self.breed.mapped_breed_term, "LBO_0000347") |
|
63
|
|
|
self.assertEqual(self.breed.confidence, GOOD) |
|
64
|
|
|
|
|
65
|
|
|
|
|
66
|
|
|
class TestAnnotateCountry(TestCase): |
|
67
|
|
|
"""A class to test annotate countries""" |
|
68
|
|
|
|
|
69
|
|
|
fixtures = [ |
|
70
|
|
|
"image_app/dictcountry", |
|
71
|
|
|
] |
|
72
|
|
|
|
|
73
|
|
|
def setUp(self): |
|
74
|
|
|
# get a country object |
|
75
|
|
|
self.country = DictCountry.objects.get(pk=1) |
|
76
|
|
|
|
|
77
|
|
|
# erase attributes |
|
78
|
|
|
self.country.term = None |
|
79
|
|
|
self.country.confidence = None |
|
80
|
|
|
self.country.save() |
|
81
|
|
|
|
|
82
|
|
|
@patch("zooma.helpers.use_zooma") |
|
83
|
|
|
def test_annotate_country(self, my_zooma): |
|
84
|
|
|
"""Testing annotate country""" |
|
85
|
|
|
|
|
86
|
|
|
my_zooma.return_value = { |
|
87
|
|
|
'type': 'country', |
|
88
|
|
|
'confidence': 'Good', |
|
89
|
|
|
'text': 'United Kingdom', |
|
90
|
|
|
'ontologyTerms': '%s/NCIT_C17233' % (OBO_URL)} |
|
91
|
|
|
|
|
92
|
|
|
# call my method |
|
93
|
|
|
annotate_country(self.country) |
|
94
|
|
|
|
|
95
|
|
|
self.assertTrue(my_zooma.called) |
|
96
|
|
|
|
|
97
|
|
|
# ensure annotation |
|
98
|
|
|
self.country.refresh_from_db() |
|
99
|
|
|
|
|
100
|
|
|
self.assertEqual(self.country.label, "United Kingdom") |
|
101
|
|
|
self.assertEqual(self.country.term, "NCIT_C17233") |
|
102
|
|
|
self.assertEqual(self.country.confidence, GOOD) |
|
103
|
|
|
|
|
104
|
|
|
|
|
105
|
|
|
class TestAnnotateSpecie(TestCase): |
|
106
|
|
|
"""A class to test annotate species""" |
|
107
|
|
|
|
|
108
|
|
|
fixtures = [ |
|
109
|
|
|
"image_app/dictspecie", |
|
110
|
|
|
] |
|
111
|
|
|
|
|
112
|
|
|
def setUp(self): |
|
113
|
|
|
# get a specie object |
|
114
|
|
|
self.specie = DictSpecie.objects.get(pk=1) |
|
115
|
|
|
|
|
116
|
|
|
# erase attributes |
|
117
|
|
|
self.specie.term = None |
|
118
|
|
|
self.specie.confidence = None |
|
119
|
|
|
self.specie.save() |
|
120
|
|
|
|
|
121
|
|
|
@patch("zooma.helpers.use_zooma") |
|
122
|
|
|
def test_annotate_specie(self, my_zooma): |
|
123
|
|
|
"""Testing annotate specie""" |
|
124
|
|
|
|
|
125
|
|
|
my_zooma.return_value = { |
|
126
|
|
|
'type': 'specie', |
|
127
|
|
|
'confidence': 'Good', |
|
128
|
|
|
'text': 'Sus scrofa', |
|
129
|
|
|
'ontologyTerms': '%s/NCBITaxon_9823' % (OBO_URL) |
|
130
|
|
|
} |
|
131
|
|
|
|
|
132
|
|
|
# call my method |
|
133
|
|
|
annotate_specie(self.specie) |
|
134
|
|
|
|
|
135
|
|
|
self.assertTrue(my_zooma.called) |
|
136
|
|
|
|
|
137
|
|
|
# ensure annotation |
|
138
|
|
|
self.specie.refresh_from_db() |
|
139
|
|
|
|
|
140
|
|
|
self.assertEqual(self.specie.label, "Sus scrofa") |
|
141
|
|
|
self.assertEqual(self.specie.term, "NCBITaxon_9823") |
|
142
|
|
|
self.assertEqual(self.specie.confidence, GOOD) |
|
143
|
|
|
|
|
144
|
|
|
|
|
145
|
|
|
class TestAnnotateUberon(TestCase): |
|
146
|
|
|
"""A class to test annotate uberon""" |
|
147
|
|
|
|
|
148
|
|
|
fixtures = [ |
|
149
|
|
|
"image_app/dictuberon", |
|
150
|
|
|
] |
|
151
|
|
|
|
|
152
|
|
|
def setUp(self): |
|
153
|
|
|
# get a specie object |
|
154
|
|
|
self.part = DictUberon.objects.get(pk=1) |
|
155
|
|
|
|
|
156
|
|
|
# erase attributes |
|
157
|
|
|
self.part.term = None |
|
158
|
|
|
self.part.confidence = None |
|
159
|
|
|
self.part.save() |
|
160
|
|
|
|
|
161
|
|
|
@patch("zooma.helpers.use_zooma") |
|
162
|
|
|
def test_annotate_uberon(self, my_zooma): |
|
163
|
|
|
"""Testing annotate uberon""" |
|
164
|
|
|
|
|
165
|
|
|
my_zooma.return_value = { |
|
166
|
|
|
'type': 'organism part', |
|
167
|
|
|
'confidence': 'Good', |
|
168
|
|
|
'text': 'semen', |
|
169
|
|
|
'ontologyTerms': '%s/UBERON_0001968' % (OBO_URL) |
|
170
|
|
|
} |
|
171
|
|
|
|
|
172
|
|
|
# call my method |
|
173
|
|
|
annotate_uberon(self.part) |
|
174
|
|
|
|
|
175
|
|
|
self.assertTrue(my_zooma.called) |
|
176
|
|
|
|
|
177
|
|
|
# ensure annotation |
|
178
|
|
|
self.part.refresh_from_db() |
|
179
|
|
|
|
|
180
|
|
|
self.assertEqual(self.part.label, "semen") |
|
181
|
|
|
self.assertEqual(self.part.term, "UBERON_0001968") |
|
182
|
|
|
self.assertEqual(self.part.confidence, GOOD) |
|
183
|
|
|
|
|
184
|
|
|
|
|
185
|
|
|
class TestAnnotateDevelStage(TestCase): |
|
186
|
|
|
"""A class to test developmental stage""" |
|
187
|
|
|
|
|
188
|
|
|
fixtures = [ |
|
189
|
|
|
"image_app/dictstage", |
|
190
|
|
|
] |
|
191
|
|
|
|
|
192
|
|
|
def setUp(self): |
|
193
|
|
|
# get a specie object |
|
194
|
|
|
self.stage = DictDevelStage.objects.get(pk=1) |
|
195
|
|
|
|
|
196
|
|
|
# erase attributes |
|
197
|
|
|
self.stage.term = None |
|
198
|
|
|
self.stage.confidence = None |
|
199
|
|
|
self.stage.save() |
|
200
|
|
|
|
|
201
|
|
|
@patch("zooma.helpers.use_zooma") |
|
202
|
|
|
def test_annotate_dictdevelstage(self, my_zooma): |
|
203
|
|
|
"""Testing annotate dictdevelstage""" |
|
204
|
|
|
|
|
205
|
|
|
my_zooma.return_value = { |
|
206
|
|
|
'confidence': 'High', |
|
207
|
|
|
'ontologyTerms': 'http://www.ebi.ac.uk/efo/EFO_0001272', |
|
208
|
|
|
'text': 'adult', |
|
209
|
|
|
'type': 'developmental stage' |
|
210
|
|
|
} |
|
211
|
|
|
|
|
212
|
|
|
# call my method |
|
213
|
|
|
annotate_dictdevelstage(self.stage) |
|
214
|
|
|
|
|
215
|
|
|
self.assertTrue(my_zooma.called) |
|
216
|
|
|
|
|
217
|
|
|
# ensure annotation |
|
218
|
|
|
self.stage.refresh_from_db() |
|
219
|
|
|
|
|
220
|
|
|
self.assertEqual(self.stage.label, "adult") |
|
221
|
|
|
self.assertEqual(self.stage.term, "EFO_0001272") |
|
222
|
|
|
self.assertEqual(self.stage.confidence, HIGH) |
|
223
|
|
|
|
|
224
|
|
|
|
|
225
|
|
|
class TestAnnotatePhysioStage(TestCase): |
|
226
|
|
|
"""A class to test developmental stage""" |
|
227
|
|
|
|
|
228
|
|
|
fixtures = [ |
|
229
|
|
|
"image_app/dictstage", |
|
230
|
|
|
] |
|
231
|
|
|
|
|
232
|
|
|
def setUp(self): |
|
233
|
|
|
# get a specie object |
|
234
|
|
|
self.stage = DictPhysioStage.objects.get(pk=1) |
|
235
|
|
|
|
|
236
|
|
|
# erase attributes |
|
237
|
|
|
self.stage.term = None |
|
238
|
|
|
self.stage.confidence = None |
|
239
|
|
|
self.stage.save() |
|
240
|
|
|
|
|
241
|
|
|
@patch("zooma.helpers.use_zooma") |
|
242
|
|
|
def test_annotate_dictphysiostage(self, my_zooma): |
|
243
|
|
|
"""Testing annotate dictphysiostage""" |
|
244
|
|
|
|
|
245
|
|
|
my_zooma.return_value = { |
|
246
|
|
|
'confidence': 'High', |
|
247
|
|
|
'ontologyTerms': 'http://purl.obolibrary.org/obo/PATO_0001701', |
|
248
|
|
|
'text': 'mature', |
|
249
|
|
|
'type': 'developmental stage' |
|
250
|
|
|
} |
|
251
|
|
|
|
|
252
|
|
|
# call my method |
|
253
|
|
|
annotate_dictphysiostage(self.stage) |
|
254
|
|
|
|
|
255
|
|
|
self.assertTrue(my_zooma.called) |
|
256
|
|
|
|
|
257
|
|
|
# ensure annotation |
|
258
|
|
|
self.stage.refresh_from_db() |
|
259
|
|
|
|
|
260
|
|
|
self.assertEqual(self.stage.label, "mature") |
|
261
|
|
|
self.assertEqual(self.stage.term, "PATO_0001701") |
|
262
|
|
|
self.assertEqual(self.stage.confidence, HIGH) |
|
263
|
|
|
|