forked from sigmavirus24/github3.py
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconftest.py
More file actions
58 lines (39 loc) · 1.62 KB
/
Copy pathconftest.py
File metadata and controls
58 lines (39 loc) · 1.62 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
import base64
import betamax
import os
import pytest
from betamax_matchers import json_body
credentials = [os.environ.get('GH_USER', 'foo').encode(),
os.environ.get('GH_PASSWORD', 'bar').encode()]
betamax.Betamax.register_request_matcher(json_body.JSONBodyMatcher)
with betamax.Betamax.configure() as config:
config.cassette_library_dir = 'tests/cassettes'
record_mode = 'never' if os.environ.get('TRAVIS_GH3') else 'once'
config.default_cassette_options['record_mode'] = record_mode
config.define_cassette_placeholder(
'<AUTH_TOKEN>',
os.environ.get('GH_AUTH', 'x' * 20)
)
config.default_cassette_options['match_requests_on'].append('json-body')
config.define_cassette_placeholder(
'<BASIC_AUTH>',
base64.b64encode(b':'.join(credentials)).decode()
)
@pytest.fixture
def betamax_simple_body(request):
"""Return configuration to match cassette on uri, method and body."""
request.cls.betamax_simple_body = {
'match_requests_on': ['uri', 'method', 'body']
}
@pytest.fixture
def enterprise_url(request):
"""Configure class with enterprise url."""
request.cls.enterprise_url = 'https://enterprise.github3.com'
class IfNoneMatchMatcher(betamax.BaseMatcher):
name = 'if-none-match'
def match(self, request, recorded_request):
request_header = request.headers.get('If-None-Match')
recorded_header = recorded_request['headers'].get('If-None-Match')
matches = True if request_header == recorded_header else False
return matches
betamax.Betamax.register_request_matcher(IfNoneMatchMatcher)