

def test_calls(self):
    passwd = 'jenkins:x:1000:1000::/home/jenkins:/bin/bash'
    group = 'jenkins:x:1000:'
    uids = {
        'john': ('1001', '1001'),
    }
    gids = {
        'john': ('1001', ''),
    }
    mngids.parse(passwd, uids)
    mngids.parse(group, gids, True)
    cmd = ['useradd', 'john']
    orig = mngids.call_addgroup
    mngids.call_addgroup = (lambda x: x)
    mngids.parse_cmdline(cmd, uids, gids)
    mngids.call_addgroup = orig
    self.assertEquals(cmd[1], '--uid')
    self.assertEquals(cmd[2], '1001')
    cmd = ['useradd', 'john', '-u', '1001']
    orig = mngids.call_addgroup
    mngids.call_addgroup = (lambda x: x)
    mngids.parse_cmdline(cmd, uids, gids)
    mngids.call_addgroup = orig
    self.assertEquals(cmd[1], '--gid')
    self.assertEquals(cmd[2], '1001')
    self.assertEquals(cmd[4], '-u')
    self.assertEquals(cmd[5], '1001')
    cmd = ['useradd', 'john', '-u', '1001', '-g', '1001']
    mngids.parse_cmdline(cmd, uids, gids)
    self.assertEquals(cmd[2], '-u')
    self.assertEquals(cmd[3], '1001')
    self.assertEquals(cmd[4], '-g')
    self.assertEquals(cmd[5], '1001')
    cmd = ['useradd', 'john', '-u', '1001', '-g', '1002']
    with self.assertRaises(KeyError):
        mngids.parse_cmdline(cmd, uids, gids)
    uids = {
        'john': ('1001', '1002'),
    }
    gids = {
        'john': ('1002', ''),
    }
    mngids.parse(passwd, uids)
    mngids.parse(group, gids, True)
    cmd = ['useradd', 'john', '-u', '1001']
    orig = mngids.call_addgroup
    mngids.call_addgroup = (lambda x: x)
    mngids.parse_cmdline(cmd, uids, gids)
    mngids.call_addgroup = orig
    self.assertEquals(cmd[1], '--gid')
    self.assertEquals(cmd[2], '1002')
    self.assertEquals(cmd[4], '-u')
    self.assertEquals(cmd[5], '1001')

dataset/ETHPy150Open redhat-cip/edeploy/build/test_mngids.py TestMngids.test_calls/original