summaryrefslogtreecommitdiff
path: root/service/test/bitmask_libraries/soledad_test.py
blob: 1c1c105eb4ea87d4401327d02c8bd9bdc2c02a70 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
from mock import patch
from app.bitmask_libraries.soledad import SoledadSession
from abstract_leap_test import AbstractLeapTest


@patch('app.bitmask_libraries.soledad.Soledad')
class SoledadSessionTest(AbstractLeapTest):

    def setUp(self):
        #given
        self.provider.fetch_soledad_json.return_value = {'hosts': {
            'couch1': {
                'hostname': 'couch1.some-server.test',
                'ip_address': '192.168.1.1',
                'port': 1234
            }
        }}

    @patch('app.bitmask_libraries.soledad.Soledad.__init__')
    def test_that_soledad_is_created_with_required_params(self, soledad_mock, init_mock):
        #when
        SoledadSession(self.provider, 'any-passphrase', self.srp_session)

        #then
        init_mock.assert_called_with(self.uuid, 'any-passphrase', '%s/soledad/%s.secret' % (self.leap_home, self.uuid),
                                            '%s/soledad/%s.db' % (self.leap_home, self.uuid),
                                            'https://couch1.some-server.test:1234/user-%s' % self.uuid,
                                            '/some/path/to/ca_cert', self.token)

    def test_that_sync_is_called(self, soledad_mock):
            instance = soledad_mock.return_value
            instance.server_url  = '/foo/bar'
            instance.need_sync.return_value = True
            soledad_session = SoledadSession(self.provider, 'any-passphrase', self.srp_session)

            #when
            soledad_session.sync()

            #then
            instance.need_sync.assert_called_with('/foo/bar')
            instance.sync.assert_called_with()

    def test_that_sync_not_called_if_not_needed(self, mock):
            instance = mock.return_value
            instance.server_url  = '/foo/bar'
            instance.need_sync.return_value = False
            soledad_session = SoledadSession(self.provider, 'any-passphrase', self.srp_session)

            #when
            soledad_session.sync()

            #then
            instance.need_sync.assert_called_with('/foo/bar')
            self.assertFalse(instance.sync.called)