Skip to content

Commit 6d7446a

Browse files
authored
Merge pull request #3106 from pickfire/django-test
Add Static/LiveServerTestCase for django test
2 parents b3f4ecd + 0ecda1e commit 6d7446a

5 files changed

Lines changed: 24 additions & 1 deletion

File tree

‎AUTHORS.rst‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ their individual contributions.
6161
* `Humberto Rocha <https://github.com/humrochagf>`_
6262
* `Ilya Lebedev <https://github.com/melevir>`_ ([email protected])
6363
* `Israel Fruchter <https://github.com/fruch>`_
64+
* `Ivan Tham <https://github.com/pickfire>`_
6465
* `Jack Massey <https://github.com/massey101>`_
6566
* `Jakub Nabaglo <https://github.com/nbgl>`_ ([email protected])
6667
* `Jenny Rouleau <https://github.com/jennyrou>`_

‎hypothesis-python/RELEASE.rst‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
RELEASE_TYPE: minor
2+
3+
This release adds :class:`~hypothesis.extra.django.LiveServerTestCase` and
4+
:class:`~hypothesis.extra.django.StaticLiveServerTestCase` for django test.
5+
Thanks to Ivan Tham for this feature!

‎hypothesis-python/docs/django.rst‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,9 @@ if you're still getting security patches, you can test with Hypothesis.
1313

1414
Using it is quite straightforward: All you need to do is subclass
1515
:class:`hypothesis.extra.django.TestCase` or
16-
:class:`hypothesis.extra.django.TransactionTestCase`
16+
:class:`hypothesis.extra.django.TransactionTestCase` or
17+
:class:`~hypothesis.extra.django.LiveServerTestCase` or
18+
:class:`~hypothesis.extra.django.StaticLiveServerTestCase`
1719
and you can use :func:`@given <hypothesis.given>` as normal,
1820
and the transactions will be per example
1921
rather than per test function as they would be if you used :func:`@given <hypothesis.given>` with a normal
@@ -23,6 +25,8 @@ on these classes that do not use
2325
:func:`@given <hypothesis.given>` will be run as normal.
2426

2527
.. class:: hypothesis.extra.django.TransactionTestCase
28+
.. class:: hypothesis.extra.django.LiveServerTestCase
29+
.. class:: hypothesis.extra.django.StaticLiveServerTestCase
2630

2731
We recommend avoiding :class:`~hypothesis.extra.django.TransactionTestCase`
2832
unless you really have to run each test case in a database transaction.

‎hypothesis-python/src/hypothesis/extra/django/__init__.py‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,17 @@
1515

1616
from hypothesis.extra.django._fields import from_field, register_field_strategy
1717
from hypothesis.extra.django._impl import (
18+
LiveServerTestCase,
19+
StaticLiveServerTestCase,
1820
TestCase,
1921
TransactionTestCase,
2022
from_form,
2123
from_model,
2224
)
2325

2426
__all__ = [
27+
"LiveServerTestCase",
28+
"StaticLiveServerTestCase",
2529
"TestCase",
2630
"TransactionTestCase",
2731
"from_field",

‎hypothesis-python/src/hypothesis/extra/django/_impl.py‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
from typing import Optional, Type, Union
2121

2222
from django import forms as df, test as dt
23+
from django.contrib.staticfiles import testing as dst
2324
from django.core.exceptions import ValidationError
2425
from django.db import IntegrityError, models as dm
2526

@@ -53,6 +54,14 @@ class TransactionTestCase(HypothesisTestCase, dt.TransactionTestCase):
5354
pass
5455

5556

57+
class LiveServerTestCase(HypothesisTestCase, dt.LiveServerTestCase):
58+
pass
59+
60+
61+
class StaticLiveServerTestCase(HypothesisTestCase, dst.StaticLiveServerTestCase):
62+
pass
63+
64+
5665
@defines_strategy()
5766
def from_model(
5867
*model: Type[dm.Model], **field_strategies: Union[st.SearchStrategy, InferType]

0 commit comments

Comments
 (0)