Skip to content

Commit 6abd1c5

Browse files
authored
Fix build (#52)
2 parents 3653bb5 + 3679b0a commit 6abd1c5

File tree

8 files changed

+351
-23
lines changed

8 files changed

+351
-23
lines changed

.travis.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ language: python
22
sudo: false
33
python:
44
- 2.7
5-
- 3.3
6-
- 3.4
75
- 3.5
6+
- 3.6
7+
- 3.7
88
cache: pip
99
install:
1010
- pip install -r ./dev_requirements.txt

dev_requirements.txt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
pytest
1+
pytest<4
22
pytest-cov
33
coveralls
44
flake8
5-
mock
5+
mock
6+
vcrpy==2.1.1

gql/client.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
log = logging.getLogger(__name__)
99

10+
1011
class RetryError(Exception):
1112
"""Custom exception thrown when retry logic fails"""
1213
def __init__(self, retries_count, last_exception):
@@ -67,7 +68,7 @@ def _get_result(self, document, *args, **kwargs):
6768
except Exception as e:
6869
last_exception = e
6970
log.warn("Request failed with exception %s. Retrying for the %s time...",
70-
e, retries_count + 1, exc_info=True)
71+
e, retries_count + 1, exc_info=True)
7172
finally:
7273
retries_count += 1
7374

gql/utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,4 @@ def to_snake_case(name):
1818

1919

2020
def to_const(string):
21-
return re.sub('[\W|^]+', '_', string).upper()
21+
return re.sub(r'[\W|^]+', '_', string).upper()

setup.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import sys
21
from setuptools import setup, find_packages
32

43
setup(
@@ -26,7 +25,7 @@
2625
packages=find_packages(include=["gql*"]),
2726
install_requires=[
2827
'six>=1.10.0',
29-
'graphql-core>=0.5.0',
28+
'graphql-core>=0.5.0,<2',
3029
'promise>=0.4.0'
3130
],
3231
tests_require=['pytest>=2.7.2', 'mock'],

tests/fixtures/vcr_cassettes/client.yaml

Lines changed: 274 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
interactions:
2+
- request:
3+
body: query=%7B%0A++myFavoriteFilm%3A+film%28id%3A+%22RmlsbToz%22%29+%7B%0A++++id%0A++++title%0A++++episodeId%0A++++characters%28first%3A+5%29+%7B%0A++++++edges+%7B%0A++++++++node+%7B%0A++++++++++name%0A++++++++%7D%0A++++++%7D%0A++++%7D%0A++%7D%0A%7D%0A
4+
headers:
5+
Accept:
6+
- '*/*'
7+
Accept-Encoding:
8+
- gzip, deflate
9+
Connection:
10+
- keep-alive
11+
Content-Length:
12+
- '247'
13+
Content-Type:
14+
- application/x-www-form-urlencoded
15+
Cookie:
16+
- csrftoken=hRIez34v4hg2Wbl8XhrbshvDIB3HmLR2L9WNTJ3SdrIQHxAKtoukxiuwQlwRJewz
17+
User-Agent:
18+
- python-requests/2.22.0
19+
x-csrftoken:
20+
- hRIez34v4hg2Wbl8XhrbshvDIB3HmLR2L9WNTJ3SdrIQHxAKtoukxiuwQlwRJewz
21+
method: POST
22+
uri: http://127.0.0.1:8000/graphql
23+
response:
24+
body:
25+
string: '{"data":{"myFavoriteFilm":{"id":"RmlsbToz","title":"Return of the Jedi","episodeId":6,"characters":{"edges":[{"node":{"name":"Luke
26+
Skywalker"}},{"node":{"name":"C-3PO"}},{"node":{"name":"R2-D2"}},{"node":{"name":"Darth
27+
Vader"}},{"node":{"name":"Leia Organa"}}]}}}}'
28+
headers:
29+
Content-Length:
30+
- '264'
31+
Content-Type:
32+
- application/json
33+
Date:
34+
- Tue, 03 Dec 2019 08:23:58 GMT
35+
Server:
36+
- WSGIServer/0.1 Python/2.7.16
37+
Set-Cookie:
38+
- csrftoken=hRIez34v4hg2Wbl8XhrbshvDIB3HmLR2L9WNTJ3SdrIQHxAKtoukxiuwQlwRJewz;
39+
expires=Tue, 01-Dec-2020 08:23:58 GMT; Max-Age=31449600; Path=/
40+
Vary:
41+
- Cookie
42+
X-Frame-Options:
43+
- SAMEORIGIN
44+
status:
45+
code: 200
46+
message: OK
47+
version: 1

tests/test_transport.py

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,31 @@
11
import pytest
22
import requests
3+
import vcr
34

45
from gql import Client, gql
56
from gql.transport.requests import RequestsHTTPTransport
67

8+
# https://github.com/graphql-python/swapi-graphene
9+
URL = 'http://127.0.0.1:8000/graphql'
10+
711

812
@pytest.fixture
913
def client():
10-
request = requests.get('http://swapi.graphene-python.org/graphql',
11-
headers={
12-
'Host': 'swapi.graphene-python.org',
13-
'Accept': 'text/html',
14-
})
15-
request.raise_for_status()
16-
csrf = request.cookies['csrftoken']
14+
with vcr.use_cassette('tests/fixtures/vcr_cassettes/client.yaml'):
15+
request = requests.get(URL,
16+
headers={
17+
'Host': 'swapi.graphene-python.org',
18+
'Accept': 'text/html',
19+
})
20+
request.raise_for_status()
21+
csrf = request.cookies['csrftoken']
1722

18-
return Client(
19-
transport=RequestsHTTPTransport(url='http://swapi.graphene-python.org/graphql',
20-
cookies={"csrftoken": csrf},
21-
headers={'x-csrftoken': csrf}),
22-
fetch_schema_from_transport=True
23-
)
23+
return Client(
24+
transport=RequestsHTTPTransport(url=URL,
25+
cookies={"csrftoken": csrf},
26+
headers={'x-csrftoken': csrf}),
27+
fetch_schema_from_transport=True
28+
)
2429

2530

2631
def test_hero_name_query(client):
@@ -76,5 +81,6 @@ def test_hero_name_query(client):
7681
}
7782
}
7883
}
79-
result = client.execute(query)
80-
assert result == expected
84+
with vcr.use_cassette('tests/fixtures/vcr_cassettes/execute.yaml'):
85+
result = client.execute(query)
86+
assert result == expected

0 commit comments

Comments
 (0)