Rename OpTestJobqueue and LUTestJobqueue
[ganeti-local] / test / ganeti.opcodes_unittest.py
index 65c515e..bb77ca2 100755 (executable)
@@ -1,7 +1,7 @@
 #!/usr/bin/python
 #
 
-# Copyright (C) 2010 Google Inc.
+# Copyright (C) 2010, 2011 Google Inc.
 #
 # This program is free software; you can redistribute it and/or modify
 # it under the terms of the GNU General Public License as published by
@@ -87,6 +87,34 @@ class TestOpcodes(unittest.TestCase):
     else:
       self.assertEqual("OP_%s" % summary, op.OP_ID)
 
+  def testSummary(self):
+    class _TestOp(opcodes.OpCode):
+      OP_ID = "OP_TEST"
+      OP_DSC_FIELD = "data"
+      OP_PARAMS = [
+        ("data", ht.NoDefault, ht.TString),
+        ]
+
+    self.assertEqual(_TestOp(data="").Summary(), "TEST()")
+    self.assertEqual(_TestOp(data="Hello World").Summary(),
+                     "TEST(Hello World)")
+    self.assertEqual(_TestOp(data="node1.example.com").Summary(),
+                     "TEST(node1.example.com)")
+
+  def testListSummary(self):
+    class _TestOp(opcodes.OpCode):
+      OP_ID = "OP_TEST"
+      OP_DSC_FIELD = "data"
+      OP_PARAMS = [
+        ("data", ht.NoDefault, ht.TList),
+        ]
+
+    self.assertEqual(_TestOp(data=["a", "b", "c"]).Summary(),
+                     "TEST(a,b,c)")
+    self.assertEqual(_TestOp(data=["a", None, "c"]).Summary(),
+                     "TEST(a,None,c)")
+    self.assertEqual(_TestOp(data=[1, 2, 3, 4]).Summary(), "TEST(1,2,3,4)")
+
   def testOpId(self):
     self.assertFalse(utils.FindDuplicates(cls.OP_ID
                                           for cls in opcodes._GetOpList()))
@@ -95,10 +123,10 @@ class TestOpcodes(unittest.TestCase):
   def testParams(self):
     supported_by_all = set(["debug_level", "dry_run", "priority"])
 
-    self.assert_(opcodes.BaseOpCode not in opcodes.OP_MAPPING.values())
-    self.assert_(opcodes.OpCode in opcodes.OP_MAPPING.values())
+    self.assertTrue(opcodes.BaseOpCode not in opcodes.OP_MAPPING.values())
+    self.assertTrue(opcodes.OpCode not in opcodes.OP_MAPPING.values())
 
-    for cls in opcodes.OP_MAPPING.values():
+    for cls in opcodes.OP_MAPPING.values() + [opcodes.OpCode]:
       all_slots = cls._all_slots()
 
       self.assertEqual(len(set(all_slots) & supported_by_all), 3,