Skip to content

Commit

Permalink
Add Static/LiveServerTestCase for django test
Browse files Browse the repository at this point in the history
  • Loading branch information
pickfire committed Sep 24, 2021
1 parent b3f4ecd commit c96abbd
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 1 deletion.
4 changes: 4 additions & 0 deletions hypothesis-python/RELEASE.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
RELEASE_TYPE: patch

This patch add `LiveServerTestCase` and `StaticLiveServerTestCase` for django
test.
4 changes: 3 additions & 1 deletion hypothesis-python/docs/django.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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 <hypothesis.given>` as normal,
and the transactions will be per example
rather than per test function as they would be if you used :func:`@given <hypothesis.given>` with a normal
Expand Down
4 changes: 4 additions & 0 deletions hypothesis-python/src/hypothesis/extra/django/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,17 @@

from hypothesis.extra.django._fields import from_field, register_field_strategy
from hypothesis.extra.django._impl import (
LiveServerTestCase,
StaticLiveServerTestCase,
TestCase,
TransactionTestCase,
from_form,
from_model,
)

__all__ = [
"LiveServerTestCase",
"StaticLiveServerTestCase",
"TestCase",
"TransactionTestCase",
"from_field",
Expand Down
9 changes: 9 additions & 0 deletions hypothesis-python/src/hypothesis/extra/django/_impl.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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]
Expand Down

0 comments on commit c96abbd

Please sign in to comment.