Skip to content

Fix build #52

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Dec 5, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ language: python
sudo: false
python:
- 2.7
- 3.3
- 3.4
- 3.5
- 3.6
- 3.7
cache: pip
install:
- pip install -r ./dev_requirements.txt
Expand Down
5 changes: 3 additions & 2 deletions dev_requirements.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
pytest
pytest<4
pytest-cov
coveralls
flake8
mock
mock
vcrpy==2.1.1
3 changes: 2 additions & 1 deletion gql/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

log = logging.getLogger(__name__)


class RetryError(Exception):
"""Custom exception thrown when retry logic fails"""
def __init__(self, retries_count, last_exception):
Expand Down Expand Up @@ -67,7 +68,7 @@ def _get_result(self, document, *args, **kwargs):
except Exception as e:
last_exception = e
log.warn("Request failed with exception %s. Retrying for the %s time...",
e, retries_count + 1, exc_info=True)
e, retries_count + 1, exc_info=True)
finally:
retries_count += 1

Expand Down
2 changes: 1 addition & 1 deletion gql/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,4 @@ def to_snake_case(name):


def to_const(string):
return re.sub('[\W|^]+', '_', string).upper()
return re.sub(r'[\W|^]+', '_', string).upper()
3 changes: 1 addition & 2 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import sys
from setuptools import setup, find_packages

setup(
Expand Down Expand Up @@ -26,7 +25,7 @@
packages=find_packages(include=["gql*"]),
install_requires=[
'six>=1.10.0',
'graphql-core>=0.5.0',
'graphql-core>=0.5.0,<2',
'promise>=0.4.0'
],
tests_require=['pytest>=2.7.2', 'mock'],
Expand Down
274 changes: 274 additions & 0 deletions tests/fixtures/vcr_cassettes/client.yaml

Large diffs are not rendered by default.

47 changes: 47 additions & 0 deletions tests/fixtures/vcr_cassettes/execute.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
interactions:
- request:
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
headers:
Accept:
- '*/*'
Accept-Encoding:
- gzip, deflate
Connection:
- keep-alive
Content-Length:
- '247'
Content-Type:
- application/x-www-form-urlencoded
Cookie:
- csrftoken=hRIez34v4hg2Wbl8XhrbshvDIB3HmLR2L9WNTJ3SdrIQHxAKtoukxiuwQlwRJewz
User-Agent:
- python-requests/2.22.0
x-csrftoken:
- hRIez34v4hg2Wbl8XhrbshvDIB3HmLR2L9WNTJ3SdrIQHxAKtoukxiuwQlwRJewz
method: POST
uri: http://127.0.0.1:8000/graphql
response:
body:
string: '{"data":{"myFavoriteFilm":{"id":"RmlsbToz","title":"Return of the Jedi","episodeId":6,"characters":{"edges":[{"node":{"name":"Luke
Skywalker"}},{"node":{"name":"C-3PO"}},{"node":{"name":"R2-D2"}},{"node":{"name":"Darth
Vader"}},{"node":{"name":"Leia Organa"}}]}}}}'
headers:
Content-Length:
- '264'
Content-Type:
- application/json
Date:
- Tue, 03 Dec 2019 08:23:58 GMT
Server:
- WSGIServer/0.1 Python/2.7.16
Set-Cookie:
- csrftoken=hRIez34v4hg2Wbl8XhrbshvDIB3HmLR2L9WNTJ3SdrIQHxAKtoukxiuwQlwRJewz;
expires=Tue, 01-Dec-2020 08:23:58 GMT; Max-Age=31449600; Path=/
Vary:
- Cookie
X-Frame-Options:
- SAMEORIGIN
status:
code: 200
message: OK
version: 1
36 changes: 21 additions & 15 deletions tests/test_transport.py
Original file line number Diff line number Diff line change
@@ -1,26 +1,31 @@
import pytest
import requests
import vcr

from gql import Client, gql
from gql.transport.requests import RequestsHTTPTransport

# https://github.com/graphql-python/swapi-graphene
URL = 'http://127.0.0.1:8000/graphql'


@pytest.fixture
def client():
request = requests.get('http://swapi.graphene-python.org/graphql',
headers={
'Host': 'swapi.graphene-python.org',
'Accept': 'text/html',
})
request.raise_for_status()
csrf = request.cookies['csrftoken']
with vcr.use_cassette('tests/fixtures/vcr_cassettes/client.yaml'):
request = requests.get(URL,
headers={
'Host': 'swapi.graphene-python.org',
'Accept': 'text/html',
})
request.raise_for_status()
csrf = request.cookies['csrftoken']

return Client(
transport=RequestsHTTPTransport(url='http://swapi.graphene-python.org/graphql',
cookies={"csrftoken": csrf},
headers={'x-csrftoken': csrf}),
fetch_schema_from_transport=True
)
return Client(
transport=RequestsHTTPTransport(url=URL,
cookies={"csrftoken": csrf},
headers={'x-csrftoken': csrf}),
fetch_schema_from_transport=True
)


def test_hero_name_query(client):
Expand Down Expand Up @@ -76,5 +81,6 @@ def test_hero_name_query(client):
}
}
}
result = client.execute(query)
assert result == expected
with vcr.use_cassette('tests/fixtures/vcr_cassettes/execute.yaml'):
result = client.execute(query)
assert result == expected