def test_process_main(self, symlink, exists, makedirs, mock_get_packages): """ Assert correct operation from the process_main() method with our _GET_UNITS_RETURN data. """ _seen_paths = [] def mock_exists(path): """ This mocks the return value of exists to return False the first time a path is given to it, and True every time thereafter for that same path. """ if path not in _seen_paths: _seen_paths.append(path) return False return True exists.side_effect = mock_exists step = steps.PublishContentStep() mock_get_packages.return_value = _GET_PACKAGES_RETURN conduit = mock.MagicMock() step.get_conduit = mock.MagicMock(return_value=conduit) step.parent = mock.MagicMock() step.parent.web_working_dir = '/some/path/' step.process_main() step.get_conduit.assert_called_once_with() mock_get_packages.assert_called_once_with(conduit.repo_id) # os.path.exists should have been called once for each Unit. It also gets called for a lot # of locale stuff, so we'll need to filter those out. pulp_exists_calls = [ c for c in exists.mock_calls if 'locale' not in c[1][0] ] self.assertEqual(len(pulp_exists_calls), 3) expected_symlink_args = [(u.storage_path, steps._get_package_path(u.name, u._filename)) for u in _PACKAGES] expected_symlink_args = [(a[0], os.path.join(step.parent.web_working_dir, a[1])) for a in expected_symlink_args] expected_exists_call_args = [(os.path.dirname(a[1]), ) for a in expected_symlink_args] actual_exists_call_args = [c[1] for c in pulp_exists_calls] self.assertEqual(set(actual_exists_call_args), set(expected_exists_call_args)) # os.makedirs should only have been called twice, since there are two versions of Nectar and # they share a directory. This is also going to be the same set as the exists set. self.assertEqual(makedirs.call_count, 2) makedirs_call_args = [c[1] for c in makedirs.mock_calls] self.assertEqual(set(makedirs_call_args), set(expected_exists_call_args)) # Lastly, three calls to symlink should have been made, one for each Unit. self.assertEqual(symlink.call_count, 3) actual_mock_call_args = [c[1] for c in symlink.mock_calls] self.assertEqual(set(actual_mock_call_args), set(expected_symlink_args))
def test___init__(self, super___init__): """ Assert correct behavior from the __init__() method. """ step = steps.PublishContentStep() super___init__.assert_called_once_with(constants.PUBLISH_STEP_CONTENT) self.assertEqual(step.context, None) self.assertEqual(step.redirect_context, None) self.assertEqual(step.description, _('Publishing Python Content.'))