def matches_when_submatchers_all_match(): matcher = all_of( has_attr("username", equal_to("bob")), has_attr("email_address", equal_to("*****@*****.**")), ) assert_equal(matched(), matcher.match(User("bob", "*****@*****.**")))
def test_when_resolution_raises_graph_error_then_result_is_invalid(): Root = g.ObjectType("Root", fields=( g.field("value", g.String), )) root_resolver = g.root_object_resolver(Root) @root_resolver.field(Root.fields.value) def root_resolve_value(graph, query, args): raise g.GraphError("BAD") graph_definition = g.define_graph(resolvers=(root_resolver, )) graph = graph_definition.create_graph({}) query = """ query { value } """ result = graphql.execute(graph=graph, document_text=query, query_type=Root) assert_that(result, is_invalid(errors=contains_exactly( all_of( is_instance(GraphQLError), has_str("BAD"), ), )))
def is_graphql_argument(type=None): if type is None: type = anything return all_of( is_instance(graphql.GraphQLArgument), has_attrs(type=type), )
def mismatches_when_submatcher_mismatches(): matcher = all_of( has_attr("username", equal_to("bob")), has_attr("email_address", equal_to("*****@*****.**")), ) assert_equal(unmatched("was missing attribute username"), matcher.match("bobbity"))
def description_contains_descriptions_of_submatchers(): matcher = all_of( has_attr("username", equal_to("bob")), has_attr("email_address", equal_to("*****@*****.**")), ) assert_equal( "all of:\n * object with attribute username: '******'\n * object with attribute email_address: '*****@*****.**'", matcher.describe())
def is_graphql_interface_type(name, fields=None): if fields is None: fields = anything return all_of( is_instance(graphql.GraphQLInterfaceType), has_attrs( name=name, fields=fields, ), )
def is_graphql_field(type=None, args=None): if type is None: type = anything if args is None: args = anything return all_of( is_instance(graphql.GraphQLField), has_attrs(type=type, args=args), )
def is_graphql_input_object_type(name=None, fields=None): if name is None: name = anything if fields is None: fields = anything return all_of( is_instance(graphql.GraphQLInputObjectType), has_attrs( name=name, fields=fields, ), )
def is_graphql_object_type(name=None, fields=None, interfaces=None): if name is None: name = anything if fields is None: fields = anything if interfaces is None: interfaces = anything return all_of( is_instance(graphql.GraphQLObjectType), has_attrs( name=name, fields=fields, interfaces=interfaces, ), )
def is_literal_block(**kwargs): return all_of( is_instance(rst.LiteralBlock), has_attrs(**kwargs), )
def is_diff(**kwargs): return all_of( is_instance(parser.Diff), has_attrs(**kwargs), )
def is_diffdoc_block(arguments, options, content): return all_of( is_instance(rst.DiffdocBlock), has_attrs(arguments=arguments, options=options, content=content), )
def _is_in_range(max_value): return all_of(is_instance(int), less_than_or_equal_to(max_value))
def is_text(value): return all_of( instance_of(documents.Text), has_attrs(value=value), )
def is_graphql_enum_type(name, values): return all_of( is_instance(graphql.GraphQLEnumType), has_attrs(name=name, values=values), )
def is_graphql_argument(type): return all_of( is_instance(graphql.GraphQLArgument), has_attrs(type=type), )
def is_start(**kwargs): return all_of( is_instance(parser.Start), has_attrs(**kwargs), )
def is_replace(**kwargs): return all_of( is_instance(parser.Replace), has_attrs(**kwargs), )
def is_graphql_input_field(type): return all_of( is_instance(graphql.GraphQLInputField), has_attrs(type=type), )
def is_graphql_enum_value(value): return all_of( is_instance(graphql.GraphQLEnumValue), has_attrs(value=value), )
def is_output(**kwargs): return all_of( is_instance(parser.Output), has_attrs(**kwargs), )
def is_render(**kwargs): return all_of( is_instance(parser.Render), has_attrs(**kwargs), )
def matcher(**kwargs): return all_of( instance_of(element_type), has_attrs(**kwargs), )
def is_code_block(**kwargs): return all_of( is_instance(rst.CodeBlock), has_attrs(**kwargs), )
def is_graphql_list(element_matcher): return all_of( is_instance(graphql.GraphQLList), has_attrs(of_type=element_matcher), )
def is_text(text): return all_of( is_instance(rst.Text), has_attrs(text=text), )
def is_graphql_non_null(element_matcher): return all_of( is_instance(graphql.GraphQLNonNull), has_attrs(of_type=element_matcher), )