Skip to content

Commit 6371fb3

Browse files
committed
Dumb try to reduce size of cassettes
1 parent 0602bba commit 6371fb3

File tree

1 file changed

+18
-3
lines changed

1 file changed

+18
-3
lines changed

tests/hubstorage/conftest.py

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
import os
22
import vcr
3+
import zlib
4+
import base64
5+
import pickle
36
import pytest
47
import requests
58
from scrapinghub import HubstorageClient
@@ -15,7 +18,16 @@
1518
TEST_AUTH = os.getenv('HS_AUTH', 'f' * 32)
1619
TEST_ENDPOINT = os.getenv('HS_ENDPOINT', 'http://storage.vm.scrapinghub.com')
1720

18-
VCR_CASSETES_DIR = 'tests/hubstorage/cassetes'
21+
VCR_CASSETES_DIR = 'tests/hubstorage/cassettes'
22+
23+
24+
class VCRGzipSerializer(object):
25+
26+
def serialize(self, cassette_dict):
27+
return base64.b64encode(zlib.compress(pickle.dumps(cassette_dict))).decode('utf8')
28+
29+
def deserialize(self, cassette_string):
30+
return pickle.loads(zlib.decompress(base64.b64decode(cassette_string.encode('utf8'))))
1931

2032

2133
@pytest.fixture(scope='session')
@@ -49,14 +61,17 @@ def setup_session(hsclient):
4961

5062
@pytest.fixture
5163
def vcr_instance(scope='session'):
52-
return vcr.VCR(cassette_library_dir=VCR_CASSETES_DIR, record_mode='once')
64+
test_vcr = vcr.VCR(cassette_library_dir=VCR_CASSETES_DIR, record_mode='once')
65+
test_vcr.register_serializer('gz', VCRGzipSerializer())
66+
test_vcr.serializer = 'gz'
67+
return test_vcr
5368

5469

5570
@pytest.fixture(autouse=True)
5671
def setup_test(hsclient, hsproject, hscollection, request, vcr_instance):
5772
# generates names like "test_module/test_function.yaml"
5873
# vcrpy creates the cassetes automatically under VCR_CASSETES_DIR
59-
cassette_name = '{}/{}.yaml'.format(
74+
cassette_name = '{}/{}.gz'.format(
6075
request.function.__module__.split('.')[-1],
6176
request.function.__name__
6277
)

0 commit comments

Comments
 (0)