They'll come up handy, and will help to verify whether
the Params class is behaving like we intended.

Signed-off-by: Lucas Meneghel Rodrigues <[email protected]>
---
 virttest/utils_params_unittest.py | 84 +++++++++++++++++++++++++++++++++++++++
 1 file changed, 84 insertions(+)
 create mode 100755 virttest/utils_params_unittest.py

diff --git a/virttest/utils_params_unittest.py 
b/virttest/utils_params_unittest.py
new file mode 100755
index 0000000..a751950
--- /dev/null
+++ b/virttest/utils_params_unittest.py
@@ -0,0 +1,84 @@
+#!/usr/bin/python
+
+import unittest
+try:
+    import autotest.common as common
+except ImportError:
+    import common
+import utils_params
+
+BASE_DICT = {
+ 'image_boot': 'yes',
+ 'image_boot_stg': 'no',
+ 'image_chain': '',
+ 'image_clone_command': 'cp --reflink=auto %s %s',
+ 'image_format': 'qcow2',
+ 'image_format_stg': 'qcow2',
+ 'image_name': 'images/f18-64',
+ 'image_name_stg': 'enospc',
+ 'image_raw_device': 'no',
+ 'image_remove_command': 'rm -rf %s',
+ 'image_size': '10G',
+ 'image_snapshot_stg': 'no',
+ 'image_unbootable_pattern': 'Hard Disk.*not a bootable disk',
+ 'image_verify_bootable': 'yes',
+ 'images': 'image1 stg',
+}
+
+CORRECT_RESULT_MAPPING = {"image1": {'image_boot_stg': 'no',
+                                     'image_snapshot_stg': 'no',
+                                     'image_chain': '',
+                                     'image_unbootable_pattern': 'Hard 
Disk.*not a bootable disk',
+                                     'image_name': 'images/f18-64',
+                                     'image_remove_command': 'rm -rf %s',
+                                     'image_name_stg': 'enospc',
+                                     'image_clone_command': 'cp --reflink=auto 
%s %s',
+                                     'image_size': '10G', 'images': 'image1 
stg',
+                                     'image_raw_device': 'no',
+                                     'image_format': 'qcow2',
+                                     'image_boot': 'yes',
+                                     'image_verify_bootable': 'yes',
+                                     'image_format_stg': 'qcow2'},
+                          "stg": {'image_snapshot': 'no',
+                                  'image_boot_stg': 'no',
+                                  'image_snapshot_stg': 'no',
+                                  'image_chain': '',
+                                  'image_unbootable_pattern': 'Hard Disk.*not 
a bootable disk',
+                                  'image_name': 'enospc',
+                                  'image_remove_command': 'rm -rf %s',
+                                  'image_name_stg': 'enospc',
+                                  'image_clone_command': 'cp --reflink=auto %s 
%s',
+                                  'image_size': '10G',
+                                  'images': 'image1 stg',
+                                  'image_raw_device': 'no',
+                                  'image_format': 'qcow2',
+                                  'image_boot': 'no',
+                                  'image_verify_bootable': 'yes',
+                                  'image_format_stg': 'qcow2'}}
+
+class TestParams(unittest.TestCase):
+    def setUp(self):
+        self.params = utils_params.Params(BASE_DICT)
+
+    def testObjects(self):
+        self.assertEquals(self.params.objects("images"), ['image1', 'stg'])
+
+    def testObjectsParams(self):
+        for key in CORRECT_RESULT_MAPPING.keys():
+            self.assertEquals(self.params.object_params(key),
+                              CORRECT_RESULT_MAPPING[key])
+
+    def testGetItemMissing(self):
+        try:
+            self.params['bogus']
+            raise ValueError("Did not get a ParamNotFound error when trying "
+                             "to access a non-existing param")
+        except utils_params.ParamNotFound:
+            pass
+
+    def testGetItem(self):
+        self.assertEqual(self.params['image_size'], "10G")
+
+
+if __name__ == "__main__":
+    unittest.main()
\ No newline at end of file
-- 
1.8.2

_______________________________________________
Virt-test-devel mailing list
[email protected]
https://www.redhat.com/mailman/listinfo/virt-test-devel

Reply via email to