-
Notifications
You must be signed in to change notification settings - Fork 183
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
1 parent
27e21e4
commit 37bcf6a
Showing
5 changed files
with
97 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import pytest | ||
from .. import get_default_backend, set_default_backend, GraphQLCoreBackend | ||
|
||
|
||
def test_get_default_backend_returns_core_by_default(): | ||
backend = get_default_backend() | ||
assert isinstance(backend, GraphQLCoreBackend) | ||
|
||
|
||
def test_set_default_backend(): | ||
default_backend = get_default_backend() | ||
new_backend = GraphQLCoreBackend() | ||
assert new_backend != default_backend | ||
set_default_backend(new_backend) | ||
assert get_default_backend() == new_backend | ||
|
||
|
||
def test_set_default_backend_fails_if_invalid_backend(): | ||
default_backend = get_default_backend() | ||
with pytest.raises(Exception) as exc_info: | ||
set_default_backend(object()) | ||
assert str(exc_info.value) == 'backend must be an instance of GraphQLBackend.' | ||
assert get_default_backend() == default_backend |
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 @@ | ||
from ...language.base import parse | ||
from ...utils.ast_to_code import ast_to_code | ||
from ..compiled import GraphQLCompiledDocument | ||
from .schema import schema | ||
|
||
|
||
def test_compileddocument_from_module_dict(): | ||
document_string = '{ hello }' | ||
document_ast = parse(document_string) | ||
document = GraphQLCompiledDocument.from_module_dict(schema, { | ||
'document_string': document_string, | ||
'document_ast': document_ast, | ||
'execute': lambda *_: True | ||
}) | ||
assert document.operations_map == { | ||
None: 'query' | ||
} | ||
assert document.document_string == document_string | ||
assert document.document_ast == document_ast | ||
assert document.schema == schema | ||
assert document.execute() | ||
|
||
|
||
def test_compileddocument_from_code(): | ||
document_string = '{ hello }' | ||
document_ast = parse(document_string) | ||
code = ''' | ||
# -*- coding: utf-8 -*- | ||
from __future__ import unicode_literals | ||
from graphql.language import ast | ||
from graphql.language.parser import Loc | ||
from graphql.language.source import Source | ||
schema = None | ||
document_string = """{document_string}""" | ||
source = Source(document_string) | ||
def loc(start, end): | ||
return Loc(start, end, source) | ||
document_ast = {document_ast} | ||
def execute(*_): | ||
return True | ||
'''.format(document_string=document_string, document_ast=ast_to_code(document_ast)) | ||
document = GraphQLCompiledDocument.from_code(schema, code) | ||
assert document.operations_map == { | ||
None: 'query' | ||
} | ||
assert document.document_string == document_string | ||
assert document.document_ast == document_ast | ||
assert document.schema == schema | ||
assert document.execute() |
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