From f7ee398dcfc830f735cb95d0963879d0eabbe37c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafa=C5=82=20Pito=C5=84?= Date: Thu, 18 Jan 2024 16:41:12 +0100 Subject: [PATCH] More tests --- .../graphql_schema_generators/schema.py | 3 +- tests/test_settings.py | 55 +++++++++++++++++++ 2 files changed, 56 insertions(+), 2 deletions(-) diff --git a/ariadne_codegen/graphql_schema_generators/schema.py b/ariadne_codegen/graphql_schema_generators/schema.py index bc5808c1..9de87871 100644 --- a/ariadne_codegen/graphql_schema_generators/schema.py +++ b/ariadne_codegen/graphql_schema_generators/schema.py @@ -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, diff --git a/tests/test_settings.py b/tests/test_settings.py index 3a629287..decebdd9 100644 --- a/tests/test_settings.py +++ b/tests/test_settings.py @@ -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() @@ -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(