Skip to content

Commit

Permalink
Add type hints to tests (#46)
Browse files Browse the repository at this point in the history
  • Loading branch information
DoctorJohn authored Jan 2, 2024
1 parent de1b76c commit 4666f5b
Show file tree
Hide file tree
Showing 8 changed files with 106 additions and 57 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ format:
lint:
poetry run ruff check aiogqlc tests
poetry run ruff format --check aiogqlc tests
poetry run mypy aiogqlc
poetry run mypy aiogqlc tests

.PHONY: test
test:
Expand Down
8 changes: 6 additions & 2 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
import asyncio

import pytest_asyncio

from tests.app import create_app
from tests.types import AiohttpClient


@pytest_asyncio.fixture
async def graphql_session(event_loop, aiohttp_client):
async def graphql_session(aiohttp_client: AiohttpClient):
app = create_app()
event_loop.set_debug(True)
loop = asyncio.get_event_loop()
loop.set_debug(True)
return await aiohttp_client(app)
9 changes: 7 additions & 2 deletions tests/test_client.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
import aiohttp

from aiogqlc import GraphQLClient
from tests.app import create_app
from tests.types import AiohttpClient


async def test_execute_extra_kwargs_are_passed_to_aiohttp(graphql_session):
async def test_execute_extra_kwargs_are_passed_to_aiohttp(
graphql_session: aiohttp.ClientSession,
):
query = """
query {
authorizationHeader
Expand All @@ -15,7 +20,7 @@ async def test_execute_extra_kwargs_are_passed_to_aiohttp(graphql_session):
assert await response.json() == {"data": {"authorizationHeader": "Bearer Token123"}}


async def test_default_headers_can_be_overridden(aiohttp_client):
async def test_default_headers_can_be_overridden(aiohttp_client: AiohttpClient):
app = create_app()
graphql_session = await aiohttp_client(
app, headers={"Authorization": "Bearer DefaultToken"}
Expand Down
8 changes: 6 additions & 2 deletions tests/test_mutations.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import aiohttp

from aiogqlc import GraphQLClient


async def test_mutation_with_flat_response(graphql_session):
async def test_mutation_with_flat_response(graphql_session: aiohttp.ClientSession):
query = """
mutation {
fakeUser(id: 7, name: "John Smith") {
Expand All @@ -19,7 +21,9 @@ async def test_mutation_with_flat_response(graphql_session):
}


async def test_mutation_with_nested_fields_in_response(graphql_session):
async def test_mutation_with_nested_fields_in_response(
graphql_session: aiohttp.ClientSession,
):
query = """
mutation {
fakeTodo(id: 7, title: "TODO", priority: 10, creator: 1) {
Expand Down
12 changes: 7 additions & 5 deletions tests/test_queries.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import aiohttp

from aiogqlc import GraphQLClient


async def test_query_flat_list(graphql_session):
async def test_query_flat_list(graphql_session: aiohttp.ClientSession):
query = """
query {
todos {
Expand All @@ -26,7 +28,7 @@ async def test_query_flat_list(graphql_session):
}


async def test_query_list_with_nested_fields(graphql_session):
async def test_query_list_with_nested_fields(graphql_session: aiohttp.ClientSession):
query = """
query {
todos {
Expand All @@ -53,7 +55,7 @@ async def test_query_list_with_nested_fields(graphql_session):
}


async def test_query_flat_object(graphql_session):
async def test_query_flat_object(graphql_session: aiohttp.ClientSession):
query = """
query {
todo(id: 1) {
Expand All @@ -72,7 +74,7 @@ async def test_query_flat_object(graphql_session):
}


async def test_query_object_with_nested_fields(graphql_session):
async def test_query_object_with_nested_fields(graphql_session: aiohttp.ClientSession):
query = """
query {
todo(id: 1) {
Expand All @@ -93,7 +95,7 @@ async def test_query_object_with_nested_fields(graphql_session):
}


async def test_selecting_an_operation(graphql_session):
async def test_selecting_an_operation(graphql_session: aiohttp.ClientSession):
query = """
query Operation1 {
todos {
Expand Down
Loading

0 comments on commit 4666f5b

Please sign in to comment.