Exemple #1
0
def test_missing_query():
    schema = """type Author {
      name: String
    }"""
    with pytest.raises(ValueError,
                       match="Query type is not defined in the schema"):
        gql_st.query(schema)
Exemple #2
0
 def get_case_strategy(
         self,
         endpoint: Endpoint,
         hooks: Optional[HookDispatcher] = None,
         feedback: Optional[Feedback] = None) -> SearchStrategy:
     constructor = partial(GraphQLCase, endpoint=endpoint)
     schema = graphql.build_client_schema(self.raw_schema)
     return st.builds(constructor, body=gql_st.query(schema))
Exemple #3
0
 def get_case_strategy(
     self,
     operation: APIOperation,
     hooks: Optional[HookDispatcher] = None,
     data_generation_method: DataGenerationMethod = DataGenerationMethod.default(),
 ) -> SearchStrategy:
     constructor = partial(GraphQLCase, operation=operation)
     return st.builds(constructor, body=gql_st.query(self.client_schema, fields=[operation.verbose_name]))
Exemple #4
0
 def get_case_strategy(
     self,
     operation: APIOperation,
     hooks: Optional[HookDispatcher] = None,
     data_generation_method: DataGenerationMethod = DataGenerationMethod.default(),
 ) -> SearchStrategy:
     constructor = partial(GraphQLCase, operation=operation)
     schema = graphql.build_client_schema(self.raw_schema)
     return st.builds(constructor, body=gql_st.query(schema))
Exemple #5
0
def test_custom_scalar():
    # custom scalar types are not supported directly
    schema = """
    scalar Date

    type Object {
      created: Date
    }

    type Query {
      getByDate(created: Date): Object
    }
    """

    @given(query=gql_st.query(schema))
    def test(query):
        pass

    with pytest.raises(TypeError,
                       match="Custom scalar types are not supported"):
        test()
Exemple #6
0
def test_arguments(arguments, node_names, notnull):
    if notnull:
        arguments += "!"
    query_type = f"""type Query {{
      getModel({arguments}): Model
    }}"""

    @given(query=gql_st.query(SCHEMA + query_type))
    def test(query):
        for node_name in node_names:
            assert node_name not in query
        if notnull:
            assert "getModel(" in query
        parsed = graphql.parse(query)
        selection = parsed.definitions[0].selection_set.selections[0]
        if notnull:
            # there should be one argument if it is not null
            assert len(selection.arguments) == 1
        # at least one Model field is selected
        assert len(selection.selection_set.selections) > 0

    test()
Exemple #7
0
def assert_schema(schema):
    @given(query=gql_st.query(schema))
    def test(query):
        graphql.parse(query)

    test()
Exemple #8
0
 def as_strategy(self) -> st.SearchStrategy[GraphQLCase]:
     constructor = partial(GraphQLCase, path=self.path)
     return st.builds(constructor, data=gql_st.query(self.schema))