/usr/lib/python2.7/dist-packages/shotgun/test/test_manager.py is in python-shotgun 0.1.0+2016.12.30.git.0682f20c42-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
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 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 | # Copyright 2015 Mirantis, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
from collections import deque
import tempfile
import fabric.exceptions
import mock
from shotgun.config import Config
from shotgun.manager import Manager
from shotgun.test import base
class TestManager(base.BaseTestCase):
@mock.patch('shotgun.manager.Driver.getDriver')
@mock.patch('shotgun.manager.utils.execute')
@mock.patch('shotgun.manager.utils.compress')
def test_snapshot(self, mcompress, mexecute, mget):
data = {
"type": "file",
"path": "/remote_dir/remote_file",
"host": {
"address": "remote_host",
},
}
conf = mock.MagicMock()
conf.target = "/target/data"
conf.objects = [data]
conf.lastdump = tempfile.mkstemp()[1]
conf.self_log_object = {"type": "file", "path": "/path"}
manager = Manager(conf)
manager.snapshot()
calls = [mock.call(data, conf), mock.call(conf.self_log_object, conf)]
mget.assert_has_calls(calls, any_order=True)
mexecute.assert_called_once_with('rm -rf /target')
@mock.patch('shotgun.manager.Driver.getDriver')
@mock.patch('shotgun.manager.utils.execute')
@mock.patch('shotgun.manager.utils.compress')
def test_snapshot_network_error(self, mcompress, mexecute, mget):
objs = [
{"type": "file",
"path": "/remote_file1",
"host": {"address": "remote_host1"},
},
{"type": "dir",
"path": "/remote_dir1",
"host": {"address": "remote_host1"},
},
{"type": "file",
"path": "/remote_file1",
"host": {"address": "remote_host2"},
},
]
drv = mock.MagicMock()
drv.snapshot.side_effect = [
fabric.exceptions.NetworkError,
None,
fabric.exceptions.NetworkError,
None,
None,
]
mget.return_value = drv
conf = Config()
conf.objs = deque(objs)
offline_obj = {
'path': '/remote_file1',
'host': {'address': 'remote_host1'},
'type': 'offline',
}
processed_obj = {
'path': '/remote_file1',
'host': {'address': 'remote_host2'},
'type': 'file',
}
manager = Manager(conf)
manager.snapshot()
mget.assert_has_calls([mock.call(offline_obj, conf),
mock.call(processed_obj, conf),
mock.call(offline_obj, conf),
mock.call(offline_obj, conf)], any_order=True)
mexecute.assert_called_once_with('rm -rf /tmp')
@mock.patch('shotgun.manager.Manager.action_single')
def test_report(self, mock_action):
objs = ["o1", "o2"]
mock_action.side_effect = [["r1", "r2"], ["r3"]]
conf = mock.Mock()
conf.objects = objs
manager = Manager(conf)
manager.action_single = mock_action
reports = []
for rep in manager.report():
reports.append(rep)
self.assertEqual(["r1", "r2", "r3"], reports)
expected_calls = [
mock.call('o1', action='report'),
mock.call('o2', action='report')]
self.assertEqual(expected_calls, mock_action.call_args_list)
@mock.patch('shotgun.manager.Driver')
def test_action_single(self, mock_driver):
mock_driver_instance = mock.Mock()
mock_driver_instance.report = mock.Mock()
mock_driver_instance.snapshot = mock.Mock()
mock_driver.getDriver = mock.Mock(return_value=mock_driver_instance)
manager = Manager('conf')
manager.action_single('object', action='report')
mock_driver.getDriver.assert_called_once_with('object', 'conf')
mock_driver_instance.report.assert_called_once_with()
self.assertFalse(mock_driver_instance.snapshot.called)
mock_driver.getDriver.reset_mock()
# default action should be 'snapshot'
manager.action_single('object')
mock_driver.getDriver.assert_called_once_with('object', 'conf')
mock_driver_instance.report.mock_reset()
mock_driver_instance.snapshot.assert_called_once_with()
self.assertFalse(mock_driver_instance.report.called)
|