|
@@ 177-185 (lines=9) @@
|
| 174 |
|
|
| 175 |
|
def test_Converts_duration_to_timedelta_when_deserializing(self): |
| 176 |
|
self.setupRepo() |
| 177 |
|
self.db.provenance.find_one.return_value = {'a':3, 'duration':89.01} |
| 178 |
|
out = self.repo.byLocation('/p/f1') |
| 179 |
|
self.fileFactory.fromProvenance.assert_called_with( |
| 180 |
|
{'a':3, 'duration':timedelta(seconds=89.01)}) |
| 181 |
|
|
| 182 |
|
def test_Obtains_optional_snapshot_data_from_cache_when_serializing(self): |
| 183 |
|
self.pictureCache.getBytes.return_value = sentinel.snapbytes |
| 184 |
|
with patch('niprov.mongo.bson') as bson: |
| 185 |
|
bson.Binary.return_value = sentinel.snapbson |
| 186 |
|
self.setupRepo() |
| 187 |
|
img = Mock() |
| 188 |
|
img.provenance = {'a':1} |
|
@@ 167-175 (lines=9) @@
|
| 164 |
|
self.fileFactory.fromProvenance.assert_any_call('p2') |
| 165 |
|
self.assertEqual(['img_p1', 'img_p2'], out) |
| 166 |
|
|
| 167 |
|
def test_Converts_timedelta_to_float_when_serializing(self): |
| 168 |
|
self.setupRepo() |
| 169 |
|
img = Mock() |
| 170 |
|
img.provenance = {'a':1, 'duration':timedelta(seconds=67.89)} |
| 171 |
|
self.repo.add(img) |
| 172 |
|
self.db.provenance.insert_one.assert_called_with( |
| 173 |
|
{'a':1, 'duration':67.89}) |
| 174 |
|
|
| 175 |
|
def test_Converts_duration_to_timedelta_when_deserializing(self): |
| 176 |
|
self.setupRepo() |
| 177 |
|
self.db.provenance.find_one.return_value = {'a':3, 'duration':89.01} |
| 178 |
|
out = self.repo.byLocation('/p/f1') |
|
@@ 84-92 (lines=9) @@
|
| 81 |
|
img.provenance = {'a':1, 'b':2} |
| 82 |
|
self.repo.update(img) |
| 83 |
|
self.db.provenance.update.assert_called_with( |
| 84 |
|
{'location':img.location.toString()}, {'a':1, 'b':2}) |
| 85 |
|
|
| 86 |
|
def test_all(self): |
| 87 |
|
self.fileFactory.fromProvenance.side_effect = lambda p: 'img_'+p |
| 88 |
|
self.db.provenance.find.return_value = ['p1', 'p2'] |
| 89 |
|
self.setupRepo() |
| 90 |
|
out = self.repo.all() |
| 91 |
|
self.db.provenance.find.assert_called_with() |
| 92 |
|
self.fileFactory.fromProvenance.assert_any_call('p1') |
| 93 |
|
self.fileFactory.fromProvenance.assert_any_call('p2') |
| 94 |
|
self.assertEqual(['img_p1', 'img_p2'], out) |
| 95 |
|
|