-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
location: add tests for graphql queries
- Loading branch information
Showing
4 changed files
with
189 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,26 @@ | ||
from graphene.test import Client as GraphQLClient | ||
|
||
import pytest | ||
|
||
from rest_framework import test | ||
|
||
from graphy.schema import schema | ||
|
||
|
||
@pytest.fixture | ||
def drf_client(db): | ||
return test.APIClient() | ||
|
||
|
||
@pytest.fixture | ||
def gql_client(): | ||
class Request: | ||
def __init__(self): | ||
self.META = {} | ||
|
||
class Context: | ||
def __init__(self): | ||
self._request = Request() | ||
self.META = {} | ||
|
||
return GraphQLClient(schema, context=Context()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
def test_address(gql_client, address): | ||
query = """ | ||
query($id: String!) { | ||
address(id: $id) { | ||
id | ||
} | ||
} | ||
""" | ||
params = {'id': str(address.id)} | ||
|
||
result = gql_client.execute(query, variables=params) | ||
|
||
assert result['data']['address'] == {'id': str(address.id)} | ||
|
||
|
||
def test_addresses(gql_client, address): | ||
query = """ | ||
query { | ||
addresses { | ||
id | ||
} | ||
} | ||
""" | ||
params = {'id': str(address.id)} | ||
|
||
result = gql_client.execute(query, variables=params) | ||
|
||
assert result['data']['addresses'] == [{'id': str(address.id)}] | ||
|
||
|
||
def test_county(gql_client, county): | ||
query = """ | ||
query($id: String!) { | ||
county(id: $id) { | ||
id | ||
} | ||
} | ||
""" | ||
|
||
params = {'id': str(county.id)} | ||
result = gql_client.execute(query, variables=params) | ||
assert result['data']['county'] == {'id': str(county.id)} | ||
|
||
|
||
def test_counties(gql_client, county): | ||
query = """ | ||
query { | ||
counties { | ||
id | ||
} | ||
} | ||
""" | ||
|
||
params = {'id': str(county.id)} | ||
result = gql_client.execute(query, variables=params) | ||
assert result['data']['counties'] == [{'id': str(county.id)}] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
def test_address_type(gql_client, address): | ||
query = """ | ||
query($id: String!) { | ||
address(id: $id) { | ||
id | ||
country | ||
streetAddress | ||
latitude | ||
longitude | ||
zipCode { | ||
id | ||
} | ||
} | ||
} | ||
""" | ||
params = {'id': str(address.id)} | ||
|
||
result = gql_client.execute(query, variables=params) | ||
|
||
address_dict = result['data']['address'] | ||
assert address_dict == { | ||
'id': str(address.id), | ||
'streetAddress': address.street_address, | ||
'latitude': address.latitude, | ||
'longitude': address.longitude, | ||
'country': str(address.country), | ||
'zipCode': {'id': str(address.zip_code.id)}, | ||
} | ||
|
||
|
||
def test_county_type(gql_client, county): | ||
query = """ | ||
query($id: String!) { | ||
county(id: $id) { | ||
id | ||
name | ||
code | ||
country | ||
} | ||
} | ||
""" | ||
|
||
params = {'id': str(county.id)} | ||
result = gql_client.execute(query, variables=params) | ||
county_dict = result['data']['county'] | ||
assert county_dict == { | ||
'id': str(county.id), | ||
'name': county.name, | ||
'code': county.code, | ||
'country': 'NO', | ||
} | ||
|
||
|
||
def test_municipality_type(gql_client, address): | ||
query = """ | ||
query($id: String!) { | ||
address(id: $id) { | ||
zipCode { | ||
municipality { | ||
id | ||
name | ||
county { | ||
id | ||
} | ||
} | ||
} | ||
} | ||
} | ||
""" | ||
params = {'id': str(address.id)} | ||
|
||
result = gql_client.execute(query, variables=params) | ||
|
||
municipality = address.zip_code.municipality | ||
municipality_dict = result['data']['address']['zipCode']['municipality'] | ||
assert municipality_dict == { | ||
'id': str(municipality.id), | ||
'name': municipality.name, | ||
'county': {'id': str(municipality.county.id)}, | ||
} | ||
|
||
|
||
def test_zipcode_type(gql_client, address): | ||
query = """ | ||
query($id: String!) { | ||
address(id: $id) { | ||
zipCode { | ||
id | ||
code | ||
name | ||
municipality { | ||
id | ||
} | ||
county { | ||
id | ||
} | ||
} | ||
} | ||
} | ||
""" | ||
params = {'id': str(address.id)} | ||
|
||
result = gql_client.execute(query, variables=params) | ||
|
||
zip_code_dict = result['data']['address']['zipCode'] | ||
assert zip_code_dict == { | ||
'id': str(address.zip_code.id), | ||
'name': address.zip_code.name, | ||
'code': address.zip_code.code, | ||
'municipality': {'id': str(address.zip_code.municipality.id)}, | ||
'county': {'id': str(address.zip_code.county.id)}, | ||
} |