From 493339d4da6b56f46416fff583ff6cc7748570ec Mon Sep 17 00:00:00 2001 From: Dean Troyer Date: Wed, 3 Jul 2013 16:47:40 -0500 Subject: Add Identity v2 project tests * establish the the form of cliff command classes * implement some common fake objects * implement Identity command tests for v2 project * fix stdout/stderr capture Also re-work the project create and set commands for exclusive options (--enable|--disable) to actually behave properly. Yay tests! Change-Id: Icbb313db544c1f8dd3c9af7709971838b5a4d115 --- openstackclient/tests/utils.py | 34 +++++++++++++++++++++++++++++----- 1 file changed, 29 insertions(+), 5 deletions(-) (limited to 'openstackclient/tests/utils.py') diff --git a/openstackclient/tests/utils.py b/openstackclient/tests/utils.py index 3e24ff4a..ff7d8a33 100644 --- a/openstackclient/tests/utils.py +++ b/openstackclient/tests/utils.py @@ -1,4 +1,5 @@ -# Copyright 2012-2013 OpenStack, LLC. +# Copyright 2012-2013 OpenStack Foundation +# Copyright 2013 Nebula Inc. # # Licensed under the Apache License, Version 2.0 (the "License"); you may # not use this file except in compliance with the License. You may obtain @@ -19,18 +20,20 @@ import fixtures import sys import testtools +from openstackclient.tests import fakes + class TestCase(testtools.TestCase): def setUp(self): testtools.TestCase.setUp(self) - if (os.environ.get("OS_STDOUT_NOCAPTURE") == "True" and - os.environ.get("OS_STDOUT_NOCAPTURE") == "1"): + if (os.environ.get("OS_STDOUT_CAPTURE") == "True" or + os.environ.get("OS_STDOUT_CAPTURE") == "1"): stdout = self.useFixture(fixtures.StringStream("stdout")).stream self.useFixture(fixtures.MonkeyPatch("sys.stdout", stdout)) - if (os.environ.get("OS_STDERR_NOCAPTURE") == "True" and - os.environ.get("OS_STDERR_NOCAPTURE") == "1"): + if (os.environ.get("OS_STDERR_CAPTURE") == "True" or + os.environ.get("OS_STDERR_CAPTURE") == "1"): stderr = self.useFixture(fixtures.StringStream("stderr")).stream self.useFixture(fixtures.MonkeyPatch("sys.stderr", stderr)) @@ -57,3 +60,24 @@ class TestCase(testtools.TestCase): else: standardMsg = '%r != %r' % (d1, d2) self.fail(standardMsg) + + +class TestCommand(TestCase): + """Test cliff command classes""" + + def setUp(self): + super(TestCommand, self).setUp() + # Build up a fake app + self.fake_stdout = fakes.FakeStdout() + self.app = fakes.FakeApp(self.fake_stdout) + self.app.client_manager = fakes.FakeClientManager() + + def check_parser(self, cmd, args, verify_args): + cmd_parser = cmd.get_parser('check_parser') + parsed_args = cmd_parser.parse_args(args) + for av in verify_args: + attr, value = av + if attr: + self.assertIn(attr, parsed_args) + self.assertEqual(getattr(parsed_args, attr), value) + return parsed_args -- cgit v1.2.1