-
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 #30 from simonsobs/dev
Add tests
- Loading branch information
Showing
8 changed files
with
112 additions
and
3 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,20 @@ | ||
from os import PathLike | ||
from pathlib import Path | ||
|
||
from graphql import parse, print_ast | ||
|
||
|
||
def read_gql(path: PathLike | 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_VERSION = read_gql(sub / 'Version.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 Version { | ||
alert { | ||
version | ||
} | ||
} |
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 nextline_alert.schema import Query | ||
|
||
|
||
@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) |
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,12 @@ | ||
from strawberry.types import ExecutionResult | ||
|
||
import nextline_alert | ||
from nextline_alert.graphql import QUERY_VERSION | ||
from tests.schema.conftest import Schema | ||
|
||
|
||
async def test_schema(schema: Schema) -> None: | ||
resp = await schema.execute(QUERY_VERSION) | ||
assert isinstance(resp, ExecutionResult) | ||
assert resp.data | ||
assert resp.data['alert']['version'] == nextline_alert.__version__ |
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,21 @@ | ||
import asyncio | ||
from collections.abc import AsyncIterator | ||
|
||
import pytest | ||
|
||
from nextline_alert.graphql import QUERY_VERSION | ||
from nextlinegraphql import create_app | ||
from nextlinegraphql.plugins.graphql.test import TestClient, gql_request | ||
|
||
|
||
@pytest.fixture | ||
async def client() -> AsyncIterator[TestClient]: | ||
app = create_app() # the plugin is loaded here | ||
async with TestClient(app) as y: | ||
await asyncio.sleep(0) | ||
yield y | ||
|
||
|
||
async def test_plugin(client: TestClient) -> None: | ||
data = await gql_request(client, QUERY_VERSION) | ||
assert data |