[Kimchi-devel] [PATCH 5/6 V6] Host's repositories management: Update test-cases.

Paulo Vital pvital at linux.vnet.ibm.com
Wed Feb 19 01:08:48 UTC 2014


Added unit tests into test_model.py and test_rest.py

Signed-off-by: Paulo Vital <pvital at linux.vnet.ibm.com>
---
 tests/test_model.py | 100 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 tests/test_rest.py  |  38 ++++++++++++++++++++
 2 files changed, 138 insertions(+)

diff --git a/tests/test_model.py b/tests/test_model.py
index 73d89bf..298a39e 100644
--- a/tests/test_model.py
+++ b/tests/test_model.py
@@ -899,6 +899,106 @@ class ModelTests(unittest.TestCase):
             volumes = inst.storagevolumes_get_list(args['name'])
             self.assertEquals(len(volumes), 2)
 
+    def test_repository_create(self):
+        inst = model.Model('test:///default',
+                           objstore_loc=self.tmp_store)
+
+        system_host_repos = len(inst.repositories_get_list())
+
+        test_repos = [{'repo_id': 'fedora-fake',
+                       'baseurl': 'http://www.fedora.org'},
+                      {'repo_id': 'fedora-updates-fake',
+                       'baseurl': 'http://www.fedora.org/updates',
+                       'is_mirror': True,
+                       'gpgkey': 'file:///tmp/KEY-fedora-updates-fake-19'}]
+
+        for repo in test_repos:
+            inst.repositories_create(repo)
+        host_repos = inst.repositories_get_list()
+        self.assertEquals(system_host_repos+len(test_repos), len(host_repos))
+
+        for repo in test_repos:
+            repo_info = inst.repository_lookup(repo.get('repo_id'))
+            self.assertEquals(repo.get('repo_id'), repo_info.get('repo_id'))
+            self.assertEquals(repo.get('baseurl', []),
+                              repo_info.get('baseurl'))
+            self.assertEquals(repo.get('is_mirror', False),
+                              repo_info.get('is_mirror'))
+            self.assertEquals(True, repo_info.get('enabled'))
+
+            if 'gpgkey' in repo.keys():
+                gpgcheck = True
+            else:
+                gpgcheck = False
+
+            self.assertEquals(gpgcheck, repo_info.get('gpgcheck'))
+
+        self.assertRaises(NotFoundError, inst.repository_lookup, 'google')
+
+        # remove files created
+        for repo in test_repos:
+            inst.repository_delete(repo['repo_id'])
+            self.assertRaises(NotFoundError,
+                              inst.repository_lookup, repo['repo_id'])
+
+    def test_repository_update(self):
+        inst = model.Model('test:///default',
+                           objstore_loc=self.tmp_store)
+
+        system_host_repos = len(inst.repositories_get_list())
+
+        repo = {'repo_id': 'fedora-fake',
+                'repo_name': 'Fedora 19 FAKE',
+                'baseurl': 'http://www.fedora.org'}
+        inst.repositories_create(repo)
+
+        host_repos = inst.repositories_get_list()
+        self.assertEquals(system_host_repos+1, len(host_repos))
+
+        new_repo = {'repo_id': 'fedora-fake',
+                    'repo_name': 'Fedora 19 Update FAKE',
+                    'baseurl': 'http://www.fedora.org/update'}
+
+        inst.repository_update(repo['repo_id'], new_repo)
+        repo_info = inst.repository_lookup(new_repo.get('repo_id'))
+        self.assertEquals(new_repo.get('repo_id'), repo_info.get('repo_id'))
+        self.assertEquals(new_repo.get('repo_name'),
+                          repo_info.get('repo_name'))
+        self.assertEquals(new_repo.get('baseurl', None),
+                          repo_info.get('baseurl'))
+        self.assertEquals(True, repo_info.get('enabled'))
+
+        # remove files creates
+        inst.repository_delete(repo['repo_id'])
+
+    def test_repository_disable_enable(self):
+        inst = model.Model('test:///default',
+                           objstore_loc=self.tmp_store)
+
+        system_host_repos = len(inst.repositories_get_list())
+
+        repo = {'repo_id': 'fedora-fake',
+                'repo_name': 'Fedora 19 FAKE',
+                'baseurl': 'http://www.fedora.org'}
+        inst.repositories_create(repo)
+
+        host_repos = inst.repositories_get_list()
+        self.assertEquals(system_host_repos+1, len(host_repos))
+
+        repo_info = inst.repository_lookup(repo.get('repo_id'))
+        self.assertEquals(True, repo_info.get('enabled'))
+
+        inst.repository_disable(repo.get('repo_id'))
+        repo_info = inst.repository_lookup(repo.get('repo_id'))
+        self.assertEquals(False, repo_info.get('enabled'))
+
+        inst.repository_enable(repo.get('repo_id'))
+        repo_info = inst.repository_lookup(repo.get('repo_id'))
+        self.assertEquals(True, repo_info.get('enabled'))
+
+        # remove files creates
+        inst.repository_delete(repo['repo_id'])
+
 
 class BaseModelTests(unittest.TestCase):
     class FoosModel(object):
diff --git a/tests/test_rest.py b/tests/test_rest.py
index 26078d6..c1689bd 100644
--- a/tests/test_rest.py
+++ b/tests/test_rest.py
@@ -1504,6 +1504,44 @@ class RestTests(unittest.TestCase):
         self.assertEquals(1, len(res))
         self.assertEquals('test-vm1', res[0]['name'])
 
+    def test_repositories(self):
+        def verify_repo(t, res):
+            for field in ('repo_id', 'repo_name', 'baseurl', 'is_mirror',
+                          'url_args', 'enabled', 'gpgcheck', 'gpgkey'):
+                if field in t.keys():
+                    self.assertEquals(t[field], res[field])
+
+        base_uri = '/host/repositories'
+        resp = self.request(base_uri)
+        self.assertEquals(200, resp.status)
+        # Already have one repo in Kimchi's system
+        self.assertEquals(1, len(json.loads(resp.read())))
+
+
+        # Create a repository
+        repo = {'repo_id': 'fedora-fake',
+                'baseurl': 'http://www.fedora.org'}
+        req = json.dumps(repo)
+        resp = self.request(base_uri, req, 'POST')
+        self.assertEquals(201, resp.status)
+
+        # Verify the repositorie
+        res = json.loads(self.request('%s/fedora-fake' % base_uri).read())
+        verify_repo(repo, res)
+
+        # Update the repository
+        repo['baseurl'] = 'http://www.fedora.org/update'
+        req = json.dumps(repo)
+        resp = self.request('%s/fedora-fake' % base_uri, req, 'PUT')
+        
+        # Verify the repository
+        res = json.loads(self.request('%s/fedora-fake' % base_uri).read())
+        verify_repo(repo, res)
+        
+        # Delete the repository
+        resp = self.request('%s/fedora-fake' % base_uri, '{}', 'DELETE')
+        self.assertEquals(204, resp.status)
+
 
 class HttpsRestTests(RestTests):
     """
-- 
1.8.3.1




More information about the Kimchi-devel mailing list