Beispiel #1
0
    def test_cache_local_file_not_exists(self):
        '''
        Test if cache_local_file handles a nonexistent file.
        '''
        path = 'saltk//saltines'
        ret = ''

        self.assertEqual(cp.cache_local_file(path), ret)
Beispiel #2
0
    def test_cache_local_file_not_exists(self):
        '''
        Test if cache_local_file handles a nonexistent file.
        '''
        path = 'saltk//saltines'
        ret = ''

        self.assertEqual(cp.cache_local_file(path), ret)
Beispiel #3
0
    def test_cache_local_file_already_cached(self):
        '''
        Test if cache_local_file handles an already cached file.
        '''
        path = 'saltk//saltines'
        dest_file = '/srv/salt/cheese/saltines'
        mock_hash = {'hsum': 'deadbeef'}
        ret = dest_file

        with patch('salt.modules.cp.hash_file',
                   MagicMock(return_value=mock_hash)):
            with patch('salt.modules.cp.is_cached',
                       MagicMock(return_value=dest_file)):
                self.assertEqual(cp.cache_local_file(path), ret)
Beispiel #4
0
    def test_cache_local_file_already_cached(self):
        '''
        Test if cache_local_file handles an already cached file.
        '''
        path = 'saltk//saltines'
        dest_file = '/srv/salt/cheese/saltines'
        mock_hash = {'hsum': 'deadbeef'}
        ret = dest_file

        with patch('salt.modules.cp.hash_file',
                   MagicMock(return_value=mock_hash)):
            with patch('salt.modules.cp.is_cached',
                       MagicMock(return_value=dest_file)):
                self.assertEqual(cp.cache_local_file(path), ret)
Beispiel #5
0
    def test_cache_local_file_success(self):
        '''
        Test if cache_local_file succeeds.
        '''
        path = 'saltk//saltines'
        dest_file = '/srv/salt/cheese/saltines'
        ret = dest_file

        class MockFileClient(object):
            def cache_local_file(self, path):
                return dest_file

        mock_file_client = MockFileClient()
        with patch('salt.modules.cp.is_cached',
                   MagicMock(return_value=False)):
            with patch.dict(cp.__context__, {'cp.fileclient': mock_file_client}):
                self.assertEqual(cp.cache_local_file(path), ret)
Beispiel #6
0
    def test_cache_local_file_success(self):
        '''
        Test if cache_local_file succeeds.
        '''
        path = 'saltk//saltines'
        dest_file = '/srv/salt/cheese/saltines'
        ret = dest_file

        class MockFileClient(object):
            def cache_local_file(self, path):
                return dest_file

        mock_file_client = MockFileClient()
        with patch('salt.modules.cp.is_cached',
                   MagicMock(return_value=False)):
            with patch.dict(cp.__context__, {'cp.fileclient': mock_file_client}):
                self.assertEqual(cp.cache_local_file(path), ret)