From ba731e355cd5196738db214ee8b9a2d13ac61349 Mon Sep 17 00:00:00 2001 From: Liam Young Date: Fri, 14 Aug 2020 07:23:52 +0000 Subject: [PATCH] Re-enable unit tests Re-enable and fix unit tests. Unit test check of set_local removed as the json dump is not ordering dict keys and the set_local calls will be removed by an imminent patch. Change-Id: Id804e0e518c0013043db6f4b7cd44ccaa5499749 --- tox.ini | 11 +++++++---- unit_tests/test_provides.py | 2 +- unit_tests/test_requires.py | 18 ++++++++---------- 3 files changed, 16 insertions(+), 15 deletions(-) diff --git a/tox.ini b/tox.ini index e1c896a..cd3d886 100644 --- a/tox.ini +++ b/tox.ini @@ -1,5 +1,5 @@ [tox] -envlist = pep8,py35 +envlist = pep8,py3 skipsdist = True # NOTE(beisner): Avoid build/test env pollution by not enabling sitepackages. sitepackages = False @@ -13,12 +13,15 @@ install_command = pip install {opts} {packages} commands = ostestr {posargs} +[testenv:py3] +basepython = python3 +deps = -r{toxinidir}/test-requirements.txt +commands = ostestr {posargs} + [testenv:py35] basepython = python3.5 deps = -r{toxinidir}/test-requirements.txt -# TODO: Need to write unit tests then remove the following command. -# https://github.com/juju/charm-tools/issues/249 -commands = /bin/true +commands = ostestr {posargs} [testenv:py36] basepython = python3.6 diff --git a/unit_tests/test_provides.py b/unit_tests/test_provides.py index 5c9a643..1ec1547 100644 --- a/unit_tests/test_provides.py +++ b/unit_tests/test_provides.py @@ -12,7 +12,7 @@ import unittest -from unitest import mock +from unittest import mock with mock.patch('charmhelpers.core.hookenv.metadata') as _meta: diff --git a/unit_tests/test_requires.py b/unit_tests/test_requires.py index 1970fd5..0c743fd 100644 --- a/unit_tests/test_requires.py +++ b/unit_tests/test_requires.py @@ -12,7 +12,7 @@ import unittest -from unitest import mock +from unittest import mock with mock.patch('charmhelpers.core.hookenv.metadata') as _meta: @@ -173,18 +173,11 @@ class TestCephClientRequires(unittest.TestCase): @mock.patch.object(charmhelpers.contrib.storage.linux.ceph.uuid, 'uuid1') def test_create_pool_new_request(self, _uuid1): + self.patch_kr('remove_state') _uuid1.return_value = '9e34123e-fa0c-11e8-ad9c-fa163ed1cc55' - req = ( - '{"api-version": 1, ' - '"ops": [{"op": "create-pool", "name": "bob", "replicas": 3, ' - '"pg_num": null, "weight": null, "group": null, ' - '"group-namespace": null, "app-name": null, "max-bytes": null, ' - '"max-objects": null}], ' - '"request-id": "9e34123e-fa0c-11e8-ad9c-fa163ed1cc55"}') self.patch_kr('get_local', None) self.patch_kr('set_local') self.cr.create_pool('bob') - self.set_local.assert_called_once_with(key='broker_req', value=req) ceph_broker_rq = self.send_request_if_needed.mock_calls[0][1][0] self.assertEqual( ceph_broker_rq.ops, @@ -202,12 +195,14 @@ class TestCephClientRequires(unittest.TestCase): @mock.patch.object(charmhelpers.contrib.storage.linux.ceph.uuid, 'uuid1') def test_create_pool_existing_request(self, _uuid1): + self.patch_kr('remove_state') _uuid1.return_value = '9e34123e-fa0c-11e8-ad9c-fa163ed1cc55' req = ( '{"api-version": 1, ' '"ops": [{"op": "create-pool", "name": "bob", "replicas": 3, ' '"pg_num": null, "weight": null, "group": null, ' - '"group-namespace": null}], ' + '"group-namespace": null, "app-name": null, "max-bytes": null, ' + '"max-objects": null}], ' '"request-id": "9e34123e-fa0c-11e8-ad9c-fa163ed1cc55"}') self.patch_kr('get_local', req) self.cr.create_pool('bob') @@ -221,6 +216,9 @@ class TestCephClientRequires(unittest.TestCase): 'group': None, 'group-namespace': None, 'pg_num': None, + 'max-bytes': None, + 'max-objects': None, + 'app-name': None, 'weight': None}]) def test_request_access_to_group_new_request(self):