|
@@ 177-185 (lines=9) @@
|
| 174 |
|
|
| 175 |
|
def test_Obtains_optional_snapshot_data_from_cache_when_serializing(self): |
| 176 |
|
self.pictureCache.getBytes.return_value = sentinel.snapbytes |
| 177 |
|
with patch('niprov.mongo.bson') as bson: |
| 178 |
|
bson.Binary.return_value = sentinel.snapbson |
| 179 |
|
self.setupRepo() |
| 180 |
|
img = Mock() |
| 181 |
|
img.provenance = {'a':1} |
| 182 |
|
self.repo.add(img) |
| 183 |
|
self.pictureCache.getBytes.assert_called_with(for_=img) |
| 184 |
|
bson.Binary.assert_called_with(sentinel.snapbytes) |
| 185 |
|
self.db.provenance.insert_one.assert_called_with({'a':1, |
| 186 |
|
'_snapshot-data':sentinel.snapbson}) |
| 187 |
|
|
| 188 |
|
def test_If_no_snapshot_doesnt_add_data_field(self): |
|
@@ 167-175 (lines=9) @@
|
| 164 |
|
self.repo.add(img) |
| 165 |
|
self.db.provenance.insert_one.assert_called_with( |
| 166 |
|
{'a':1, 'duration':67.89}) |
| 167 |
|
|
| 168 |
|
def test_Converts_duration_to_timedelta_when_deserializing(self): |
| 169 |
|
self.setupRepo() |
| 170 |
|
self.db.provenance.find_one.return_value = {'a':3, 'duration':89.01} |
| 171 |
|
out = self.repo.byLocation('/p/f1') |
| 172 |
|
self.fileFactory.fromProvenance.assert_called_with( |
| 173 |
|
{'a':3, 'duration':timedelta(seconds=89.01)}) |
| 174 |
|
|
| 175 |
|
def test_Obtains_optional_snapshot_data_from_cache_when_serializing(self): |
| 176 |
|
self.pictureCache.getBytes.return_value = sentinel.snapbytes |
| 177 |
|
with patch('niprov.mongo.bson') as bson: |
| 178 |
|
bson.Binary.return_value = sentinel.snapbson |
|
@@ 84-92 (lines=9) @@
|
| 81 |
|
|
| 82 |
|
def test_updateApproval(self): |
| 83 |
|
self.setupRepo() |
| 84 |
|
img = Mock() |
| 85 |
|
p = '/p/f1' |
| 86 |
|
newStatus = 'oh-oh' |
| 87 |
|
self.repo.updateApproval(p, newStatus) |
| 88 |
|
self.db.provenance.update.assert_called_with( |
| 89 |
|
{'location':p}, {'$set': {'approval': newStatus}}) |
| 90 |
|
|
| 91 |
|
def test_latest(self): |
| 92 |
|
self.fileFactory.fromProvenance.side_effect = lambda p: 'img_'+p |
| 93 |
|
self.db.provenance.find.return_value = Mock() |
| 94 |
|
self.db.provenance.find.return_value.sort.return_value.limit.return_value = ['px','py'] |
| 95 |
|
self.setupRepo() |