From: ShaoHe Feng <shaohef(a)linux.vnet.ibm.com>
update test_rest.py and test_model.py
Signed-off-by: ShaoHe Feng <shaohef(a)linux.vnet.ibm.com>
---
tests/test_model.py | 18 ++++++++++++++++++
tests/test_rest.py | 15 +++++++++++++++
2 files changed, 33 insertions(+)
diff --git a/tests/test_model.py b/tests/test_model.py
index b374d2d..74cff87 100644
--- a/tests/test_model.py
+++ b/tests/test_model.py
@@ -21,6 +21,7 @@
# License along with this library; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+import cherrypy
import os
import platform
import psutil
@@ -380,6 +381,23 @@ class ModelTests(unittest.TestCase):
self.assertEquals(params[key], info[key])
@unittest.skipUnless(utils.running_as_root(), 'Must be run as root')
+ def test_template_clone(self):
+ inst = model.Model('qemu:///system',
+ objstore_loc=self.tmp_store)
+ with RollbackContext() as rollback:
+ orig_params = {'name': 'test-template', 'memory':
1024, 'cpus': 1}
+ inst.templates_create(orig_params)
+ orig_temp = inst.template_lookup(orig_params['name'])
+
+ self.assertRaises(cherrypy.HTTPRedirect,
+ inst.template_clone, 'test-template')
+ clone_temp = inst.template_lookup('test-template%s' %
"-clone1")
+
+ clone_temp['name'] = orig_temp['name']
+ for key in clone_temp.keys():
+ self.assertEquals(clone_temp[key], orig_temp[key])
+
+ @unittest.skipUnless(utils.running_as_root(), 'Must be run as root')
def test_template_update(self):
inst = model.Model('qemu:///system',
objstore_loc=self.tmp_store)
diff --git a/tests/test_rest.py b/tests/test_rest.py
index 69b8316..6401d95 100644
--- a/tests/test_rest.py
+++ b/tests/test_rest.py
@@ -811,6 +811,21 @@ class RestTests(unittest.TestCase):
res = json.loads(self.request('/templates/test').read())
verify_template(t, res)
+ # clone a template
+ resp = self.request('/templates/%s/clone' % t['name'],
'{}', 'POST')
+ self.assertEquals(303, resp.status)
+
+ # Verify the clone template
+ res = json.loads(self.request('/templates/%s-clone1' %
+ t['name']).read())
+ old_temp = t['name']
+ t['name'] = res['name']
+ verify_template(t, res)
+ # Delete the clone template
+ resp = self.request('/templates/%s' % t['name'], '{}',
'DELETE')
+ self.assertEquals(204, resp.status)
+ t['name'] = old_temp
+
# Create a template with same name fails with 400
t = {'name': 'test', 'os_distro': 'ImagineOS',
'os_version': '1.0', 'memory': 1024, 'cpus':
1,
--
1.8.4.2