Complete test coverage for os_vm_quota_cores (#14)

This commit is contained in:
Major Hayden 2017-03-09 14:55:44 -06:00 committed by GitHub
parent 143b0b8d75
commit 3114e7a123
2 changed files with 31 additions and 2 deletions

View File

@ -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 = {

View File

@ -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'