diff --git a/hypothesis-python/RELEASE.rst b/hypothesis-python/RELEASE.rst new file mode 100644 index 0000000000..59dd7262b3 --- /dev/null +++ b/hypothesis-python/RELEASE.rst @@ -0,0 +1,4 @@ +RELEASE_TYPE: patch + +This patch add `LiveServerTestCase` and `StaticLiveServerTestCase` for django +test. diff --git a/hypothesis-python/docs/django.rst b/hypothesis-python/docs/django.rst index 4b40d859e7..cbedc8758a 100644 --- a/hypothesis-python/docs/django.rst +++ b/hypothesis-python/docs/django.rst @@ -13,7 +13,9 @@ if you're still getting security patches, you can test with Hypothesis. Using it is quite straightforward: All you need to do is subclass :class:`hypothesis.extra.django.TestCase` or -:class:`hypothesis.extra.django.TransactionTestCase` +:class:`hypothesis.extra.django.TransactionTestCase` or +:class:`hypothesis.extra.django.LiveServerTestCase` or +:class:`hypothesis.extra.django.StaticLiveServerTestCase` and you can use :func:`@given ` as normal, and the transactions will be per example rather than per test function as they would be if you used :func:`@given ` with a normal diff --git a/hypothesis-python/src/hypothesis/extra/django/__init__.py b/hypothesis-python/src/hypothesis/extra/django/__init__.py index e821309891..239d188b0c 100644 --- a/hypothesis-python/src/hypothesis/extra/django/__init__.py +++ b/hypothesis-python/src/hypothesis/extra/django/__init__.py @@ -15,6 +15,8 @@ from hypothesis.extra.django._fields import from_field, register_field_strategy from hypothesis.extra.django._impl import ( + LiveServerTestCase, + StaticLiveServerTestCase, TestCase, TransactionTestCase, from_form, @@ -22,6 +24,8 @@ ) __all__ = [ + "LiveServerTestCase", + "StaticLiveServerTestCase", "TestCase", "TransactionTestCase", "from_field", diff --git a/hypothesis-python/src/hypothesis/extra/django/_impl.py b/hypothesis-python/src/hypothesis/extra/django/_impl.py index 498a49bb2c..dd628d2b57 100644 --- a/hypothesis-python/src/hypothesis/extra/django/_impl.py +++ b/hypothesis-python/src/hypothesis/extra/django/_impl.py @@ -20,6 +20,7 @@ from typing import Optional, Type, Union from django import forms as df, test as dt +from django.contrib.staticfiles import testing as dst from django.core.exceptions import ValidationError from django.db import IntegrityError, models as dm @@ -53,6 +54,14 @@ class TransactionTestCase(HypothesisTestCase, dt.TransactionTestCase): pass +class LiveServerTestCase(HypothesisTestCase, dt.LiveServerTestCase): + pass + + +class StaticLiveServerTestCase(HypothesisTestCase, dst.StaticLiveServerTestCase): + pass + + @defines_strategy() def from_model( *model: Type[dm.Model], **field_strategies: Union[st.SearchStrategy, InferType]