Revision ea9d3b40 test/py/ganeti.cli_unittest.py

b/test/py/ganeti.cli_unittest.py
1423 1423
      self._TestFullISpecsInner(skel_ipolicy, exp_minmax1, None,
1424 1424
                                False, fill_all)
1425 1425

  
1426

  
1427
class TestPrintIPolicyCommand(unittest.TestCase):
1428
  """Test case for cli.PrintIPolicyCommand"""
1429
  _SPECS1 = {
1430
    "par1": 42,
1431
    "par2": "xyz",
1432
    }
1433
  _SPECS1_STR = "par1=42,par2=xyz"
1434
  _SPECS2 = {
1435
    "param": 10,
1436
    "another_param": 101,
1437
    }
1438
  _SPECS2_STR = "another_param=101,param=10"
1439

  
1440
  def _CheckPrintIPolicyCommand(self, ipolicy, isgroup, expected):
1441
    buf = StringIO()
1442
    cli.PrintIPolicyCommand(buf, ipolicy, isgroup)
1443
    self.assertEqual(buf.getvalue(), expected)
1444

  
1445
  def testIgnoreStdForGroup(self):
1446
    self._CheckPrintIPolicyCommand({"std": self._SPECS1}, True, "")
1447

  
1448
  def testIgnoreEmpty(self):
1449
    policies = [
1450
      {},
1451
      {"std": {}},
1452
      {"minmax": {}},
1453
      {"minmax": {
1454
        "min": {},
1455
        "max": {},
1456
        }},
1457
      {"minmax": {
1458
        "min": self._SPECS1,
1459
        "max": {},
1460
        }},
1461
      ]
1462
    for pol in policies:
1463
      self._CheckPrintIPolicyCommand(pol, False, "")
1464

  
1465
  def testFullPolicies(self):
1466
    cases = [
1467
      ({"std": self._SPECS1},
1468
       " %s %s" % (cli.IPOLICY_STD_SPECS_STR, self._SPECS1_STR)),
1469
      ({"minmax": {
1470
        "min": self._SPECS1,
1471
        "max": self._SPECS2,
1472
        }},
1473
       " %s min:%s/max:%s" % (cli.IPOLICY_BOUNDS_SPECS_STR,
1474
                              self._SPECS1_STR, self._SPECS2_STR)),
1475
      ]
1476
    for (pol, exp) in cases:
1477
      self._CheckPrintIPolicyCommand(pol, False, exp)
1478

  
1479

  
1426 1480
if __name__ == "__main__":
1427 1481
  testutils.GanetiTestProgram()

Also available in: Unified diff