def _verify_crud_mutation(self, model, action): # create the mutation summarized = summarize_crud_mutation(model=model, method=action) # make sure the name matches the convention assert summarized['name'] == crud_mutation_name(model=model, action=action), ( "Summarized %s mutation did not have the right name." % action ) # make sure the event is what we expect assert summarized['event'] == get_crud_action(model=model, method=action), ( "Summarized %s mutation did not have the right event type." % action )
def _verify_crud_mutation(self, model, action): # create the mutation summarized = summarize_crud_mutation(model=model, method=action) # make sure the name matches the convention assert summarized['name'] == crud_mutation_name( model=model, action=action), ( "Summarized %s mutation did not have the right name." % action) # make sure the event is what we expect assert summarized['event'] == get_crud_action( model=model, method=action), ( "Summarized %s mutation did not have the right event type." % action)
def test_graphql_mutation_from_summary(self): # create a mock mutation summary mock_summary = summarize_crud_mutation(model=MockModelService(), method="delete") # create the mutation mutation = graphql_mutation_from_summary(mock_summary) # create a schema to test the mutation mock_schema = graphene.Schema() # get the corresponding object type mutation_object = mock_schema.T(mutation) mutation_fields = list(mutation_object.get_fields().keys()) # there should be one field named status assert mutation_fields == ['status'], ( "Delete mutation did not have correct output" )
def test_graphql_mutation_from_summary(self): # create a mock mutation summary mock_summary = summarize_crud_mutation(model=MockModelService(), method="delete") # create the mutation mutation = graphql_mutation_from_summary(mock_summary) # create a schema to test the mutation mock_schema = graphene.Schema() # get the corresponding object type mutation_object = mock_schema.T(mutation) mutation_fields = list(mutation_object.get_fields().keys()) # there should be one field named status assert mutation_fields == [ 'status' ], ("Delete mutation did not have correct output")
def test_generate_api_schema_with_mutation(self): model_service = MockModelService()() # create mock summaries model_summary = model_service.summarize() mutation_summary = summarize_crud_mutation(model=model_service, method='create') # create the graphql schema schema = generate_api_schema( models=[model_summary], mutations=[mutation_summary] ) # the list of mutations in the schema schema_mutations = [field.default_name for field in schema.mutation._meta.local_fields] # make sure the schema has the correct mutation list assert schema_mutations == ['createTestModel'], ( "Generated schema did not have the correct mutations" )
def test_generate_api_schema_with_mutation(self): model_service = MockModelService()() # create mock summaries model_summary = model_service.summarize() mutation_summary = summarize_crud_mutation(model=model_service, method='create') # create the graphql schema schema = generate_api_schema(models=[model_summary], mutations=[mutation_summary]) # the list of mutations in the schema schema_mutations = [ field.default_name for field in schema.mutation._meta.local_fields ] # make sure the schema has the correct mutation list assert schema_mutations == [ 'createTestModel' ], ("Generated schema did not have the correct mutations")
def test_graphql_mutation_with_object_io_from_summary(self): # create a mock mutation summary with a io that's an object mock_summary = summarize_crud_mutation(model=MockModelService(), method="create") # create the mutation mutation = graphql_mutation_from_summary(mock_summary) # create a schema to test the mutation mock_schema = graphene.Schema() # get the corresponding object type mutation_object = mock_schema.T(mutation) # make sure there is a resulting 'testModel' in the mutation assert 'testModel' in mutation_object.get_fields(), ( "Generated create mutation from summary does not have a service record in its output." ) # the fields of the mutation result output_fields = set(mutation_object.get_fields()['testModel'].type.get_fields().keys()) # make sure the object has the right types assert output_fields == {'date', 'name', 'id'}, ( "Mutation output did not have the correct fields." )
def test_graphql_mutation_with_object_io_from_summary(self): # create a mock mutation summary with a io that's an object mock_summary = summarize_crud_mutation(model=MockModelService(), method="create") # create the mutation mutation = graphql_mutation_from_summary(mock_summary) # create a schema to test the mutation mock_schema = graphene.Schema() # get the corresponding object type mutation_object = mock_schema.T(mutation) # make sure there is a resulting 'testModel' in the mutation assert 'testModel' in mutation_object.get_fields(), ( "Generated create mutation from summary does not have a service record in its output." ) # the fields of the mutation result output_fields = set( mutation_object.get_fields()['testModel'].type.get_fields().keys()) # make sure the object has the right types assert output_fields == { 'date', 'name', 'id' }, ("Mutation output did not have the correct fields.")