diff options
author | Paul Kehrer <paul.l.kehrer@gmail.com> | 2014-03-20 09:06:11 -0400 |
---|---|---|
committer | Paul Kehrer <paul.l.kehrer@gmail.com> | 2014-03-20 09:30:12 -0400 |
commit | cc78b2a2a8c08322a64fa56ce17d06628b18485a (patch) | |
tree | ab4609e1045cef47a4575a983cd7638235fa0e68 | |
parent | 026db28334c3e1ee38cb9171c4b28735fe748b3b (diff) | |
download | python-barbicanclient-cc78b2a2a8c08322a64fa56ce17d06628b18485a.tar.gz |
port tests to testtools, add branch coverage, omit openstack common
Change-Id: I364dcaac1db1922cc815ece455a69734aa6c51f6
-rw-r--r-- | .coveragerc | 3 | ||||
-rw-r--r-- | .gitignore | 4 | ||||
-rw-r--r-- | .testr.conf | 5 | ||||
-rw-r--r-- | barbicanclient/test/common/test_auth.py | 48 | ||||
-rw-r--r-- | barbicanclient/test/test_barbican.py | 18 | ||||
-rw-r--r-- | barbicanclient/test/test_client.py | 28 | ||||
-rw-r--r-- | barbicanclient/test/test_client_orders.py | 6 | ||||
-rw-r--r-- | barbicanclient/test/test_client_secrets.py | 17 | ||||
-rw-r--r-- | barbicanclient/test/test_client_verifications.py | 6 | ||||
-rw-r--r-- | test-requirements.txt | 7 | ||||
-rw-r--r-- | tox.ini | 25 |
11 files changed, 71 insertions, 96 deletions
diff --git a/.coveragerc b/.coveragerc new file mode 100644 index 0000000..6b48db2 --- /dev/null +++ b/.coveragerc @@ -0,0 +1,3 @@ +[run] +branch = True +omit = barbicanclient/openstack/* @@ -24,9 +24,9 @@ pip-log.txt # Unit test / coverage reports .coverage .tox -nosetests.xml -coverage.xml +.testrepository flake8.log +cover # pyenv .python-version diff --git a/.testr.conf b/.testr.conf new file mode 100644 index 0000000..0d13a20 --- /dev/null +++ b/.testr.conf @@ -0,0 +1,5 @@ +[DEFAULT] +test_command=${PYTHON:-python} -m subunit.run discover -t . $LISTOPT $IDOPTION + +test_id_option=--load-list $IDFILE +test_list_option=--list diff --git a/barbicanclient/test/common/test_auth.py b/barbicanclient/test/common/test_auth.py index eb7eb25..52db65c 100644 --- a/barbicanclient/test/common/test_auth.py +++ b/barbicanclient/test/common/test_auth.py @@ -16,14 +16,15 @@ import json import mock import requests -import unittest2 as unittest +import testtools from barbicanclient.common import auth -class WhenTestingKeystoneAuthentication(unittest.TestCase): +class WhenTestingKeystoneAuthentication(testtools.TestCase): def setUp(self): + super(WhenTestingKeystoneAuthentication, self).setUp() self.keystone_client = mock.MagicMock() self.auth_url = 'https://www.yada.com' @@ -41,8 +42,8 @@ class WhenTestingKeystoneAuthentication(unittest.TestCase): self.keystone_client) def test_endpoint_username_password_tenant_are_required(self): - with self.assertRaises(ValueError): - keystone = auth.KeystoneAuthV2() + with testtools.ExpectedException(ValueError): + auth.KeystoneAuthV2() def test_nothing_is_required_if_keystone_is_present(self): fake_keystone = mock.Mock(tenant_name='foo', tenant_id='bar') @@ -56,9 +57,10 @@ class WhenTestingKeystoneAuthentication(unittest.TestCase): self.assertEquals(barbican_url, self.keystone_auth.barbican_url) -class WhenTestingRackspaceAuthentication(unittest.TestCase): +class WhenTestingRackspaceAuthentication(testtools.TestCase): def setUp(self): + super(WhenTestingRackspaceAuthentication, self).setUp() self._auth_url = 'https://auth.url.com' self._username = 'username' self._api_key = 'api_key' @@ -85,16 +87,16 @@ class WhenTestingRackspaceAuthentication(unittest.TestCase): self.addCleanup(patcher.stop) def test_auth_url_username_and_api_key_are_required(self): - with self.assertRaises(ValueError): - identity = auth.RackspaceAuthV2() - with self.assertRaises(ValueError): - identity = auth.RackspaceAuthV2(self._auth_url) - with self.assertRaises(ValueError): - identity = auth.RackspaceAuthV2(self._auth_url, - self._username) - with self.assertRaises(ValueError): - identity = auth.RackspaceAuthV2(self._auth_url, - api_key=self._api_key) + with testtools.ExpectedException(ValueError): + auth.RackspaceAuthV2() + with testtools.ExpectedException(ValueError): + auth.RackspaceAuthV2(self._auth_url) + with testtools.ExpectedException(ValueError): + auth.RackspaceAuthV2(self._auth_url, + self._username) + with testtools.ExpectedException(ValueError): + auth.RackspaceAuthV2(self._auth_url, + api_key=self._api_key) def test_tokens_is_appended_to_auth_url(self): identity = auth.RackspaceAuthV2(self._auth_url, @@ -129,17 +131,17 @@ class WhenTestingRackspaceAuthentication(unittest.TestCase): def test_auth_exception_thrown_for_bad_status(self): self._response.status_code = 400 - with self.assertRaises(auth.AuthException): - identity = auth.RackspaceAuthV2(self._auth_url, - self._username, - api_key=self._api_key) + with testtools.ExpectedException(auth.AuthException): + auth.RackspaceAuthV2(self._auth_url, + self._username, + api_key=self._api_key) def test_error_raised_for_bad_response_from_server(self): self._response._content = 'Not JSON' - with self.assertRaises(auth.AuthException): - identity = auth.RackspaceAuthV2(self._auth_url, - self._username, - api_key=self._api_key) + with testtools.ExpectedException(auth.AuthException): + auth.RackspaceAuthV2(self._auth_url, + self._username, + api_key=self._api_key) def test_auth_token_is_set(self): identity = auth.RackspaceAuthV2(self._auth_url, diff --git a/barbicanclient/test/test_barbican.py b/barbicanclient/test/test_barbican.py index c784ea3..2c9f512 100644 --- a/barbicanclient/test/test_barbican.py +++ b/barbicanclient/test/test_barbican.py @@ -16,20 +16,12 @@ import cStringIO import os import sys -import unittest2 as unittest +import testtools import barbicanclient.barbican -def suite(): - suite = unittest.TestSuite() - - suite.addTest(TestBarbican()) - - return suite - - -class TestBarbican(unittest.TestCase): +class TestBarbican(testtools.TestCase): def barbican(self, argstr): """Source: Keystone client's shell method in test_shell.py""" orig = sys.stdout @@ -49,12 +41,6 @@ class TestBarbican(unittest.TestCase): os.environ = _old_env return out - def setUp(self): - pass - def test_help(self): args = "-h" self.assertIn('usage: ', self.barbican(args)) - -if __name__ == '__main__': - unittest.main() diff --git a/barbicanclient/test/test_client.py b/barbicanclient/test/test_client.py index dbc3324..f69fb3e 100644 --- a/barbicanclient/test/test_client.py +++ b/barbicanclient/test/test_client.py @@ -15,7 +15,7 @@ import mock import requests -import unittest2 as unittest +import testtools from barbicanclient import client from barbicanclient.openstack.common import timeutils @@ -47,8 +47,9 @@ class FakeResp(object): return self.content -class WhenTestingClientInit(unittest.TestCase): +class WhenTestingClientInit(testtools.TestCase): def setUp(self): + super(WhenTestingClientInit, self).setUp() self.auth_endpoint = 'https://localhost:5000/v2.0/' self.auth_token = 'fake_auth_token' self.user = 'user' @@ -79,12 +80,12 @@ class WhenTestingClientInit(unittest.TestCase): self.auth_token) def test_error_thrown_when_no_auth_and_no_endpoint(self): - with self.assertRaises(ValueError): - c = client.Client(tenant_id=self.tenant_id) + self.assertRaises(ValueError, client.Client, + **{"tenant_id": self.tenant_id}) def test_error_thrown_when_no_auth_and_no_tenant_id(self): - with self.assertRaises(ValueError): - c = client.Client(endpoint=self.endpoint) + self.assertRaises(ValueError, client.Client, + **{"endpoint": self.endpoint}) def test_client_strips_trailing_slash_from_endpoint(self): c = client.Client(endpoint=self.endpoint, tenant_id=self.tenant_id) @@ -97,24 +98,22 @@ class WhenTestingClientInit(unittest.TestCase): def test_should_raise_for_unauthorized_response(self): resp = self._mock_response(status_code=401) c = client.Client(auth_plugin=self.fake_auth) - with self.assertRaises(client.HTTPAuthError): - c._check_status_code(resp) + self.assertRaises(client.HTTPAuthError, c._check_status_code, resp) def test_should_raise_for_server_error(self): resp = self._mock_response(status_code=500) c = client.Client(auth_plugin=self.fake_auth) - with self.assertRaises(client.HTTPServerError): - c._check_status_code(resp) + self.assertRaises(client.HTTPServerError, c._check_status_code, resp) def test_should_raise_for_client_errors(self): resp = self._mock_response(status_code=400) c = client.Client(auth_plugin=self.fake_auth) - with self.assertRaises(client.HTTPClientError): - c._check_status_code(resp) + self.assertRaises(client.HTTPClientError, c._check_status_code, resp) -class WhenTestingClientWithSession(unittest.TestCase): +class WhenTestingClientWithSession(testtools.TestCase): def setUp(self): + super(WhenTestingClientWithSession, self).setUp() self.endpoint = 'https://localhost:9311/v1/' self.tenant_id = '1234567' @@ -195,8 +194,9 @@ class WhenTestingClientWithSession(unittest.TestCase): self.assertEqual(self.entity_href, url) -class BaseEntityResource(unittest.TestCase): +class BaseEntityResource(testtools.TestCase): def _setUp(self, entity): + super(BaseEntityResource, self).setUp() self.endpoint = 'https://localhost:9311/v1/' self.tenant_id = '1234567' diff --git a/barbicanclient/test/test_client_orders.py b/barbicanclient/test/test_client_orders.py index b6f1d99..a554862 100644 --- a/barbicanclient/test/test_client_orders.py +++ b/barbicanclient/test/test_client_orders.py @@ -123,9 +123,7 @@ class WhenTestingOrders(test_client.BaseEntityResource): self.assertEqual(5, params['offset']) def test_should_fail_get_no_href(self): - with self.assertRaises(ValueError): - self.manager.get(None) + self.assertRaises(ValueError, self.manager.get, None) def test_should_fail_delete_no_href(self): - with self.assertRaises(ValueError): - self.manager.delete(None) + self.assertRaises(ValueError, self.manager.delete, None) diff --git a/barbicanclient/test/test_client_secrets.py b/barbicanclient/test/test_client_secrets.py index 1d2c28c..f93df26 100644 --- a/barbicanclient/test/test_client_secrets.py +++ b/barbicanclient/test/test_client_secrets.py @@ -163,27 +163,24 @@ class WhenTestingSecrets(test_client.BaseEntityResource): self.assertEqual(5, params['offset']) def test_should_fail_get_invalid_secret(self): - with self.assertRaises(ValueError): - self.manager.get('12345') + self.assertRaises(ValueError, self.manager.get, '12345') def test_should_fail_get_no_href(self): - with self.assertRaises(ValueError): - self.manager.get(None) + self.assertRaises(ValueError, self.manager.get, None) def test_should_fail_decrypt_no_content_types(self): self.api.get.return_value = self.secret.get_dict(self.entity_href) - with self.assertRaises(ValueError): - self.manager.decrypt(secret_ref=self.entity_href) + self.assertRaises(ValueError, self.manager.decrypt, + **{"secret_ref": self.entity_href}) def test_should_fail_decrypt_no_default_content_type(self): content_types_dict = {'no-default': 'application/octet-stream'} self.api.get.return_value = self.secret.get_dict(self.entity_href, content_types_dict) - with self.assertRaises(ValueError): - self.manager.decrypt(secret_ref=self.entity_href) + self.assertRaises(ValueError, self.manager.decrypt, + **{"secret_ref": self.entity_href}) def test_should_fail_delete_no_href(self): - with self.assertRaises(ValueError): - self.manager.delete(None) + self.assertRaises(ValueError, self.manager.get, None) diff --git a/barbicanclient/test/test_client_verifications.py b/barbicanclient/test/test_client_verifications.py index d7f3b8f..d887ac3 100644 --- a/barbicanclient/test/test_client_verifications.py +++ b/barbicanclient/test/test_client_verifications.py @@ -127,9 +127,7 @@ class WhenTestingVerifications(test_client.BaseEntityResource): self.assertEqual(5, params['offset']) def test_should_fail_get_no_href(self): - with self.assertRaises(ValueError): - self.manager.get(None) + self.assertRaises(ValueError, self.manager.get, None) def test_should_fail_delete_no_href(self): - with self.assertRaises(ValueError): - self.manager.delete(None) + self.assertRaises(ValueError, self.manager.delete, None) diff --git a/test-requirements.txt b/test-requirements.txt index 3c5872c..647888c 100644 --- a/test-requirements.txt +++ b/test-requirements.txt @@ -1,6 +1,7 @@ +coverage>=3.6 +discover hacking>=0.7.0 mock>=1.0.1 -nose>=1.3.0 -nosexcover>=1.0.8 +testrepository>=0.0.17 +testtools>=0.9.32,<0.9.35 tox>=1.6.0 -unittest2>=0.5.1 @@ -7,24 +7,15 @@ envlist = py26, py27, pep8 [testenv] -setenv = VIRTUAL_ENV={envdir} - LANG=en_US.UTF-8 - LANGUAGE=en_US:en - LC_ALL=C - OS_STDOUT_NOCAPTURE=False - OS_STDERR_NOCAPTURE=False - deps = -r{toxinidir}/requirements.txt -r{toxinidir}/test-requirements.txt +commands = + python setup.py testr --coverage + coverage combine + coverage report -m [testenv:pep8] -commands = {toxinidir}/tools/hacking.sh - -[testenv:venv] -commands = {posargs} - -[testenv:cover] -commands = nosetests --with-coverage --cover-package=barbicanclient +commands = {toxinidir}/tools/hacking.sh {posargs} [tox:jenkins] downloadcache = ~/cache/pip @@ -33,9 +24,3 @@ downloadcache = ~/cache/pip ignore = F,H show-source = True exclude = .venv,.tox,dist,doc,*egg - -[testenv:py26] -commands = nosetests {posargs:--with-xcoverage --all-modules --cover-inclusive --traverse-namespace --with-xunit --cover-package=barbicanclient} - -[testenv:py27] -commands = nosetests {posargs:--with-xcoverage --all-modules --cover-inclusive --traverse-namespace --with-xunit --cover-package=barbicanclient} |