ExportingTest   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 24
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
dl 0
loc 24
rs 10
c 0
b 0
f 0
wmc 5

4 Methods

Rating   Name   Duplication   Size   Complexity  
A test_import() 0 10 2
A patchJsonFileConstructor() 0 7 2
A setUp() 0 3 1
A ctr() 0 3 1
1
from mock import Mock, patch, sentinel
2
from tests.ditest import DependencyInjectionTestBase
3
from datetime import datetime
4
5
6
class ExportingTest(DependencyInjectionTestBase):
7
8
    def setUp(self):
9
        super(ExportingTest, self).setUp()
10
        self.tempRepo = Mock()
11
12
    def test_import(self):
13
        import niprov.importing 
14
        self.tempRepo.all.return_value = [sentinel.p1, sentinel.p2]
15
        niprov.importing.JsonFile = self.patchJsonFileConstructor()
16
        niprov.importing.importp('target_file', dependencies=self.dependencies)
17
        assert self.JsonFileCtr.called, "Did not create a JsonFile repo."
18
        urlUsed = self.tempRepo.dependencies.getConfiguration().database_url
19
        self.assertEqual(urlUsed, 'target_file')
20
        self.repo.add.assert_any_call(sentinel.p1)
21
        self.repo.add.assert_any_call(sentinel.p2)
22
23
    def patchJsonFileConstructor(self):
24
        self.JsonFileCtr = Mock()
25
        def ctr(dependencies): 
26
            self.tempRepo.dependencies = dependencies
27
            return self.tempRepo
28
        self.JsonFileCtr.side_effect = ctr
29
        return self.JsonFileCtr
30
31
32
33