def test_check_root_privilege(self): with ExitStack() as resources: mock_geteuid = resources.enter_context( patch('os.geteuid', return_value=0)) resources.enter_context( patch('pwd.getpwuid', return_value=['test'])) check_root_privilege() mock_geteuid.assert_called_with()
def test_check_root_privilege_non_root(self): with ExitStack() as resources: mock_geteuid = resources.enter_context( patch('os.geteuid', return_value=1)) resources.enter_context( patch('pwd.getpwuid', return_value=['test'])) with self.assertRaises(PrivilegeError) as cm: check_root_privilege() mock_geteuid.assert_called_with() self.assertEqual(cm.exception.user_name, 'test')
def test_check_root_privilege_non_root(self): with ExitStack() as resources: mock_geteuid = resources.enter_context( patch('os.geteuid', return_value=1)) resources.enter_context( patch('pwd.getpwuid', return_value=['test'])) with self.assertRaises(PrivilegeError) as cm: check_root_privilege() mock_geteuid.assert_called_with() self.assertEqual( cm.exception.user_name, 'test')
def __init__(self, args): super().__init__(args) self.gadget_tree = args.gadget_tree # It's required to run ubuntu-image as root to build classic image. check_root_privilege()