<s> from graphql . core . language . location import SourceLocation <EOL> from graphql . core . validation . rules import FieldsOnCorrectType <EOL> from . utils import expect_fails_rule , expect_passes_rule <EOL> def undefined_field ( field , type , suggestions , line , column ) : <EOL> return { <EOL> '<STR_LIT:message>' : FieldsOnCorrectType . undefined_field_message ( field , type , suggestions ) , <EOL> '<STR_LIT>' : [ SourceLocation ( line , column ) ] <EOL> } <EOL> def test_object_field_selection ( ) : <EOL> expect_passes_rule ( FieldsOnCorrectType , '''<STR_LIT>''' ) <EOL> def test_aliased_object_field_selection ( ) : <EOL> expect_passes_rule ( FieldsOnCorrectType , '''<STR_LIT>''' ) <EOL> def test_interface_field_selection ( ) : <EOL> expect_passes_rule ( FieldsOnCorrectType , '''<STR_LIT>''' ) <EOL> def test_aliased_interface_field_selection ( ) : <EOL> expect_passes_rule ( FieldsOnCorrectType , '''<STR_LIT>''' ) <EOL> def test_lying_alias_selection ( ) : <EOL> expect_passes_rule ( FieldsOnCorrectType , '''<STR_LIT>''' ) <EOL> def test_ignores_fields_on_unknown_type ( ) : <EOL> expect_passes_rule ( FieldsOnCorrectType , '''<STR_LIT>''' ) <EOL> def test_reports_errors_when_type_is_known_again ( ) : <EOL> expect_fails_rule ( FieldsOnCorrectType , '''<STR_LIT>''' , [ <EOL> undefined_field ( '<STR_LIT>' , '<STR_LIT>' , [ ] , <NUM_LIT:3> , <NUM_LIT:9> ) , <EOL> undefined_field ( '<STR_LIT>' , '<STR_LIT>' , [ ] , <NUM_LIT:5> , <NUM_LIT> ) <EOL> ] ) <EOL> def test_field_not_defined_on_fragment ( ) : <EOL> expect_fails_rule ( FieldsOnCorrectType , '''<STR_LIT>''' , [ <EOL> undefined_field ( '<STR_LIT>' , '<STR_LIT>' , [ ] , <NUM_LIT:3> , <NUM_LIT:9> ) <EOL> ] ) <EOL> def test_ignores_deeply_unknown_field ( ) : <EOL> expect_fails_rule ( FieldsOnCorrectType , '''<STR_LIT>''' , [ <EOL> undefined_field ( '<STR_LIT>' , '<STR_LIT>' , [ ] , <NUM_LIT:3> , <NUM_LIT:9> ) <EOL> ] ) <EOL> def test_sub_field_not_defined ( ) : <EOL> expect_fails_rule ( FieldsOnCorrectType , '''<STR_LIT>''' , [ <EOL> undefined_field ( '<STR_LIT>' , '<STR_LIT>' , [ ] , <NUM_LIT:4> , <NUM_LIT:11> ) <EOL> ] ) <EOL> def test_field_not_defined_on_inline_fragment ( ) : <EOL> expect_fails_rule ( FieldsOnCorrectType , '''<STR_LIT>''' , [ <EOL> undefined_field ( '<STR_LIT>' , '<STR_LIT>' , [ ] , <NUM_LIT:4> , <NUM_LIT:11> ) <EOL> ] ) <EOL> def test_aliased_field_target_not_defined ( ) : <EOL> expect_fails_rule ( FieldsOnCorrectType , '''<STR_LIT>''' , [ <EOL> undefined_field ( '<STR_LIT>' , '<STR_LIT>' , [ ] , <NUM_LIT:3> , <NUM_LIT:9> ) <EOL> ] ) <EOL> def test_aliased_lying_field_target_not_defined ( ) : <EOL> expect_fails_rule ( FieldsOnCorrectType , '''<STR_LIT>''' , [ <EOL> undefined_field ( '<STR_LIT>' , '<STR_LIT>' , [ ] , <NUM_LIT:3> , <NUM_LIT:9> ) <EOL> ] ) <EOL> def test_not_defined_on_interface ( ) : <EOL> expect_fails_rule ( FieldsOnCorrectType , '''<STR_LIT>''' , [ <EOL> undefined_field ( '<STR_LIT>' , '<STR_LIT>' , [ ] , <NUM_LIT:3> , <NUM_LIT:9> ) <EOL> ] ) <EOL> def test_defined_on_implementors_but_not_on_interface ( ) : <EOL> expect_fails_rule ( FieldsOnCorrectType , '''<STR_LIT>''' , [ <EOL> undefined_field ( '<STR_LIT>' , '<STR_LIT>' , [ '<STR_LIT>' , '<STR_LIT>' ] , <NUM_LIT:3> , <NUM_LIT:9> ) <EOL> ] ) <EOL> def test_meta_field_selection_on_union ( ) : <EOL> expect_passes_rule ( FieldsOnCorrectType , '''<STR_LIT>''' ) <EOL> def test_direct_field_selection_on_union ( ) : <EOL> expect_fails_rule ( FieldsOnCorrectType , '''<STR_LIT>''' , [ <EOL> undefined_field ( '<STR_LIT>' , '<STR_LIT>' , [ ] , <NUM_LIT:3> , <NUM_LIT:9> ) <EOL> ] ) <EOL> def test_defined_on_implementors_queried_on_union ( ) : <EOL> expect_fails_rule ( FieldsOnCorrectType , '''<STR_LIT>''' , [ <EOL> undefined_field ( <EOL> '<STR_LIT:name>' , <EOL> '<STR_LIT>' , <EOL> [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] , <EOL> <NUM_LIT:3> , <EOL> <NUM_LIT:9> <EOL> ) <EOL> ] ) <EOL> def test_valid_field_in_inline_fragment ( ) : <EOL> expect_passes_rule ( FieldsOnCorrectType , '''<STR_LIT>''' ) <EOL> def test_fields_correct_type_no_suggestion ( ) : <EOL> message = FieldsOnCorrectType . undefined_field_message ( '<STR_LIT:T>' , '<STR_LIT:f>' , [ ] ) <EOL> assert message == '<STR_LIT>' <EOL> def test_fields_correct_type_no_small_number_suggestions ( ) : <EOL> message = FieldsOnCorrectType . undefined_field_message ( '<STR_LIT:T>' , '<STR_LIT:f>' , [ '<STR_LIT:A>' , '<STR_LIT:B>' ] ) <EOL> assert message == ( <EOL> '<STR_LIT>' + <EOL> '<STR_LIT>' + <EOL> '<STR_LIT>' <EOL> ) <EOL> def test_fields_correct_type_lot_suggestions ( ) : <EOL> message = FieldsOnCorrectType . undefined_field_message ( '<STR_LIT:T>' , '<STR_LIT:f>' , [ '<STR_LIT:A>' , '<STR_LIT:B>' , '<STR_LIT:C>' , '<STR_LIT:D>' , '<STR_LIT:E>' , '<STR_LIT:F>' ] ) <EOL> assert message == ( <EOL> '<STR_LIT>' + <EOL> '<STR_LIT>' + <EOL> '<STR_LIT>' + <EOL> '<STR_LIT>' <EOL> ) </s>
