diff options
| author | Dean Troyer <dtroyer@gmail.com> | 2013-07-03 16:47:40 -0500 |
|---|---|---|
| committer | Dean Troyer <dtroyer@gmail.com> | 2013-08-16 14:35:46 -0500 |
| commit | 493339d4da6b56f46416fff583ff6cc7748570ec (patch) | |
| tree | 847fe6214daca6548d41d402d89b92e618173991 /openstackclient/tests/fakes.py | |
| parent | 93612bbf53500bfeace7460e7cb317ed0073a6d1 (diff) | |
| download | python-openstackclient-493339d4da6b56f46416fff583ff6cc7748570ec.tar.gz | |
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
Diffstat (limited to 'openstackclient/tests/fakes.py')
| -rw-r--r-- | openstackclient/tests/fakes.py | 62 |
1 files changed, 62 insertions, 0 deletions
diff --git a/openstackclient/tests/fakes.py b/openstackclient/tests/fakes.py new file mode 100644 index 00000000..d0cd4a9f --- /dev/null +++ b/openstackclient/tests/fakes.py @@ -0,0 +1,62 @@ +# 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 +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, 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. +# + +import sys + + +class FakeStdout: + def __init__(self): + self.content = [] + + def write(self, text): + self.content.append(text) + + def make_string(self): + result = '' + for line in self.content: + result = result + line + return result + + +class FakeApp(object): + def __init__(self, _stdout): + self.stdout = _stdout + self.client_manager = None + self.stdin = sys.stdin + self.stdout = _stdout or sys.stdout + self.stderr = sys.stderr + + +class FakeClientManager(object): + def __init__(self): + pass + + +class FakeResource(object): + def __init__(self, manager, info, loaded=False): + self.manager = manager + self._info = info + self._add_details(info) + self._loaded = loaded + + def _add_details(self, info): + for (k, v) in info.iteritems(): + setattr(self, k, v) + + def __repr__(self): + reprkeys = sorted(k for k in self.__dict__.keys() if k[0] != '_' and + k != 'manager') + info = ", ".join("%s=%s" % (k, getattr(self, k)) for k in reprkeys) + return "<%s %s>" % (self.__class__.__name__, info) |
