Skip to content

Commit

Permalink
More tests
Browse files Browse the repository at this point in the history
  • Loading branch information
rafalp committed Jan 18, 2024
1 parent 279da88 commit f7ee398
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 2 deletions.
3 changes: 1 addition & 2 deletions ariadne_codegen/graphql_schema_generators/schema.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import ast
from pathlib import Path

from graphql import GraphQLSchema
from graphql import GraphQLSchema, print_schema
from graphql.type.schema import TypeMap
from graphql import print_schema

from ..codegen import (
generate_ann_assign,
Expand Down
55 changes: 55 additions & 0 deletions tests/test_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,45 @@ def test_graphq_schema_settings_without_schema_path_with_remote_schema_url_is_va
assert not settings.schema_path


def test_graphql_schema_settings_with_target_file_path_with_py_extension_is_valid():
settings = GraphQLSchemaSettings(
remote_schema_url="http://testserver/graphq/",
target_file_path="schema_file.py",
)

assert settings.target_file_path == "schema_file.py"
assert settings.target_file_format == "py"


def test_graphql_schema_settings_with_target_file_path_with_graphql_extension_is_valid():
settings = GraphQLSchemaSettings(
remote_schema_url="http://testserver/graphq/",
target_file_path="schema_file.graphql",
)

assert settings.target_file_path == "schema_file.graphql"
assert settings.target_file_format == "graphql"


def test_graphql_schema_settings_with_target_file_path_with_graphql_extension_is_valid():
settings = GraphQLSchemaSettings(
remote_schema_url="http://testserver/graphq/",
target_file_path="schema_file.gql",
)

assert settings.target_file_path == "schema_file.gql"
assert settings.target_file_format == "gql"


def test_graphql_schema_settings_target_file_format_is_lowercased():
settings = GraphQLSchemaSettings(
remote_schema_url="http://testserver/graphq/",
target_file_path="schema_file.GQL",
)

assert settings.target_file_format == "gql"


def test_graphq_schema_settings_without_schema_path_or_remote_schema_url_is_not_valid():
with pytest.raises(InvalidConfiguration):
GraphQLSchemaSettings()
Expand All @@ -236,6 +275,22 @@ def test_graphql_schema_settings_raises_invalid_configuration_for_invalid_schema
GraphQLSchemaSettings(schema_path="not_exisitng.graphql")


def test_graphql_schema_settings_with_target_file_path_missing_extension_raises_exception():
with pytest.raises(InvalidConfiguration):
GraphQLSchemaSettings(
remote_schema_url="http://testserver/graphq/",
target_file_path="schema_file",
)


def test_graphql_schema_settings_with_target_file_path_invalid_extension_raises_exception():
with pytest.raises(InvalidConfiguration):
GraphQLSchemaSettings(
remote_schema_url="http://testserver/graphq/",
target_file_path="schema_file.invalid",
)


def test_graphql_schema_settings_with_invalid_schema_variable_name_raises_exception():
with pytest.raises(InvalidConfiguration):
GraphQLSchemaSettings(
Expand Down

0 comments on commit f7ee398

Please sign in to comment.