On 02/10/2014 11:46 AM, Paulo Vital wrote:
Added unit tests into test_model.py and test_rest.py
Signed-off-by: Paulo Vital <pvital(a)linux.vnet.ibm.com>
---
tests/test_model.py | 99 +++++++++++++++++++++++++++++++++++++++++++++++++++++
tests/test_rest.py | 32 +++++++++++++++++
2 files changed, 131 insertions(+)
diff --git a/tests/test_model.py b/tests/test_model.py
index 4a6d2fe..40c53c0 100644
--- a/tests/test_model.py
+++ b/tests/test_model.py
@@ -794,6 +794,105 @@ 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',
+ 'mirrors': 'http://www.fedora.org/updates',
+ '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('mirrors', None),
+ repo_info.get('mirrors'))
+ 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 0ed293b..cae9e4f 100644
--- a/tests/test_rest.py
+++ b/tests/test_rest.py
@@ -1321,6 +1321,38 @@ 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',
'mirrors',
+ 'url_args', 'enabled', 'gpgcheck',
'gpgkey'):
+ self.assertEquals(t[field], res[field])
+
+ resp = self.request('/repositories')
It should be /host/repositories, right?
+ self.assertEquals(200, resp.status)
+ self.assertEquals(0, len(json.loads(resp.read())))
+
+ # Create a repository
+ repo = {'repo_id': 'fedora-fake',
+ 'repo_name': 'Fedora 19 FAKE',
+ 'baseurl': 'http://www.fedora.org'}
+ req = json.dumps(repo)
+ resp = self.request('/repositories', req, 'POST')
+ self.assertEquals(201, resp.status)
+
+ # Verify the repositorie
+ res = json.loads(self.request('/repositories/fedora-fake').read())
+ verify_template(repo, res)
+
+ # Update the repository
+ repo['baseurl'] = 'http://www.fedora.org/update'
+ req = json.dumps(repo)
+ resp = self.request('/repositories/%s' % repo['repo_id'], req,
'PUT')
+ self.assertEquals(200, resp.status)
+
+ # Verify the template
+ res = json.loads(self.request('/repositories/fedora-fake').read())
+ verify_template(repo, res)
+
class HttpsRestTests(RestTests):
"""