@@ -0,0 +1,2173 @@
+import pytest%0A%0A%0A@pytest.fixture%0Adef mockctl(testdir):%0A    testdir.makepyfile(mockctl=%22%22%22%0A        import mock%0A        pytest_plugins = 'sangoma.lab.roles'%0A%0A        def pytest_lab_addroles(rolemanager):%0A            rolemanager.register('mock', mock.Mock())%0A    %22%22%22)%0A%0A%0Adef test_manage_location(testdir):%0A    testdir.makeconftest(%22%22%22%0A        pytest_plugins = 'sangoma.lab.roles'%0A    %22%22%22)%0A%0A    testdir.makepyfile(%22%22%22%0A        import pytest%0A%0A        FACTS = %7B'testing': True%7D%0A%0A        def test_manage():%0A            localhost = pytest.env.manage('localhost', facts=FACTS)%0A            assert localhost.hostname == 'localhost'%0A            assert localhost.facts == FACTS%0A    %22%22%22)%0A%0A    # Needs a subprocess because of plumbums's atexit hooks%0A    result = testdir.runpytest_subprocess('--env', 'mock')%0A    assert result.ret == 0%0A%0A%0Adef test_add_role(mockctl, testdir):%0A    testdir.makeconftest(%22%22%22%0A        import pytest%0A        pytest_plugins = 'mockctl'%0A%0A        @pytest.fixture%0A        def localhost():%0A            return pytest.env.manage('localhost')%0A%0A        def pytest_lab_register_role(config, ctl):%0A            if ctl.name == 'mock':%0A                ctl.setup()%0A%0A        def pytest_lab_delete_role(config, ctl):%0A            if ctl.name == 'mock':%0A                ctl.teardown()%0A    %22%22%22)%0A%0A    testdir.makepyfile(%22%22%22%0A        def test_add_role(localhost):%0A            role = localhost.role('mock')%0A            assert role.name == 'mock'%0A            role.setup.assert_called_once_with()%0A%0A            localhost.destroy(role)%0A            role.teardown.assert_called_once_with()%0A    %22%22%22)%0A%0A    result = testdir.runpytest_subprocess('--env', 'mock')%0A    assert result.ret == 0%0A%0A%0Adef test_add_unknown_role(mockctl, testdir):%0A    testdir.makeconftest(%22%22%22%0A        import pytest%0A        pytest_plugins = 'mockctl'%0A%0A        @pytest.fixture%0A        def localhost():%0A            return pytest.env.manage('localhost')%0A    %22%22%22)%0A%0A    testdir.makepyfile(%22%22%22%0A        import pytest%0A%0A        def test_add_role(localhost):%0A            with pytest.raises(KeyError):%0A                localhost.role('tyler')%0A    %22%22%22)%0A%0A    result = testdir.runpytest_subprocess('--env', 'mock')%0A    assert result.ret == 0%0A

Add unit tests for basic role stuff