Ejemplo n.º 1
0
    def test_managed(self):
        ret = {
            'changes': {},
            'comment': 'Loaded.',
            'name': 'test',
            'result': False
        }
        parse = MagicMock(return_value='abcdef')
        temp_file = MagicMock(return_value='')
        compliance_report = MagicMock(return_value={'complies': False})
        load_config = MagicMock(return_value={'comment': 'Loaded.'})
        file_remove = MagicMock()

        with patch('salt.utils.files.fopen'):
            with patch.dict(
                    netyang.__salt__, {
                        'temp.file': temp_file,
                        'napalm_yang.parse': parse,
                        'napalm_yang.load_config': load_config,
                        'napalm_yang.compliance_report': compliance_report,
                        'file.remove': file_remove
                    }):
                with patch.dict(netyang.__opts__, {'test': False}):
                    self.assertDictEqual(
                        netyang.managed('test', 'test', models=('model1', )),
                        ret)
                    assert parse.called
                    assert temp_file.called
                    assert compliance_report.called
                    assert load_config.called
                    assert file_remove.called
    def test_managed(self):
        ret = {
            "changes": {},
            "comment": "Loaded.",
            "name": "test",
            "result": False
        }
        parse = MagicMock(return_value="abcdef")
        temp_file = MagicMock(return_value="")
        compliance_report = MagicMock(return_value={"complies": False})
        load_config = MagicMock(return_value={"comment": "Loaded."})
        file_remove = MagicMock()

        with patch("salt.utils.files.fopen"):
            with patch.dict(
                    netyang.__salt__,
                {
                    "temp.file": temp_file,
                    "napalm_yang.parse": parse,
                    "napalm_yang.load_config": load_config,
                    "napalm_yang.compliance_report": compliance_report,
                    "file.remove": file_remove,
                },
            ):
                with patch.dict(netyang.__opts__, {"test": False}):
                    self.assertDictEqual(
                        netyang.managed("test", "test", models=("model1", )),
                        ret)
                    assert parse.called
                    assert temp_file.called
                    assert compliance_report.called
                    assert load_config.called
                    assert file_remove.called