|
@@ 193-202 (lines=10) @@
|
| 190 |
|
q.getFields.return_value = [field1] |
| 191 |
|
out = repo.inquire(q) |
| 192 |
|
self.assertEqual([img2, img4], out) |
| 193 |
|
|
| 194 |
|
def test_Search_only_returns_objects_which_have_needle(self): |
| 195 |
|
self.fileFactory.fromProvenance.side_effect = lambda p: 'img_'+p['l'] |
| 196 |
|
from niprov.jsonfile import JsonFile |
| 197 |
|
repo = JsonFile(self.dependencies) |
| 198 |
|
img1 = self.imageWithProvenance({'transformation':'green blue'}) |
| 199 |
|
img2 = self.imageWithProvenance({'transformation':'yellow red'}) |
| 200 |
|
repo.all = Mock() |
| 201 |
|
repo.all.return_value = [img1, img2] |
| 202 |
|
out = repo.search('red') |
| 203 |
|
self.assertEqual([img2], out) |
| 204 |
|
|
| 205 |
|
def test_Search_sorts_results_by_number_of_matches(self): |
|
@@ 129-138 (lines=10) @@
|
| 126 |
|
out = repo.statistics() |
| 127 |
|
self.assertEqual(totalsize, out['totalsize']) |
| 128 |
|
|
| 129 |
|
def test_byId(self): |
| 130 |
|
from niprov.jsonfile import JsonFile |
| 131 |
|
repo = JsonFile(self.dependencies) |
| 132 |
|
img1 = self.imageWithProvenance({'id':'1'}) |
| 133 |
|
img2 = self.imageWithProvenance({'id':'2'}) |
| 134 |
|
img3 = self.imageWithProvenance({'id':'3'}) |
| 135 |
|
repo.all = Mock() |
| 136 |
|
repo.all.return_value = [img1, img2, img3] |
| 137 |
|
out = repo.byId('2') |
| 138 |
|
self.assertEqual(img2, out) |
| 139 |
|
|
| 140 |
|
def test_byLocations(self): |
| 141 |
|
self.fileFactory.fromProvenance.side_effect = lambda p: 'img_'+p['a'] |
|
@@ 241-251 (lines=11) @@
|
| 238 |
|
self.assertIn(i6, out) |
| 239 |
|
self.assertIn(i7, out) |
| 240 |
|
self.assertIn(i8, out) |
| 241 |
|
|
| 242 |
|
def test_Search_distinguishes_words_as_OR_search(self): |
| 243 |
|
self.fileFactory.fromProvenance.side_effect = lambda p: 'img_'+p['l'] |
| 244 |
|
from niprov.jsonfile import JsonFile |
| 245 |
|
repo = JsonFile(self.dependencies) |
| 246 |
|
i1 = self.imageWithProvenance({'transformation':'blue red red'}) #2 |
| 247 |
|
i2 = self.imageWithProvenance({'transformation':'red blue green red'}) #3 |
| 248 |
|
i3 = self.imageWithProvenance({'transformation':'green blue'}) #1 |
| 249 |
|
repo.all = Mock() |
| 250 |
|
repo.all.return_value = [i1,i2,i3] |
| 251 |
|
out = repo.search('red green') |
| 252 |
|
self.assertEqual([i2, i1, i3], out) |
| 253 |
|
|
| 254 |
|
def test_Search_returns_max_20_results(self): |
|
@@ 253-263 (lines=11) @@
|
| 250 |
|
repo.all.return_value = [i1,i2,i3] |
| 251 |
|
out = repo.search('red green') |
| 252 |
|
self.assertEqual([i2, i1, i3], out) |
| 253 |
|
|
| 254 |
|
def test_Search_returns_max_20_results(self): |
| 255 |
|
self.fileFactory.fromProvenance.side_effect = lambda p: 'img_'+p['l'] |
| 256 |
|
from niprov.jsonfile import JsonFile |
| 257 |
|
repo = JsonFile(self.dependencies) |
| 258 |
|
recs = [] |
| 259 |
|
for i in range(35): |
| 260 |
|
recs.append(self.imageWithProvenance({'transformation':'red'})) |
| 261 |
|
repo.all = Mock() |
| 262 |
|
repo.all.return_value = recs |
| 263 |
|
out = repo.search('red') |
| 264 |
|
self.assertEqual(20, len(out)) |
| 265 |
|
|
| 266 |
|
def test_Query_with_ALL_field(self): |