|
| 1 | +from graphql.core.language.location import SourceLocation |
| 2 | +from graphql.core.validation.rules import ArgumentsOfCorrectType |
| 3 | +from utils import expect_passes_rule, expect_fails_rule |
| 4 | + |
| 5 | + |
| 6 | +def bad_value(arg_name, type_name, value, line, column): |
| 7 | + return { |
| 8 | + 'message': ArgumentsOfCorrectType.bad_value_message(arg_name, type_name, value), |
| 9 | + 'locations': [SourceLocation(line, column)] |
| 10 | + } |
| 11 | + |
| 12 | + |
| 13 | +def test_good_int_value(): |
| 14 | + expect_passes_rule(ArgumentsOfCorrectType, ''' |
| 15 | + { |
| 16 | + complicatedArgs { |
| 17 | + intArgField(intArg: 2) |
| 18 | + } |
| 19 | + } |
| 20 | + ''') |
| 21 | + |
| 22 | + |
| 23 | +def test_good_boolean_value(): |
| 24 | + expect_passes_rule(ArgumentsOfCorrectType, ''' |
| 25 | + { |
| 26 | + complicatedArgs { |
| 27 | + booleanArgField(booleanArg: true) |
| 28 | + } |
| 29 | + } |
| 30 | + ''') |
| 31 | + |
| 32 | + |
| 33 | +def test_good_string_value(): |
| 34 | + expect_passes_rule(ArgumentsOfCorrectType, ''' |
| 35 | + { |
| 36 | + complicatedArgs { |
| 37 | + stringArgField(stringArg: "foo") |
| 38 | + } |
| 39 | + } |
| 40 | + ''') |
| 41 | + |
| 42 | + |
| 43 | +def test_good_float_value(): |
| 44 | + expect_passes_rule(ArgumentsOfCorrectType, ''' |
| 45 | + { |
| 46 | + complicatedArgs { |
| 47 | + floatArgField(floatArg: 1.1) |
| 48 | + } |
| 49 | + } |
| 50 | + ''') |
| 51 | + |
| 52 | + |
| 53 | +def test_int_into_float(): |
| 54 | + expect_passes_rule(ArgumentsOfCorrectType, ''' |
| 55 | + { |
| 56 | + complicatedArgs { |
| 57 | + floatArgField(floatArg: 1) |
| 58 | + } |
| 59 | + } |
| 60 | + ''') |
| 61 | + |
| 62 | + |
| 63 | +def test_int_into_id(): |
| 64 | + expect_passes_rule(ArgumentsOfCorrectType, ''' |
| 65 | + { |
| 66 | + complicatedArgs { |
| 67 | + idArgField(idArg: 1) |
| 68 | + } |
| 69 | + } |
| 70 | + ''') |
| 71 | + |
| 72 | + |
| 73 | +def test_string_into_id(): |
| 74 | + expect_passes_rule(ArgumentsOfCorrectType, ''' |
| 75 | + { |
| 76 | + complicatedArgs { |
| 77 | + idArgField(idArg: "someIdString") |
| 78 | + } |
| 79 | + } |
| 80 | + ''') |
| 81 | + |
| 82 | + |
| 83 | +def test_good_enum_value(): |
| 84 | + expect_passes_rule(ArgumentsOfCorrectType, ''' |
| 85 | + { |
| 86 | + dog { |
| 87 | + doesKnowCommand(dogCommand: SIT) |
| 88 | + } |
| 89 | + } |
| 90 | + ''') |
| 91 | + |
| 92 | +# |
| 93 | +# def test_int_into_string(): |
| 94 | +# expect_passes_rule(ArgumentsOfCorrectType, ''' |
| 95 | +# |
| 96 | +# ''') |
0 commit comments