From 135fe15ec37cbc45475c8e50a0ff3e1ce183966d Mon Sep 17 00:00:00 2001 From: Tonye Jack Date: Fri, 15 Jan 2021 14:29:28 -0500 Subject: [PATCH] Added GraphQLTransactionTestCase - Adds support for testing code that is executed within a transaction Reference: https://docs.djangoproject.com/en/3.1/topics/testing/tools/#django.test.TransactionTestCase ``` For instance, you cannot test that a block of code is executing within a transaction, as is required when using select_for_update(). In those cases, you should use TransactionTestCase. ``` --- graphene_django/utils/testing.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/graphene_django/utils/testing.py b/graphene_django/utils/testing.py index 584a08b..d923917 100644 --- a/graphene_django/utils/testing.py +++ b/graphene_django/utils/testing.py @@ -61,7 +61,7 @@ def graphql_query( return resp -class GraphQLTestCase(TestCase): +class GraphQLTestMixin(object): """ Based on: https://www.sam.today/blog/testing-graphql-with-graphene-django/ """ @@ -139,3 +139,12 @@ class GraphQLTestCase(TestCase): """ content = json.loads(resp.content) self.assertIn("errors", list(content.keys()), msg or content) + + +class GraphQLTestCase(GraphQLTestMixin, TestCase): + pass + + +class GraphQLTransactionTestCase(GraphQLTestMixin, TransactionTestCase) + pass +