ExportingTest.patchJsonFileConstructor()   A
last analyzed

Complexity

Conditions 2

Size

Total Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
dl 0
loc 7
rs 9.4285
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A ExportingTest.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