1
|
|
|
import unittest |
2
|
|
|
from mock import sentinel, Mock |
3
|
|
|
from tests.ditest import DependencyInjectionTestBase |
4
|
|
|
|
5
|
|
|
class ExportingTests(DependencyInjectionTestBase): |
6
|
|
|
|
7
|
|
|
def setUp(self): |
8
|
|
|
super(ExportingTests, self).setUp() |
9
|
|
|
|
10
|
|
|
def export(self, *args, **kwargs): |
11
|
|
|
import niprov |
12
|
|
|
return niprov.export(*args, dependencies=self.dependencies, **kwargs) |
13
|
|
|
|
14
|
|
|
def test_Obtains_format_from_factory(self): |
15
|
|
|
self.export(None, form='json', medium='x') |
16
|
|
|
self.formatFactory.create.assert_any_call('json') |
17
|
|
|
self.export(None, form='xml', medium='x') |
18
|
|
|
self.formatFactory.create.assert_any_call('xml') |
19
|
|
|
|
20
|
|
|
def test_Obtains_medium_from_factory(self): |
21
|
|
|
self.export(None, medium='file', form='x') |
22
|
|
|
self.mediumFactory.create.assert_any_call('file') |
23
|
|
|
self.export(None, medium='stdout', form='x') |
24
|
|
|
self.mediumFactory.create.assert_any_call('stdout') |
25
|
|
|
|
26
|
|
|
def test_Passes_provenance_through_format_and_medium(self): |
27
|
|
|
self.format.serialize.return_value = 'serialized prov' |
28
|
|
|
self.medium.export.return_value = sentinel.mediumOutput |
29
|
|
|
out = self.export(sentinel.images, 'a medium','a format') |
30
|
|
|
self.format.serialize.assert_any_call(sentinel.images) |
31
|
|
|
self.medium.export.assert_called_with('serialized prov', self.format) |
32
|
|
|
self.assertEqual(sentinel.mediumOutput, out) |
33
|
|
|
|
34
|
|
|
def test_Passes_single_item_of_provenance_to_exporter(self): |
35
|
|
|
self.export(sentinel.image, 'a medium','a format') |
36
|
|
|
self.format.serialize.assert_any_call(sentinel.image) |
37
|
|
|
|
38
|
|
|
def test_Can_export_pipeline_for_file(self): |
39
|
|
|
out = self.export(sentinel.image, 'a medium','a format', pipeline=True) |
40
|
|
|
self.pipelineFactory.forFile.assert_called_with(sentinel.image) |
41
|
|
|
self.format.serialize.assert_called_with( |
42
|
|
|
self.pipelineFactory.forFile()) |
43
|
|
|
|
44
|
|
|
def test_Backup_passes_all_images_to_export(self): |
45
|
|
|
import niprov.exporting |
46
|
|
|
niprov.exporting.export = Mock() |
47
|
|
|
niprov.exporting.backup(self.dependencies) |
48
|
|
|
niprov.exporting.export.assert_called_with(self.query.all(), |
49
|
|
|
medium='file', form='json', dependencies=self.dependencies) |
50
|
|
|
|
51
|
|
|
|
52
|
|
|
|
53
|
|
|
|
54
|
|
|
|