|
1 | 1 | import os |
2 | | -import zlib |
3 | | -import base64 |
4 | | -import pickle |
5 | 2 |
|
6 | 3 | import vcr |
7 | 4 | import pytest |
|
12 | 9 | from scrapinghub.hubstorage.serialization import MSGPACK_AVAILABLE |
13 | 10 |
|
14 | 11 | from ..conftest import request_accept_header_matcher |
15 | | - |
16 | | - |
17 | | -TEST_PROJECT_ID = "2222222" |
18 | | -TEST_SPIDER_NAME = 'hs-test-spider' |
19 | | -TEST_FRONTIER_SLOT = 'site.com' |
20 | | -TEST_BOTGROUP = 'python-hubstorage-test' |
21 | | -TEST_COLLECTION_NAME = "test_collection_123" |
22 | | -TEST_ADMIN_AUTH = os.getenv('AUTH', 'f' * 32) |
23 | | -TEST_USER_AUTH = os.getenv('USER_AUTH', 'e' * 32) |
24 | | -TEST_DASH_ENDPOINT = os.getenv('DASH_ENDPOINT', 'http://33.33.33.51:8080/api/') |
25 | | -TEST_HS_ENDPOINT = os.getenv('HS_ENDPOINT', |
26 | | - 'http://storage.vm.scrapinghub.com') |
| 12 | +from ..conftest import VCRGzipSerializer |
| 13 | +from ..conftest import ( |
| 14 | + TEST_SPIDER_NAME, |
| 15 | + TEST_FRONTIER_SLOT, |
| 16 | + TEST_COLLECTION_NAME, |
| 17 | + TEST_ENDPOINT, |
| 18 | + TEST_PROJECT_ID, |
| 19 | + TEST_ADMIN_AUTH, |
| 20 | + TEST_DASH_ENDPOINT, |
| 21 | +) |
27 | 22 |
|
28 | 23 | # use some fixed timestamp to represent current time |
29 | 24 | TEST_TS = 1476803148638 |
30 | 25 |
|
31 | 26 | # vcrpy creates the cassetes automatically under VCR_CASSETES_DIR |
32 | 27 | VCR_CASSETES_DIR = 'tests/client/cassetes' |
33 | 28 |
|
34 | | - |
35 | | -class VCRGzipSerializer(object): |
36 | | - """Custom ZIP serializer for VCR.py.""" |
37 | | - |
38 | | - def serialize(self, cassette_dict): |
39 | | - # receives a dict, must return a string |
40 | | - # there can be binary data inside some of the requests, |
41 | | - # so it's impossible to use json for serialization to string |
42 | | - compressed = zlib.compress(pickle.dumps(cassette_dict, protocol=2)) |
43 | | - return base64.b64encode(compressed).decode('utf8') |
44 | | - |
45 | | - def deserialize(self, cassette_string): |
46 | | - # receives a string, must return a dict |
47 | | - decoded = base64.b64decode(cassette_string.encode('utf8')) |
48 | | - return pickle.loads(zlib.decompress(decoded)) |
49 | | - |
50 | | - |
51 | 29 | my_vcr = vcr.VCR(cassette_library_dir=VCR_CASSETES_DIR, record_mode='once') |
52 | 30 | my_vcr.register_serializer('gz', VCRGzipSerializer()) |
53 | 31 | my_vcr.register_matcher('accept_header', request_accept_header_matcher) |
@@ -79,7 +57,7 @@ def is_using_real_services(request): |
79 | 57 | @pytest.fixture(scope='session') |
80 | 58 | def client(): |
81 | 59 | return ScrapinghubClient(auth=TEST_ADMIN_AUTH, |
82 | | - endpoint=TEST_HS_ENDPOINT, |
| 60 | + endpoint=TEST_ENDPOINT, |
83 | 61 | dash_endpoint=TEST_DASH_ENDPOINT) |
84 | 62 |
|
85 | 63 |
|
|
0 commit comments