Exemplo n.º 1
0
def create_mock_environment(source_config=None, target_config=None,
                            global_config=None, mock_formulabase=None):
        temp_directory = tempfile.mkdtemp()
        environment = Environment(root=temp_directory,
                                  sprinter_namespace='test',
                                  global_config=(global_config or create_default_config()))
        environment.namespace = "test"
        if source_config:
            environment.source = load_manifest(StringIO(source_config), namespace="test")

        if target_config:
            environment.target = load_manifest(StringIO(target_config), namespace="test")

        environment.warmup()
        # TODO: implement sandboxing so no need to mock these
        environment.injections.commit = Mock()
        environment.global_injections.commit = Mock()
        environment.write_manifest = Mock()
        if mock_formulabase:
            formula_dict = {'sprinter.formula.base': mock_formulabase}
            environment.features = FeatureDict(environment,
                                               environment.source, environment.target,
                                               environment.global_path,
                                               formula_dict=formula_dict)
        return environment, temp_directory
Exemplo n.º 2
0
 def test_utilssh_file_written(self):
     """ The latest utilssh file should be written at the end of an install """
     temp_dir = tempfile.mkdtemp()
     try:
         with patch('sprinter.lib.prompt') as prompt:
             prompt.return_value = "1,2"
             env = Environment(root=temp_dir)
             env.formula_dict['sprinter.formulabase'] = Mock(return_value=create_mock_formulabase())
             env.target = StringIO(test_target)
             env.warmup()
             env.injections.commit = Mock()
             env.install()
             global_path = os.path.join(temp_dir, '.global')
             assert os.path.exists(os.path.join(global_path, 'utils.sh'))
     finally:
         shutil.rmtree(temp_dir)