[Kimchi-devel] [PATCH 5/7] Host's software update: Update test cases.

Aline Manera alinefm at linux.vnet.ibm.com
Thu Feb 13 14:07:31 UTC 2014


From: Paulo Vital <pvital at linux.vnet.ibm.com>

Added unit tests into test_mockmodel.py

Signed-off-by: Paulo Vital <pvital at linux.vnet.ibm.com>
---
 tests/test_mockmodel.py |   15 +++++++++++++++
 tests/test_rest.py      |   28 ++++++++++++++++++++++++++++
 2 files changed, 43 insertions(+)

diff --git a/tests/test_mockmodel.py b/tests/test_mockmodel.py
index 29413a9..b985fe0 100644
--- a/tests/test_mockmodel.py
+++ b/tests/test_mockmodel.py
@@ -152,3 +152,18 @@ class MockModelTests(unittest.TestCase):
         self.assertEquals(stats_keys, set(eval(info['stats']).keys()))
         self.assertEquals('vnc', info['graphics']['type'])
         self.assertEquals('0.0.0.0', info['graphics']['listen'])
+
+    def test_packages_update(self):
+        pkgs = model.packagesupdate_get_list()
+        self.assertEquals(3, len(pkgs))
+
+        for pkg_name in pkgs:
+            pkgupdate = model.packageupdate_lookup(pkg_name)
+            self.assertIn('package_name', pkgupdate.keys())
+            self.assertIn('repository', pkgupdate.keys())
+            self.assertIn('arch', pkgupdate.keys())
+            self.assertIn('version', pkgupdate.keys())
+
+        task = model.packagesupdate_update()
+        task_params = [u'id', u'message', u'status', u'target_uri']
+        self.assertEquals(sorted(task_params), sorted(task.keys()))
diff --git a/tests/test_rest.py b/tests/test_rest.py
index b72ff0b..69702a9 100644
--- a/tests/test_rest.py
+++ b/tests/test_rest.py
@@ -1300,6 +1300,34 @@ class RestTests(unittest.TestCase):
         self.assertIn('net_recv_rate', stats)
         self.assertIn('net_sent_rate', stats)
 
+    def test_packages_update(self):
+        resp = self.request('/host/packagesupdate', None, 'GET')
+        pkgs = json.loads(resp.read())
+        self.assertEquals(3, len(pkgs))
+
+        for p in pkgs:
+            name = p['package_name']
+            resp = self.request('/host/packagesupdate/' + name, None, 'GET')
+            info = json.loads(resp.read())
+            self.assertIn('package_name', info.keys())
+            self.assertIn('repository', info.keys())
+            self.assertIn('arch', info.keys())
+            self.assertIn('version', info.keys())
+
+        resp = self.request('/host/packagesupdate/update', '{}', 'POST')
+        task = json.loads(resp.read())
+        task_params = [u'id', u'message', u'status', u'target_uri']
+        self.assertEquals(sorted(task_params), sorted(task.keys()))
+
+        resp = self.request('/tasks/' + task[u'id'], None, 'GET')
+        task_info = json.loads(resp.read())
+        self.assertEquals(task_info['status'], 'running')
+        time.sleep(6)
+        resp = self.request('/tasks/' + task[u'id'], None, 'GET')
+        task_info = json.loads(resp.read())
+        self.assertEquals(task_info['status'], 'finished')
+        self.assertIn(u'All packages updated', task_info['message'])
+
     def test_get_param(self):
         req = json.dumps({'name': 'test', 'cdrom': '/nonexistent.iso'})
         self.request('/templates', req, 'POST')
-- 
1.7.10.4




More information about the Kimchi-devel mailing list