11
									
								
								tests/README.rst
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										11
									
								
								tests/README.rst
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,11 @@ | ||||
| Testing Guidelines | ||||
| ================== | ||||
|  | ||||
| * All tests adhere to pep8 standards | ||||
| * All tests must be stand-alone and deterministic | ||||
| * All tests covering HTTP transactions will have a fixture file | ||||
|     * fixture file names shall match method names | ||||
|     * fixtures should be edited to include no *more* data than necessary | ||||
|     * fixtures shall not include accessible IP addresses or credentials | ||||
| * All changes shall be accompanied by a test | ||||
| * All changes shall be associated with an issue number | ||||
| @@ -12,7 +12,10 @@ | ||||
| # 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 logging | ||||
| import os | ||||
| import unittest | ||||
| import vcr | ||||
|  | ||||
|  | ||||
| def tests_resource_path(local_path=''): | ||||
| @@ -21,3 +24,17 @@ def tests_resource_path(local_path=''): | ||||
|  | ||||
| # Fully qualified path to the fixtures directory underneath this module | ||||
| fixtures_path = tests_resource_path('fixtures') | ||||
|  | ||||
|  | ||||
| def monkey_patch_vcrpy(): | ||||
|     # TODO (hartsock): This should be unnecessary. Remove after vcrpy updates. | ||||
|     vcr.stubs.VCRHTTPSConnection.is_verified = True | ||||
|  | ||||
|  | ||||
| class VCRTestBase(unittest.TestCase): | ||||
|  | ||||
|     def setUp(self): | ||||
|         monkey_patch_vcrpy() | ||||
|         logging.basicConfig() | ||||
|         vcr_log = logging.getLogger('vcr') | ||||
|         vcr_log.setLevel(logging.DEBUG) | ||||
|   | ||||
| @@ -13,8 +13,7 @@ | ||||
| # See the License for the specific language governing permissions and | ||||
| # limitations under the License. | ||||
|  | ||||
| from tests import fixtures_path | ||||
| import logging | ||||
| import tests | ||||
| import unittest | ||||
| import vcr | ||||
|  | ||||
| @@ -22,15 +21,11 @@ from pyVim import connect | ||||
| from pyVmomi import vim | ||||
|  | ||||
|  | ||||
| class ConnectionTests(unittest.TestCase): | ||||
|  | ||||
|     def setUp(self): | ||||
|         logging.basicConfig() | ||||
|         vcr_log = logging.getLogger('vcr') | ||||
|         vcr_log.setLevel(logging.DEBUG) | ||||
| class ConnectionTests(tests.VCRTestBase): | ||||
|  | ||||
|     @vcr.use_cassette('basic_connection.yaml', | ||||
|                       cassette_library_dir=fixtures_path, record_mode='none') | ||||
|                       cassette_library_dir=tests.fixtures_path, | ||||
|                       record_mode='none') | ||||
|     def test_basic_connection(self): | ||||
|         # see: http://python3porting.com/noconv.html | ||||
|         si = connect.Connect(host='vcsa', | ||||
| @@ -47,7 +42,8 @@ class ConnectionTests(unittest.TestCase): | ||||
|         self.assertTrue(session_id in cookie) | ||||
|  | ||||
|     @vcr.use_cassette('basic_connection_bad_password.yaml', | ||||
|                       cassette_library_dir=fixtures_path, record_mode='none') | ||||
|                       cassette_library_dir=tests.fixtures_path, | ||||
|                       record_mode='none') | ||||
|     def test_basic_connection_bad_password(self): | ||||
|         def should_fail(): | ||||
|             connect.Connect(host='vcsa', | ||||
| @@ -57,7 +53,8 @@ class ConnectionTests(unittest.TestCase): | ||||
|         self.assertRaises(vim.fault.InvalidLogin, should_fail) | ||||
|  | ||||
|     @vcr.use_cassette('smart_connection.yaml', | ||||
|                       cassette_library_dir=fixtures_path, record_mode='none') | ||||
|                       cassette_library_dir=tests.fixtures_path, | ||||
|                       record_mode='none') | ||||
|     def test_smart_connection(self): | ||||
|         # see: http://python3porting.com/noconv.html | ||||
|         si = connect.SmartConnect(host='vcsa', | ||||
|   | ||||
| @@ -12,24 +12,18 @@ | ||||
| # 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. | ||||
| from tests import fixtures_path | ||||
| import logging | ||||
| import unittest | ||||
| import tests | ||||
| import vcr | ||||
|  | ||||
| from pyVim import connect | ||||
| from pyVmomi import vim | ||||
|  | ||||
|  | ||||
| class ContainerViewTests(unittest.TestCase): | ||||
|  | ||||
|     def setUp(self): | ||||
|         logging.basicConfig() | ||||
|         vcr_log = logging.getLogger('vcr') | ||||
|         vcr_log.setLevel(logging.DEBUG) | ||||
| class ContainerViewTests(tests.VCRTestBase): | ||||
|  | ||||
|     @vcr.use_cassette('basic_container_view.yaml', | ||||
|                       cassette_library_dir=fixtures_path, record_mode='once') | ||||
|                       cassette_library_dir=tests.fixtures_path, | ||||
|                       record_mode='once') | ||||
|     def test_basic_container_view(self): | ||||
|         # see: http://python3porting.com/noconv.html | ||||
|         si = connect.SmartConnect(host='vcsa', | ||||
|   | ||||
| @@ -17,8 +17,7 @@ import unittest | ||||
| import vcr | ||||
|  | ||||
| from pyVim import connect | ||||
| from pyVmomi import SoapStubAdapter | ||||
| from pyVmomi import vim | ||||
|  | ||||
|  | ||||
| class DeserializerTests(unittest.TestCase): | ||||
|  | ||||
| @@ -44,7 +43,7 @@ class DeserializerTests(unittest.TestCase): | ||||
|             # NOTE (hartsock): not using 'assertRaises' so we can inspect obj | ||||
|             fault = ex | ||||
|         # NOTE (hartsock): assertIsNotNone does not work in Python 2.6 | ||||
|         self.assertTrue(fault is not None) # only until 2.6 support is dropped. | ||||
|         self.assertTrue(fault is not None)  # only until 2.6 support is dropped | ||||
|         # Observe that the malformed XML was reported up the stack to the | ||||
|         # user so that field reports will contain SOAP message information. | ||||
|         self.assertTrue('<detail> ' | ||||
|   | ||||
| @@ -15,18 +15,18 @@ | ||||
| from datetime import datetime | ||||
| from datetime import timedelta | ||||
|  | ||||
| from tests import fixtures_path | ||||
| import unittest | ||||
| import tests | ||||
| import vcr | ||||
|  | ||||
| from pyVim import connect | ||||
| from pyVmomi.Iso8601 import TZManager | ||||
|  | ||||
|  | ||||
| class Iso8601Tests(unittest.TestCase): | ||||
| class Iso8601Tests(tests.VCRTestBase): | ||||
|  | ||||
|     @vcr.use_cassette('test_vm_config_iso8601.yaml', | ||||
|                       cassette_library_dir=fixtures_path, record_mode='once') | ||||
|                       cassette_library_dir=tests.fixtures_path, | ||||
|                       record_mode='once') | ||||
|     def test_vm_config_iso8601(self): | ||||
|         si = connect.SmartConnect(host='vcsa', | ||||
|                                   user='my_user', | ||||
| @@ -82,11 +82,10 @@ class Iso8601Tests(unittest.TestCase): | ||||
|         # NOTE (hartsock): the `match_on` option is altered to use the | ||||
|         # look at the XML body sent to the server | ||||
|         with my_vcr.use_cassette('iso8601_set_datetime.yaml', | ||||
|                                  cassette_library_dir=fixtures_path, | ||||
|                                  cassette_library_dir=tests.fixtures_path, | ||||
|                                  record_mode='once', | ||||
|                                  match_on=['method', 'scheme', 'host', 'port', | ||||
|                                            'path', 'query', 'document']): | ||||
|  | ||||
|             si = connect.SmartConnect(host='vcsa', | ||||
|                                       user='my_user', | ||||
|                                       pwd='my_password') | ||||
|   | ||||
| @@ -14,16 +14,17 @@ | ||||
| # limitations under the License. | ||||
| from __future__ import print_function | ||||
|  | ||||
| from tests import fixtures_path | ||||
| import unittest | ||||
| import tests | ||||
| import vcr | ||||
|  | ||||
| from pyVim import connect | ||||
|  | ||||
| class ManagedObjectTests(unittest.TestCase): | ||||
|  | ||||
| class ManagedObjectTests(tests.VCRTestBase): | ||||
|  | ||||
|     @vcr.use_cassette('root_folder_parent.yaml', | ||||
|                       cassette_library_dir=fixtures_path, record_mode='once') | ||||
|                       cassette_library_dir=tests.fixtures_path, | ||||
|                       record_mode='once') | ||||
|     def test_root_folder_parent(self): | ||||
|         # see: http://python3porting.com/noconv.html | ||||
|         si = connect.SmartConnect(host='vcsa', | ||||
|   | ||||
| @@ -12,15 +12,15 @@ | ||||
| # 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. | ||||
| from tests import fixtures_path | ||||
| import unittest | ||||
| import tests | ||||
| import vcr | ||||
|  | ||||
|  | ||||
| from pyVmomi import SoapStubAdapter | ||||
| from pyVmomi import vim | ||||
|  | ||||
| class SerializerTests(unittest.TestCase): | ||||
|  | ||||
| class SerializerTests(tests.VCRTestBase): | ||||
|  | ||||
|     def test_simple_request_serializer(self): | ||||
|         def request_matcher(r1, r2): | ||||
| @@ -40,7 +40,7 @@ class SerializerTests(unittest.TestCase): | ||||
|  | ||||
|         with my_vcr.use_cassette( | ||||
|                 'test_simple_request_serializer.yaml', | ||||
|                 cassette_library_dir=fixtures_path, | ||||
|                 cassette_library_dir=tests.fixtures_path, | ||||
|                 record_mode='none', | ||||
|                 match_on=['request_matcher']) as cass: | ||||
|             host = 'vcsa' | ||||
|   | ||||
| @@ -14,17 +14,18 @@ | ||||
| # limitations under the License. | ||||
| from __future__ import print_function | ||||
|  | ||||
| from tests import fixtures_path | ||||
| import unittest | ||||
| import tests | ||||
| import vcr | ||||
|  | ||||
| from pyVim import connect | ||||
| from pyVmomi import vim | ||||
|  | ||||
| class VirtualMachineTests(unittest.TestCase): | ||||
|  | ||||
| class VirtualMachineTests(tests.VCRTestBase): | ||||
|  | ||||
|     @vcr.use_cassette('vm_nic_data.yaml', | ||||
|                       cassette_library_dir=fixtures_path, record_mode='never') | ||||
|                       cassette_library_dir=tests.fixtures_path, | ||||
|                       record_mode='never') | ||||
|     def test_vm_nic_data(self): | ||||
|         data = {'ESXi-5.5-16': [], | ||||
|                 'ESXi-5.5-17': [], | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 Shawn Hartsock
					Shawn Hartsock