|
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 DictBreed, DictSpecie, DictCountry, DictUberon |
|
14
|
|
|
from common.constants import OBO_URL, GOOD |
|
15
|
|
|
|
|
16
|
|
|
from ..helpers import ( |
|
17
|
|
|
annotate_breed, annotate_specie, annotate_country, annotate_uberon) |
|
18
|
|
|
|
|
19
|
|
|
|
|
20
|
|
|
class TestAnnotateBreed(TestCase): |
|
21
|
|
|
"""A class to test annotate breeds""" |
|
22
|
|
|
|
|
23
|
|
|
fixtures = [ |
|
24
|
|
|
"image_app/dictbreed", |
|
25
|
|
|
"image_app/dictcountry", |
|
26
|
|
|
"image_app/dictspecie" |
|
27
|
|
|
] |
|
28
|
|
|
|
|
29
|
|
|
def setUp(self): |
|
30
|
|
|
# get a breed object |
|
31
|
|
|
self.breed = DictBreed.objects.get(pk=1) |
|
32
|
|
|
|
|
33
|
|
|
# erase attributes |
|
34
|
|
|
self.breed.mapped_breed = None |
|
35
|
|
|
self.breed.mapped_breed_term = None |
|
36
|
|
|
self.breed.confidence = None |
|
37
|
|
|
self.breed.save() |
|
38
|
|
|
|
|
39
|
|
|
@patch("zooma.helpers.use_zooma") |
|
40
|
|
|
def test_annotate_breed(self, my_zooma): |
|
41
|
|
|
"""Testing annotate breed""" |
|
42
|
|
|
|
|
43
|
|
|
my_zooma.return_value = { |
|
44
|
|
|
'type': 'breed', |
|
45
|
|
|
'confidence': 'Good', |
|
46
|
|
|
'text': 'Bentheim Black Pied', |
|
47
|
|
|
'ontologyTerms': '%s/LBO_0000347' % (OBO_URL) |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
|
# call my method |
|
51
|
|
|
annotate_breed(self.breed) |
|
52
|
|
|
|
|
53
|
|
|
self.assertTrue(my_zooma.called) |
|
54
|
|
|
|
|
55
|
|
|
# ensure annotation |
|
56
|
|
|
self.breed.refresh_from_db() |
|
57
|
|
|
|
|
58
|
|
|
self.assertEqual(self.breed.mapped_breed, "Bentheim Black Pied") |
|
59
|
|
|
self.assertEqual(self.breed.mapped_breed_term, "LBO_0000347") |
|
60
|
|
|
self.assertEqual(self.breed.confidence, GOOD) |
|
61
|
|
|
|
|
62
|
|
|
|
|
63
|
|
|
class TestAnnotateCountry(TestCase): |
|
64
|
|
|
"""A class to test annotate countries""" |
|
65
|
|
|
|
|
66
|
|
|
fixtures = [ |
|
67
|
|
|
"image_app/dictcountry", |
|
68
|
|
|
] |
|
69
|
|
|
|
|
70
|
|
|
def setUp(self): |
|
71
|
|
|
# get a country object |
|
72
|
|
|
self.country = DictCountry.objects.get(pk=1) |
|
73
|
|
|
|
|
74
|
|
|
# erase attributes |
|
75
|
|
|
self.country.term = None |
|
76
|
|
|
self.country.confidence = None |
|
77
|
|
|
self.country.save() |
|
78
|
|
|
|
|
79
|
|
|
@patch("zooma.helpers.use_zooma") |
|
80
|
|
|
def test_annotate_country(self, my_zooma): |
|
81
|
|
|
"""Testing annotate country""" |
|
82
|
|
|
|
|
83
|
|
|
my_zooma.return_value = { |
|
84
|
|
|
'type': 'country', |
|
85
|
|
|
'confidence': 'Good', |
|
86
|
|
|
'text': 'United Kingdom', |
|
87
|
|
|
'ontologyTerms': '%s/NCIT_C17233' % (OBO_URL)} |
|
88
|
|
|
|
|
89
|
|
|
# call my method |
|
90
|
|
|
annotate_country(self.country) |
|
91
|
|
|
|
|
92
|
|
|
self.assertTrue(my_zooma.called) |
|
93
|
|
|
|
|
94
|
|
|
# ensure annotation |
|
95
|
|
|
self.country.refresh_from_db() |
|
96
|
|
|
|
|
97
|
|
|
self.assertEqual(self.country.label, "United Kingdom") |
|
98
|
|
|
self.assertEqual(self.country.term, "NCIT_C17233") |
|
99
|
|
|
self.assertEqual(self.country.confidence, GOOD) |
|
100
|
|
|
|
|
101
|
|
|
|
|
102
|
|
|
class TestAnnotateSpecie(TestCase): |
|
103
|
|
|
"""A class to test annotate species""" |
|
104
|
|
|
|
|
105
|
|
|
fixtures = [ |
|
106
|
|
|
"image_app/dictspecie", |
|
107
|
|
|
] |
|
108
|
|
|
|
|
109
|
|
|
def setUp(self): |
|
110
|
|
|
# get a specie object |
|
111
|
|
|
self.specie = DictSpecie.objects.get(pk=1) |
|
112
|
|
|
|
|
113
|
|
|
# erase attributes |
|
114
|
|
|
self.specie.term = None |
|
115
|
|
|
self.specie.confidence = None |
|
116
|
|
|
self.specie.save() |
|
117
|
|
|
|
|
118
|
|
|
@patch("zooma.helpers.use_zooma") |
|
119
|
|
|
def test_annotate_specie(self, my_zooma): |
|
120
|
|
|
"""Testing annotate specie""" |
|
121
|
|
|
|
|
122
|
|
|
my_zooma.return_value = { |
|
123
|
|
|
'type': 'specie', |
|
124
|
|
|
'confidence': 'Good', |
|
125
|
|
|
'text': 'Sus scrofa', |
|
126
|
|
|
'ontologyTerms': '%s/NCBITaxon_9823' % (OBO_URL) |
|
127
|
|
|
} |
|
128
|
|
|
|
|
129
|
|
|
# call my method |
|
130
|
|
|
annotate_specie(self.specie) |
|
131
|
|
|
|
|
132
|
|
|
self.assertTrue(my_zooma.called) |
|
133
|
|
|
|
|
134
|
|
|
# ensure annotation |
|
135
|
|
|
self.specie.refresh_from_db() |
|
136
|
|
|
|
|
137
|
|
|
self.assertEqual(self.specie.label, "Sus scrofa") |
|
138
|
|
|
self.assertEqual(self.specie.term, "NCBITaxon_9823") |
|
139
|
|
|
self.assertEqual(self.specie.confidence, GOOD) |
|
140
|
|
|
|
|
141
|
|
|
|
|
142
|
|
|
class TestAnnotateUberon(TestCase): |
|
143
|
|
|
"""A class to test annotate uberon""" |
|
144
|
|
|
|
|
145
|
|
|
fixtures = [ |
|
146
|
|
|
"image_app/dictuberon", |
|
147
|
|
|
] |
|
148
|
|
|
|
|
149
|
|
|
def setUp(self): |
|
150
|
|
|
# get a specie object |
|
151
|
|
|
self.part = DictUberon.objects.get(pk=1) |
|
152
|
|
|
|
|
153
|
|
|
# erase attributes |
|
154
|
|
|
self.part.term = None |
|
155
|
|
|
self.part.confidence = None |
|
156
|
|
|
self.part.save() |
|
157
|
|
|
|
|
158
|
|
|
@patch("zooma.helpers.use_zooma") |
|
159
|
|
|
def test_annotate_uberon(self, my_zooma): |
|
160
|
|
|
"""Testing annotate uberon""" |
|
161
|
|
|
|
|
162
|
|
|
my_zooma.return_value = { |
|
163
|
|
|
'type': 'organism part', |
|
164
|
|
|
'confidence': 'Good', |
|
165
|
|
|
'text': 'semen', |
|
166
|
|
|
'ontologyTerms': '%s/UBERON_0001968' % (OBO_URL) |
|
167
|
|
|
} |
|
168
|
|
|
|
|
169
|
|
|
# call my method |
|
170
|
|
|
annotate_uberon(self.part) |
|
171
|
|
|
|
|
172
|
|
|
self.assertTrue(my_zooma.called) |
|
173
|
|
|
|
|
174
|
|
|
# ensure annotation |
|
175
|
|
|
self.part.refresh_from_db() |
|
176
|
|
|
|
|
177
|
|
|
self.assertEqual(self.part.label, "semen") |
|
178
|
|
|
self.assertEqual(self.part.term, "UBERON_0001968") |
|
179
|
|
|
self.assertEqual(self.part.confidence, GOOD) |
|
180
|
|
|
|