import pytest
boto = pytest.importorskip("boto")
+import boto
+import boto.iam
from boto.s3.connection import S3Connection
from boto.s3.key import Key
+from ConfigParser import DuplicateSectionError
import vcr
def test_boto_stubs(tmpdir):
# Perform the imports within the patched context so that
# CertValidatingHTTPSConnection refers to the patched version.
from boto.https_connection import CertValidatingHTTPSConnection
+ from vcr.stubs.boto_stubs import VCRCertValidatingHTTPSConnection
+ # Prove that the class was patched by the stub and that we can instantiate it.
+ assert CertValidatingHTTPSConnection is VCRCertValidatingHTTPSConnection
CertValidatingHTTPSConnection('hostname.does.not.matter')
def test_boto_without_vcr():
k = Key(s3_bucket)
k.key = 'test.txt'
k.set_contents_from_string('hello world i am a string')
+
+def test_boto_iam(tmpdir):
+ try:
+ boto.config.add_section('Boto')
+ except DuplicateSectionError:
+ pass
+ # Ensure that boto uses HTTPS
+ boto.config.set('Boto', 'is_secure', 'true')
+ # Ensure that boto uses CertValidatingHTTPSConnection
+ boto.config.set('Boto', 'https_validate_certificates', 'true')
+
+ with vcr.use_cassette(str(tmpdir.join('boto-iam.yml'))) as cass:
+ iam_conn = boto.iam.connect_to_region('universal')
+ iam_conn.get_all_users()
+
+ with vcr.use_cassette(str(tmpdir.join('boto-iam.yml'))) as cass:
+ iam_conn = boto.iam.connect_to_region('universal')
+ iam_conn.get_all_users()
except ImportError: # pragma: no cover
pass
+try:
+ # Try to save the original types for boto
+ import boto.https_connection
+ _CertValidatingHTTPSConnection = boto.https_connection.CertValidatingHTTPSConnection
+except ImportError: # pragma: no cover
+ pass
+
def install(cassette):
"""
except ImportError: # pragma: no cover
pass
+ # patch boto
+ try:
+ import boto.https_connection as cpool
+ from .stubs.boto_stubs import VCRCertValidatingHTTPSConnection
+ cpool.CertValidatingHTTPSConnection = VCRCertValidatingHTTPSConnection
+ cpool.CertValidatingHTTPSConnection.cassette = cassette
+ except ImportError: # pragma: no cover
+ pass
+
def reset():
'''Undo all the patching'''
cpool.SCHEME_TO_CONNECTION = _SCHEME_TO_CONNECTION
except ImportError: # pragma: no cover
pass
+
+ try:
+ import boto.https_connection as cpool
+ cpool.CertValidatingHTTPSConnection = _CertValidatingHTTPSConnection
+ except ImportError: # pragma: no cover
+ pass