From 3114e7a123faaa48958361a26d2c1ce6f7d09e7d Mon Sep 17 00:00:00 2001 From: Major Hayden Date: Thu, 9 Mar 2017 14:55:44 -0600 Subject: [PATCH] Complete test coverage for os_vm_quota_cores (#14) --- monitorstack/plugins/os_vm_quota_cores.py | 2 ++ tests/test_os_vm.py | 31 +++++++++++++++++++++-- 2 files changed, 31 insertions(+), 2 deletions(-) diff --git a/monitorstack/plugins/os_vm_quota_cores.py b/monitorstack/plugins/os_vm_quota_cores.py index 37198e0..d04e0ed 100644 --- a/monitorstack/plugins/os_vm_quota_cores.py +++ b/monitorstack/plugins/os_vm_quota_cores.py @@ -11,6 +11,7 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. +"""Get nova cores quotas.""" import click @@ -29,6 +30,7 @@ COMMAND_NAME = 'os_vm_quota_cores' default='openstack.ini') @pass_context def cli(ctx, config_file): + """Get nova cores quotas.""" setattr(cli, '__doc__', DOC) output = { diff --git a/tests/test_os_vm.py b/tests/test_os_vm.py index 4457900..dc38e08 100644 --- a/tests/test_os_vm.py +++ b/tests/test_os_vm.py @@ -18,6 +18,7 @@ import json from click.testing import CliRunner from monitorstack.cli import cli +from monitorstack.utils.os_utils import OpenStack as Ost def _runner(module): @@ -27,14 +28,40 @@ def _runner(module): module, '--config-file', 'tests/files/test-openstack.ini', ]) - print(result) return json.loads(result.output) +class MockProject(object): + """Mock class for OpenStack class.""" + + def __init__(self): + """Mock init.""" + self.id = 'testing' + self.name = 'testing' + + class TestOs(object): """Tests for the os_vm.* monitors.""" - def test_os_vm_quota_cores(self): + def test_os_vm_quota_cores_success(self, monkeypatch): + """Ensure the run() method works.""" + def mock_get_projects(arg1): + projects = MockProject() + return [projects] + + def mock_get_compute_limits(self, project_id, interface): + return {'quota_set': {'cores': 10}} + + monkeypatch.setattr(Ost, 'get_projects', mock_get_projects) + monkeypatch.setattr(Ost, 'get_compute_limits', mock_get_compute_limits) + + result = _runner('os_vm_quota_cores') + from pprint import pprint + pprint(result) + assert result['measurement_name'] == 'os_vm_quota_cores' + assert result['meta'] == {'quotas': 'cores'} + + def test_os_vm_quota_cores_failure(self): """Ensure the run() method works.""" result = _runner('os_vm_quota_cores') assert result['measurement_name'] == 'os_vm_quota_cores'