From 679f3a036960899f1d515cccd15ccf8760e1a86e Mon Sep 17 00:00:00 2001 From: Justin Riley Date: Wed, 3 Aug 2016 00:35:58 -0400 Subject: [PATCH] use vcrpy for oneclient tests Will commit cassettes later once the tests have been executed on a test VM and the test authorization token has been stripped. --- onedns/tests/__init__.py | 11 +++++++++++ onedns/tests/conftest.py | 5 ++++- onedns/tests/test_oneclient.py | 4 ++++ setup.py | 1 + 4 files changed, 20 insertions(+), 1 deletion(-) diff --git a/onedns/tests/__init__.py b/onedns/tests/__init__.py index e69de29..10b91bf 100644 --- a/onedns/tests/__init__.py +++ b/onedns/tests/__init__.py @@ -0,0 +1,11 @@ +import os + +from vcr import VCR + +vcr = VCR( + serializer='yaml', + cassette_library_dir=os.path.join( + os.path.dirname(os.path.realpath(__file__)), 'fixtures/oneclient' + ), + record_mode='once', +) diff --git a/onedns/tests/conftest.py b/onedns/tests/conftest.py index 3ed5afb..b8693c4 100644 --- a/onedns/tests/conftest.py +++ b/onedns/tests/conftest.py @@ -17,6 +17,9 @@ def dns(request): return dns -@pytest.fixture(scope="module") +@pytest.fixture(scope="function") def oneclient(request): + """ + NOTE: All fixtures must be function scope to work with VCRPY cassettes + """ return one.OneClient() diff --git a/onedns/tests/test_oneclient.py b/onedns/tests/test_oneclient.py index a1745a8..9499cb8 100644 --- a/onedns/tests/test_oneclient.py +++ b/onedns/tests/test_oneclient.py @@ -1,15 +1,19 @@ +from onedns.tests import vcr + import pytest import oca from oca import vm +@vcr.use_cassette() def test_get_vms(oneclient): vms = oneclient.vms() assert isinstance(vms, vm.VirtualMachinePool) assert len(vms) > 0 +@vcr.use_cassette() def test_get_vm_by_id(oneclient): with pytest.raises(TypeError): oneclient.get_vm_by_id('asdf') diff --git a/setup.py b/setup.py index d23f46a..6b38241 100644 --- a/setup.py +++ b/setup.py @@ -29,6 +29,7 @@ setup( tests_require=[ "pytest>=2.9.2", "testfixtures>=4.10.0", + "vcrpy>=1.9.0", ], entry_points=dict(console_scripts=['onedns = onedns.cli:main']), zip_safe=False