-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #157 from simonsobs/dev
Update tests
- Loading branch information
Showing
9 changed files
with
61 additions
and
2 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 |
---|---|---|
@@ -0,0 +1,19 @@ | ||
from pathlib import Path | ||
|
||
from graphql import parse, print_ast | ||
|
||
|
||
def read_gql(path: Path | str) -> str: | ||
'''Load a GraphQL query from a file while checking its syntax.''' | ||
|
||
text = Path(path).read_text() | ||
parsed = parse(text) | ||
reformatted = print_ast(parsed) | ||
return reformatted | ||
|
||
|
||
pwd = Path(__file__).resolve().parent | ||
|
||
|
||
sub = pwd / 'queries' | ||
QUERY_HEADERS = read_gql(sub / 'Headers.gql') |
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,5 @@ | ||
query DevHeaders { | ||
dev { | ||
headers | ||
} | ||
} |
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,3 +1,6 @@ | ||
__all__ = ['Query'] | ||
|
||
from .query import Query | ||
|
||
Mutation = None | ||
Subscription = None |
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
Empty file.
Empty file.
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,14 @@ | ||
import pytest | ||
from strawberry import Schema | ||
|
||
from nextlinegraphql.plugins.dev.schema import Mutation, Query, Subscription | ||
|
||
|
||
@pytest.fixture(scope='session') | ||
def schema() -> Schema: | ||
'''GraphQL schema | ||
The scope is `session` because Hypothesis doesn't allow function-scoped | ||
fixtures. This is fine as the schema is stateless. | ||
''' | ||
return Schema(query=Query, mutation=Mutation, subscription=Subscription) |
Empty file.
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,18 @@ | ||
import json | ||
from unittest.mock import Mock | ||
|
||
from starlette.requests import Headers, Request | ||
|
||
from nextlinegraphql.plugins.dev.graphql import QUERY_HEADERS | ||
from tests.plugins.dev.schema.conftest import Schema | ||
|
||
|
||
async def test_schema(schema: Schema) -> None: | ||
request = Mock(spec=Request) | ||
request.headers = Headers({'foo': 'bar'}) | ||
context = {'request': request} | ||
result = await schema.execute(QUERY_HEADERS, context_value=context) | ||
assert (data := result.data) | ||
expected = {'dev': {'headers': json.dumps({'foo': 'bar'})}} | ||
assert data == expected | ||
|