|
1 | 1 | import os
|
2 | 2 | import vcr
|
| 3 | +import zlib |
| 4 | +import base64 |
| 5 | +import pickle |
3 | 6 | import pytest
|
4 | 7 | import requests
|
5 | 8 | from scrapinghub import HubstorageClient
|
|
15 | 18 | TEST_AUTH = os.getenv('HS_AUTH', 'f' * 32)
|
16 | 19 | TEST_ENDPOINT = os.getenv('HS_ENDPOINT', 'http://storage.vm.scrapinghub.com')
|
17 | 20 |
|
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')))) |
19 | 31 |
|
20 | 32 |
|
21 | 33 | @pytest.fixture(scope='session')
|
@@ -49,14 +61,17 @@ def setup_session(hsclient):
|
49 | 61 |
|
50 | 62 | @pytest.fixture
|
51 | 63 | 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 |
53 | 68 |
|
54 | 69 |
|
55 | 70 | @pytest.fixture(autouse=True)
|
56 | 71 | def setup_test(hsclient, hsproject, hscollection, request, vcr_instance):
|
57 | 72 | # generates names like "test_module/test_function.yaml"
|
58 | 73 | # vcrpy creates the cassetes automatically under VCR_CASSETES_DIR
|
59 |
| - cassette_name = '{}/{}.yaml'.format( |
| 74 | + cassette_name = '{}/{}.gz'.format( |
60 | 75 | request.function.__module__.split('.')[-1],
|
61 | 76 | request.function.__name__
|
62 | 77 | )
|
|
0 commit comments