Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
438 additions
and
6 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
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
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 |
---|---|---|
|
@@ -13,5 +13,6 @@ pytest-mock | |
python-dateutil | ||
snapshottest | ||
requests | ||
werkzeug | ||
|
||
pip-tools |
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,55 @@ | ||
from unittest.mock import Mock | ||
|
||
from ariadne import ExtensionManager | ||
from ariadne.types import ExtensionSync as Extension | ||
|
||
|
||
context: dict = {} | ||
exception = ValueError() | ||
query = "{ test }" | ||
|
||
|
||
def test_request_started_event_is_called_by_extension_manager(): | ||
extension = Mock(spec=Extension) | ||
manager = ExtensionManager([Mock(return_value=extension)]) | ||
with manager.request(context): | ||
pass | ||
|
||
extension.request_started.assert_called_once_with(context) | ||
|
||
|
||
def test_request_finished_event_is_called_by_extension_manager(): | ||
extension = Mock(spec=Extension) | ||
manager = ExtensionManager([Mock(return_value=extension)]) | ||
with manager.request(context): | ||
pass | ||
|
||
extension.request_finished.assert_called_once_with(context) | ||
|
||
|
||
def test_request_finished_event_is_called_with_error(): | ||
extension = Mock(spec=Extension) | ||
manager = ExtensionManager([Mock(return_value=extension)]) | ||
try: | ||
with manager.request(context): | ||
raise exception | ||
except: # pylint: disable=bare-except | ||
pass | ||
|
||
extension.request_finished.assert_called_once_with(context, exception) | ||
|
||
|
||
def test_has_errors_event_is_called_with_errors_list(): | ||
extension = Mock(spec=Extension) | ||
manager = ExtensionManager([Mock(return_value=extension)]) | ||
manager.has_errors([exception]) | ||
extension.has_errors.assert_called_once_with([exception]) | ||
|
||
|
||
def test_extensions_are_formatted(): | ||
extensions = [ | ||
Mock(spec=Extension, format=Mock(return_value={"a": 1})), | ||
Mock(spec=Extension, format=Mock(return_value={"b": 2})), | ||
] | ||
manager = ExtensionManager([Mock(return_value=ext) for ext in extensions]) | ||
assert manager.format() == {"a": 1, "b": 2} |
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,54 @@ | ||
import pytest | ||
from freezegun import freeze_time | ||
from graphql import get_introspection_query | ||
|
||
from ariadne import graphql_sync as graphql | ||
from ariadne.contrib.tracing.apollotracing import ( | ||
ApolloTracingExtensionSync as ApolloTracingExtension, | ||
) | ||
|
||
|
||
@pytest.mark.asyncio | ||
async def test_apollotracing_extension_causes_no_errors_in_query_execution(schema): | ||
_, result = graphql( | ||
schema, {"query": "{ status }"}, extensions=[ApolloTracingExtension] | ||
) | ||
assert result["data"] == {"status": True} | ||
|
||
|
||
@pytest.fixture | ||
def freeze_microtime(mocker): | ||
mocker.patch( | ||
"ariadne.contrib.tracing.apollotracing.perf_counter_ns", return_value=2 | ||
) | ||
|
||
|
||
@freeze_time("2012-01-14 03:21:34") | ||
@pytest.mark.asyncio | ||
async def test_apollotracing_extension_adds_tracing_data_to_result_extensions( | ||
schema, freeze_microtime, snapshot # pylint: disable=unused-argument | ||
): | ||
_, result = graphql( | ||
schema, {"query": "{ status }"}, extensions=[ApolloTracingExtension] | ||
) | ||
snapshot.assert_match(result) | ||
|
||
|
||
@freeze_time("2012-01-14 03:21:34") | ||
@pytest.mark.asyncio | ||
async def test_apollotracing_extension_handles_exceptions_in_resolvers( | ||
schema, freeze_microtime, snapshot # pylint: disable=unused-argument | ||
): | ||
_, result = graphql( | ||
schema, {"query": "{ testError }"}, extensions=[ApolloTracingExtension] | ||
) | ||
snapshot.assert_match(result["data"]) | ||
|
||
|
||
@pytest.mark.asyncio | ||
async def test_apollotracing_extension_doesnt_break_introspection(schema): | ||
introspection_query = get_introspection_query(descriptions=True) | ||
_, result = graphql( | ||
schema, {"query": introspection_query}, extensions=[ApolloTracingExtension] | ||
) | ||
assert "errors" not in result |
Oops, something went wrong.