]> khamidou — GitHub mirrors - vcrpy.git/commitdiff
boto3 integration tests
authorbogdan barna <foo.barna@gmail.com>
Wed, 22 Jun 2016 10:51:13 +0000 (13:51 +0300)
committerDavid de Sousa <davidesousa@gmail.com>
Sun, 26 Jun 2016 23:39:49 +0000 (01:39 +0200)
tests/integration/test_boto.py
tests/integration/test_boto3.py [new file with mode: 0644]
tox.ini
vcr/stubs/boto3_stubs.py

index 6a396cc130a0854b182b6fefec5070e6a12f3891..404f045319339e15e1431b8286f3d716715dab96 100644 (file)
@@ -5,8 +5,12 @@ import boto  # NOQA
 import boto.iam  # NOQA
 from boto.s3.connection import S3Connection  # NOQA
 from boto.s3.key import Key  # NOQA
-from ConfigParser import DuplicateSectionError  # NOQA
 import vcr  # NOQA
+try: # NOQA
+    from ConfigParser import DuplicateSectionError # NOQA
+except ImportError: # NOQA
+    # python3
+    from configparser import DuplicateSectionError # NOQA
 
 
 def test_boto_stubs(tmpdir):
diff --git a/tests/integration/test_boto3.py b/tests/integration/test_boto3.py
new file mode 100644 (file)
index 0000000..007309a
--- /dev/null
@@ -0,0 +1,68 @@
+import pytest
+boto3 = pytest.importorskip("boto3")
+
+import boto3
+import vcr
+
+bucket = 'boto3-demo-1337'              # a bucket you can access
+key = 'test/my_test.txt'                # key with r+w access
+content = 'hello world i am a string'   # content to put in the test file
+
+
+def test_boto_stubs(tmpdir):
+    with vcr.use_cassette(str(tmpdir.join('boto3-stubs.yml'))):
+        # Perform the imports within the patched context so that
+        # HTTPConnection, VerifiedHTTPSConnection refers to the patched version.
+        from botocore.vendored.requests.packages.urllib3.connectionpool import \
+            HTTPConnection, VerifiedHTTPSConnection
+        from vcr.stubs.boto3_stubs import VCRRequestsHTTPConnection, VCRRequestsHTTPSConnection
+        # Prove that the class was patched by the stub and that we can instantiate it.
+        assert issubclass(HTTPConnection, VCRRequestsHTTPConnection)
+        assert issubclass(VerifiedHTTPSConnection, VCRRequestsHTTPSConnection)
+        HTTPConnection('hostname.does.not.matter')
+        VerifiedHTTPSConnection('hostname.does.not.matter')
+
+
+def test_boto3_without_vcr():
+    s3_resource = boto3.resource('s3')
+    b = s3_resource.Bucket(bucket)
+    b.put_object(Key=key, Body=content)
+
+    # retrieve content to check it
+    o = s3_resource.Object(bucket, key).get()
+
+    # decode for python3
+    assert content == o['Body'].read().decode('utf-8')
+
+
+def test_boto_medium_difficulty(tmpdir):
+    s3_resource = boto3.resource('s3')
+    b = s3_resource.Bucket(bucket)
+    with vcr.use_cassette(str(tmpdir.join('boto3-medium.yml'))):
+        b.put_object(Key=key, Body=content)
+        o = s3_resource.Object(bucket, key).get()
+        assert content == o['Body'].read().decode('utf-8')
+
+    with vcr.use_cassette(str(tmpdir.join('boto3-medium.yml'))) as cass:
+        b.put_object(Key=key, Body=content)
+        o = s3_resource.Object(bucket, key).get()
+        assert content == o['Body'].read().decode('utf-8')
+        assert cass.all_played
+
+
+def test_boto_hardcore_mode(tmpdir):
+    with vcr.use_cassette(str(tmpdir.join('boto3-hardcore.yml'))):
+        s3_resource = boto3.resource('s3')
+        b = s3_resource.Bucket(bucket)
+        b.put_object(Key=key, Body=content)
+        o = s3_resource.Object(bucket, key).get()
+        assert content == o['Body'].read().decode('utf-8')
+
+    with vcr.use_cassette(str(tmpdir.join('boto3-hardcore.yml'))) as cass:
+        s3_resource = boto3.resource('s3')
+        b = s3_resource.Bucket(bucket)
+        b.put_object(Key=key, Body=content)
+        o = s3_resource.Object(bucket, key).get()
+        assert content == o['Body'].read().decode('utf-8')
+        assert cass.all_played
+
diff --git a/tox.ini b/tox.ini
index 046a848e7739f7a20e8b814f4a3fade7c72de91c..77ce9b71a26ab00b03512964f8570ee197533f24 100644 (file)
--- a/tox.ini
+++ b/tox.ini
@@ -1,5 +1,5 @@
 [tox]
-envlist = {py26,py27,py33,py34,pypy,pypy3}-{flakes,requests27,requests26,requests25,requests24,requests23,requests22,requests1,httplib2,urllib317,urllib319,urllib3110,tornado3,tornado4,boto}
+envlist = {py26,py27,py33,py34,pypy,pypy3}-{flakes,requests27,requests26,requests25,requests24,requests23,requests22,requests1,httplib2,urllib317,urllib319,urllib3110,tornado3,tornado4,boto,boto3}
 
 [testenv:flakes]
 skipsdist = True
@@ -37,6 +37,7 @@ deps =
     {py26,py27,py33,py34}-tornado3: pycurl
     {py26,py27,py33,py34}-tornado4: pycurl
     boto: boto
+    boto3: boto3
 
 [flake8]
 max_line_length = 110
index 43476be3252aa3847dcf11670047577be7b6d426..93a7bdb394bde3bc93bdeae52a5e0db2e7892013 100644 (file)
@@ -6,8 +6,10 @@ from ..stubs import VCRHTTPConnection, VCRHTTPSConnection
 # urllib3 defines its own HTTPConnection classes, which boto3 goes ahead and assumes
 # you're using.  It includes some polyfills for newer features missing in older pythons.
 
+
 class VCRRequestsHTTPConnection(VCRHTTPConnection, HTTPConnection):
     _baseclass = HTTPConnection
 
+
 class VCRRequestsHTTPSConnection(VCRHTTPSConnection, VerifiedHTTPSConnection):
     _baseclass = VerifiedHTTPSConnection