def test_parse_bool_arguments(): # test that bool args are matched, even if follwed by a comma # ordering issues in earlier python versions inner = OrderedDict() inner["x"] = True inner["y"] = False args = parse_graphql_arguments({"where": inner}) assert args == "where: { x: true, y: false }"
def test_parse_none_arguments(): # test that nulls are matched, even when followed by a comma # ordering issues in earlier python versions inner = OrderedDict() inner["x"] = None inner["y"] = None args = parse_graphql_arguments({"where": inner}) assert args == "where: { x: null, y: null }"
def test_parse_nested_string(): gql_args = parse_graphql_arguments( {"input": { "x": json.dumps({ "a": 1, "b": 2 }, sort_keys=True) }}) assert gql_args == r'input: { x: "{\"a\": 1, \"b\": 2}" }'
def test_parse_json_arguments(): arg = json.dumps({"a": "b", "c": [1, "d"]}, sort_keys=True) gql_args = parse_graphql_arguments({"where": {"x": {"eq": arg}}}) assert gql_args == r'where: { x: { eq: "{\"a\": \"b\", \"c\": [1, \"d\"]}" } }'
def test_parse_string_arguments(): args = parse_graphql_arguments({"where": {"x": {"eq": r"a 'b' c"}}}) assert args == "where: { x: { eq: \"a 'b' c\" } }"
def test_parse_arguments(): args = parse_graphql_arguments({"where": {"x": {"eq": "1"}}}) assert args == 'where: { x: { eq: "1" } }'
def test_uuid_value_in_arguments(): id = uuid.uuid4() query = parse_graphql_arguments({"id": id}) assert query == 'id: "{}"'.format(id)
def test_set_value_in_arguments_with_one_value(): query = parse_graphql_arguments( {"where": { "color": LiteralSetValue(["red"]) }}) assert query == 'where: { color: "{red}" }'
def test_enum_value_in_arguments(): query = parse_graphql_arguments({"where": {"color": EnumValue("red")}}) assert query == "where: { color: red }"
def test_dict_values_in_arguments(): x = {"a": 1, "b": 2} assert parse_graphql_arguments({"checks": x.values()}) in [ "checks: [1, 2]", "checks: [2, 1]", ]
def test_dict_keys_in_arguments(): x = {"a": 1, "b": 2} assert parse_graphql_arguments({"checks": x.keys()}) in [ 'checks: ["a", "b"]', 'checks: ["b", "a"]', ]
def test_empty_dict_in_arguments(): assert parse_graphql_arguments({"where": {}}) == "where: {}"