First pass at adding compute unit tests.
Change-Id: Icf3340d457f75eec89bb0e5c9b4b953c3b81020f
This commit is contained in:
		 Josh Kearney
					Josh Kearney
				
			
				
					committed by
					
						 Dean Troyer
						Dean Troyer
					
				
			
			
				
	
			
			
			 Dean Troyer
						Dean Troyer
					
				
			
						parent
						
							1bb59c53ee
						
					
				
				
					commit
					4297e5781b
				
			
							
								
								
									
										14
									
								
								tests/compute/__init__.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										14
									
								
								tests/compute/__init__.py
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,14 @@ | ||||
| #   Copyright 2013 OpenStack, LLC. | ||||
| # | ||||
| #   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. | ||||
| # | ||||
							
								
								
									
										59
									
								
								tests/compute/test_compute.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										59
									
								
								tests/compute/test_compute.py
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,59 @@ | ||||
| #   Copyright 2013 OpenStack, LLC. | ||||
| # | ||||
| #   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 mock | ||||
|  | ||||
| from openstackclient.common import clientmanager | ||||
| from openstackclient.compute import client as compute_client | ||||
| from tests import utils | ||||
|  | ||||
|  | ||||
| class FakeClient(object): | ||||
|     def __init__(self, endpoint=None, **kwargs): | ||||
|         self.client = mock.MagicMock() | ||||
|         self.servers = mock.MagicMock() | ||||
|  | ||||
|         self.client.auth_url = kwargs['auth_url'] | ||||
|  | ||||
|  | ||||
| class TestCompute(utils.TestCase): | ||||
|     def setUp(self): | ||||
|         super(TestCompute, self).setUp() | ||||
|  | ||||
|         self.auth_token = "foobar" | ||||
|         self.auth_url = "http://0.0.0.0" | ||||
|  | ||||
|         api_version = {"compute": "2"} | ||||
|  | ||||
|         compute_client.API_VERSIONS = { | ||||
|             "2": "tests.compute.test_compute.FakeClient" | ||||
|         } | ||||
|  | ||||
|         self.cm = clientmanager.ClientManager(token=self.auth_token, | ||||
|                                               url=self.auth_url, | ||||
|                                               auth_url=self.auth_url, | ||||
|                                               api_version=api_version) | ||||
|  | ||||
|     def test_make_client(self): | ||||
|         test_servers = [ | ||||
|             ["id 1", "name 1", "status 1", "networks 1"], | ||||
|             ["id 2", "name 2", "status 2", "networks 2"] | ||||
|         ] | ||||
|  | ||||
|         self.cm.compute.servers.list.return_value = test_servers | ||||
|  | ||||
|         self.assertEqual(self.cm.compute.servers.list(), test_servers) | ||||
|         self.assertEqual(self.cm.compute.client.auth_token, self.auth_token) | ||||
|         self.assertEqual(self.cm.compute.client.auth_url, self.auth_url) | ||||
| @@ -14,23 +14,22 @@ | ||||
| # | ||||
| 
 | ||||
| from openstackclient.common import clientmanager | ||||
| 
 | ||||
| 
 | ||||
| def factory(inst): | ||||
|     return object() | ||||
| from tests import utils | ||||
| 
 | ||||
| 
 | ||||
| class Container(object): | ||||
|     attr = clientmanager.ClientCache(lambda x: object()) | ||||
| 
 | ||||
|     attr = clientmanager.ClientCache(factory) | ||||
| 
 | ||||
|     def init_token(self): | ||||
|         return | ||||
|     def __init__(self): | ||||
|         pass | ||||
| 
 | ||||
| 
 | ||||
| def test_singleton(): | ||||
|     # Verify that the ClientCache descriptor only | ||||
|     # invokes the factory one time and always | ||||
|     # returns the same value after that. | ||||
| class TestClientManager(utils.TestCase): | ||||
|     def setUp(self): | ||||
|         super(TestClientManager, self).setUp() | ||||
| 
 | ||||
|     def test_singleton(self): | ||||
|         # NOTE(dtroyer): Verify that the ClientCache descriptor only invokes | ||||
|         # the factory one time and always returns the same value after that. | ||||
|         c = Container() | ||||
|     assert c.attr is c.attr | ||||
|         self.assertEqual(c.attr, c.attr) | ||||
| @@ -13,10 +13,10 @@ | ||||
| #   under the License. | ||||
| # | ||||
|  | ||||
| import fixtures | ||||
| import os | ||||
| import mock | ||||
|  | ||||
| import fixtures | ||||
| from openstackclient import shell as os_shell | ||||
| from tests import utils | ||||
|  | ||||
| @@ -47,8 +47,7 @@ def make_shell(): | ||||
|     return _shell | ||||
|  | ||||
|  | ||||
| class ShellTest(utils.TestCase): | ||||
|  | ||||
| class TestShell(utils.TestCase): | ||||
|     FAKE_ENV = { | ||||
|         'OS_AUTH_URL': DEFAULT_AUTH_URL, | ||||
|         'OS_TENANT_ID': DEFAULT_TENANT_ID, | ||||
| @@ -60,7 +59,7 @@ class ShellTest(utils.TestCase): | ||||
|  | ||||
|     def setUp(self): | ||||
|         """ Patch os.environ to avoid required auth info""" | ||||
|         super(ShellTest, self).setUp() | ||||
|         super(TestShell, self).setUp() | ||||
|         for var in self.FAKE_ENV: | ||||
|             self.useFixture( | ||||
|                 fixtures.EnvironmentVariable( | ||||
| @@ -85,7 +84,7 @@ class ShellTest(utils.TestCase): | ||||
|     def tearDown(self): | ||||
|         #self.auth_patch.stop() | ||||
|         self.cmd_patch.stop() | ||||
|         super(ShellTest, self).tearDown() | ||||
|         super(TestShell, self).tearDown() | ||||
|  | ||||
|     def test_shell_args(self): | ||||
|         sh = make_shell() | ||||
|   | ||||
| @@ -22,14 +22,13 @@ import testtools | ||||
| class TestCase(testtools.TestCase): | ||||
|     def setUp(self): | ||||
|         super(TestCase, self).setUp() | ||||
|  | ||||
|         if (os.environ.get("OS_STDOUT_NOCAPTURE") == "True" and | ||||
|                 os.environ.get("OS_STDOUT_NOCAPTURE") == "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"): | ||||
|             stderr = self.useFixture(fixtures.StringStream("stderr")).stream | ||||
|             self.useFixture(fixtures.MonkeyPatch("sys.stderr", stderr)) | ||||
|  | ||||
|     def tearDown(self): | ||||
|         super(TestCase, self).tearDown() | ||||
|   | ||||
		Reference in New Issue
	
	Block a user