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
14 changed files
with
501 additions
and
14 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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 |
---|---|---|
@@ -0,0 +1 @@ | ||
# Copyright 2018-present Kensho Technologies, LLC. |
40 changes: 40 additions & 0 deletions
40
graphql_compiler/tests/integration_tests/integration_backend_config.py
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,40 @@ | ||
# Copyright 2018-present Kensho Technologies, LLC. | ||
from collections import namedtuple | ||
|
||
from .. import test_backend | ||
|
||
|
||
DEFAULT_ROOT_PASSWORD = u'root' | ||
MSSQL_ROOT_PASSWORD = u'Root-secure1' # mssql has stricter root password restrictions | ||
|
||
SQL_BACKENDS = { | ||
test_backend.POSTGRES, | ||
test_backend.MYSQL, | ||
test_backend.MARIADB, | ||
test_backend.MSSQL, | ||
test_backend.SQLITE, | ||
} | ||
|
||
MATCH_BACKENDS = { | ||
test_backend.ORIENTDB, | ||
} | ||
|
||
SQL_BACKEND_TO_CONNECTION_STRING = { | ||
test_backend.POSTGRES: | ||
u'postgresql://postgres:{password}@localhost:5432'.format(password=DEFAULT_ROOT_PASSWORD), | ||
test_backend.MYSQL: | ||
u'mysql://root:{password}@127.0.0.1:3306'.format(password=DEFAULT_ROOT_PASSWORD), | ||
test_backend.MARIADB: | ||
u'mysql://root:{password}@127.0.0.1:3307'.format(password=DEFAULT_ROOT_PASSWORD), | ||
test_backend.MSSQL: | ||
u'mssql+pymssql://SA:{password}@localhost:1433'.format(password=MSSQL_ROOT_PASSWORD), | ||
test_backend.SQLITE: | ||
u'sqlite:///:memory:', | ||
} | ||
|
||
SqlTestBackend = namedtuple('SqlTestBackend', ( | ||
'connection_string', | ||
'engine', | ||
'connection', | ||
'transaction', | ||
)) |
56 changes: 56 additions & 0 deletions
56
graphql_compiler/tests/integration_tests/integration_test_helpers.py
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 @@ | ||
# Copyright 2018-present Kensho Technologies, LLC. | ||
from graphql import GraphQLString | ||
import six | ||
from sqlalchemy import text | ||
|
||
from ... import CompilationResult, OutputMetadata, graphql_to_match | ||
from ...compiler import SQL_LANGUAGE | ||
|
||
|
||
def sort_db_results(results): | ||
"""Deterministically sort DB results. | ||
Args: | ||
results: List[Dict], results from a DB. | ||
Returns: | ||
List[Dict], sorted DB results. | ||
""" | ||
sort_order = [] | ||
if len(results) > 0: | ||
sort_order = sorted(six.iterkeys(results[0])) | ||
|
||
def sort_key(result): | ||
"""Convert None/Not None to avoid comparisons of None to a non-None type.""" | ||
return tuple((result[col] is not None, result[col]) for col in sort_order) | ||
|
||
return sorted(results, key=sort_key) | ||
|
||
|
||
def compile_and_run_match_query(schema, graphql_query, parameters, graph_client): | ||
"""Compiles and runs a MATCH query against the supplied graph client.""" | ||
compilation_result = graphql_to_match(schema, graphql_query, parameters) | ||
query = compilation_result.query | ||
results = [row.oRecordData for row in graph_client.command(query)] | ||
return results | ||
|
||
|
||
def compile_and_run_sql_query(schema, graphql_query, parameters, sql_test_backend): | ||
"""Compiles and runs a SQL query against the supplied SQL backend.""" | ||
# TODO: un-mock the SQL compilation once the SQL backend can run queries. | ||
def mock_sql_compilation(schema, graphql_query, parameters, compiler_metadata): | ||
"""Mock out SQL backend compilation for unimplemented SQL backend.""" | ||
mock_compilation_result = CompilationResult( | ||
query=text('SELECT name AS animal_name FROM animal'), | ||
language=SQL_LANGUAGE, | ||
input_metadata={}, | ||
output_metadata={'animal_name': OutputMetadata(GraphQLString, False)} | ||
) | ||
return mock_compilation_result | ||
|
||
compilation_result = mock_sql_compilation(schema, graphql_query, parameters, None) | ||
query = compilation_result.query | ||
results = [] | ||
for result in sql_test_backend.connection.execute(query): | ||
results.append(dict(result)) | ||
return results |
Oops, something went wrong.