Exemple #1
0
    def test_is_not_root(self, monkeypatch):
        def func():
            return True # pragma: no cover
        monkeypatch.setattr(decorators.os, 'getuid', lambda: 20)
        with pytest.raises(exceptions.SuperUserError) as error:
            decorators.needs_root(func)()

        msg = 'This command needs to be executed with sudo or as root'
        assert str(error.value) == msg
    def test_is_not_root(self, monkeypatch):
        def func():
            return True # pragma: no cover
        monkeypatch.setattr(decorators.os, 'getuid', lambda: 20)
        with pytest.raises(exceptions.SuperUserError) as error:
            decorators.needs_root(func)()

        msg = 'This command needs to be executed with sudo or as root'
        assert str(error.value) == msg
Exemple #3
0
 def test_is_root(self, monkeypatch):
     def func():
         return True
     monkeypatch.setattr(decorators.os, 'getuid', lambda: 0)
     assert decorators.needs_root(func)() is True
Exemple #4
0
 def test_is_not_root_env_var_skip_needs_root(self, monkeypatch):
     def func():
         return True
     monkeypatch.setattr(decorators.os, 'getuid', lambda: 123)
     monkeypatch.setattr(decorators.os, 'environ', {'CEPH_VOLUME_SKIP_NEEDS_ROOT': '1'})
     assert decorators.needs_root(func)() is True
 def test_is_root(self, monkeypatch):
     def func():
         return True
     monkeypatch.setattr(decorators.os, 'getuid', lambda: 0)
     assert decorators.needs_root(func)() is True