diff --git a/docs/testing.rst b/docs/testing.rst index c24f7c4..f1e1f46 100644 --- a/docs/testing.rst +++ b/docs/testing.rst @@ -82,6 +82,41 @@ Usage: # Add some more asserts if you like ... + +For testing mutations that are executed within a transaction you should subclass `GraphQLTransactionTestCase` + +Usage: + +.. code:: python + + import json + + from graphene_django.utils.testing import GraphQLTransactionTestCase + + class MyFancyTransactionTestCase(GraphQLTransactionTestCase): + + def test_some_mutation_that_executes_within_a_transaction(self): + response = self.query( + ''' + mutation myMutation($input: MyMutationInput!) { + myMutation(input: $input) { + my-model { + id + name + } + } + } + ''', + op_name='myMutation', + input_data={'my_field': 'foo', 'other_field': 'bar'} + ) + + # This validates the status code and if you get errors + self.assertResponseNoErrors(response) + + # Add some more asserts if you like + ... + Using pytest ------------ @@ -117,3 +152,6 @@ To use pytest define a simple fixture using the query helper below content = json.loads(response.content) assert 'errors' not in content + + +Running Transaction \ No newline at end of file