Completed
Pull Request — master (#127)
by Jasper
01:07
created

ExportingTests   A

Complexity

Total Complexity 14

Size/Duplication

Total Lines 68
Duplicated Lines 0 %
Metric Value
dl 0
loc 68
rs 10
wmc 14

13 Methods

Rating   Name   Duplication   Size   Complexity  
A test_Obtains_medium_from_factory() 0 5 1
A test_Passes_single_item_of_provenance_to_exporter() 0 4 1
A test_Can_export_all_files_for_subject() 0 4 1
A test_Can_export_one_file_specifically() 0 3 1
A test_Can_export_stats() 0 3 1
A test_Can_export_pipeline_for_file() 0 5 1
A test_Passes_provenance_through_format_and_medium() 0 7 1
A test_Without_specifics_returns_latest_files() 0 3 1
A test_Obtains_format_from_factory() 0 5 1
A test_If_file_unknown_tells_listener() 0 6 2
A export() 0 3 1
A setUp() 0 2 1
A test_Completes_locationString_forFile() 0 4 1
1
import unittest
2
from mock import sentinel
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(form='json', medium='x')
16
        self.formatFactory.create.assert_any_call('json')
17
        self.export(form='xml', medium='x')
18
        self.formatFactory.create.assert_any_call('xml')
19
20
    def test_Obtains_medium_from_factory(self):
21
        self.export(medium='file', form='x')
22
        self.mediumFactory.create.assert_any_call('file')
23
        self.export(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('a medium','a format')
30
        self.format.serialize.assert_any_call(self.repo.latest())
31
        self.medium.export.assert_called_with('serialized prov', self.format)
32
        self.assertEqual(sentinel.mediumOutput, out)
33
34
    def test_Without_specifics_returns_latest_files(self):
35
        out = self.export('a medium','a format')
36
        self.format.serialize.assert_called_with(self.repo.latest())
37
38
    def test_Can_export_one_file_specifically(self):
39
        out = self.export('a medium','a format',forFile='afile.f')
40
        self.format.serialize.assert_called_with(self.repo.byLocation('afile.f'))
41
42
    def test_Can_export_all_files_for_subject(self):
43
        out = self.export('a medium','a format',forSubject='Jane Doe')
44
        self.format.serialize.assert_called_with(
45
            self.repo.bySubject('Jane Doe'))
46
47
    def test_Passes_single_item_of_provenance_to_exporter(self):
48
        self.export('a medium','a format',forFile='xyz')
49
        self.format.serialize.assert_any_call(
50
            self.repo.byLocation('xyz'))
51
52
    def test_Can_export_stats(self):
53
        out = self.export('a medium','a format',statistics=True)
54
        self.format.serialize.assert_called_with(self.repo.statistics())
55
56
    def test_Completes_locationString_forFile(self):
57
        out = self.export('a medium','a format',forFile='afile.f')
58
        self.locationFactory.completeString.assert_any_call('afile.f')
59
        self.repo.byLocation.assert_called_with(self.locationFactory.completeString())
60
61
    def test_If_file_unknown_tells_listener(self):
62
        self.locationFactory.completeString.side_effect = lambda p: p
63
        self.repo.knowsByLocation.return_value = False
64
        self.repo.byLocation.side_effect = IndexError
65
        self.export('a medium','a format',forFile='xyz')
66
        self.listener.unknownFile.assert_called_with('xyz')
67
68
    def test_Can_export_pipeline_for_file(self):
69
        out = self.export('a medium','a format', forFile='a/b/c', pipeline=True)
70
        self.pipelineFactory.forFile.assert_called_with(self.repo.byLocation())
71
        self.format.serialize.assert_called_with(
72
            self.pipelineFactory.forFile())
73
74
75
76
77