mirror of
https://github.com/pretix/pretix.git
synced 2026-05-04 15:04:03 +00:00
Helper and docs for offlinesales API (#5302)
This commit is contained in:
@@ -19,37 +19,3 @@
|
||||
# You should have received a copy of the GNU Affero General Public License along with this program. If not, see
|
||||
# <https://www.gnu.org/licenses/>.
|
||||
#
|
||||
from django.db import DEFAULT_DB_ALIAS, connections
|
||||
from django.test.utils import CaptureQueriesContext
|
||||
|
||||
|
||||
class _AssertNumQueriesContext(CaptureQueriesContext):
|
||||
# Inspired by /django/test/testcases.py
|
||||
# but copied over to work without the unit test module
|
||||
def __init__(self, num, connection):
|
||||
self.num = num
|
||||
super(_AssertNumQueriesContext, self).__init__(connection)
|
||||
|
||||
def __exit__(self, exc_type, exc_value, traceback):
|
||||
super(_AssertNumQueriesContext, self).__exit__(exc_type, exc_value, traceback)
|
||||
if exc_type is not None:
|
||||
return
|
||||
executed = len(self)
|
||||
assert executed == self.num, "%d queries executed, %d expected\nCaptured queries were:\n%s" % (
|
||||
executed, self.num,
|
||||
'\n'.join(
|
||||
query['sql'] for query in self.captured_queries
|
||||
)
|
||||
)
|
||||
|
||||
|
||||
def assert_num_queries(num, func=None, *args, **kwargs):
|
||||
using = kwargs.pop("using", DEFAULT_DB_ALIAS)
|
||||
conn = connections[using]
|
||||
|
||||
context = _AssertNumQueriesContext(num, conn)
|
||||
if func is None:
|
||||
return context
|
||||
|
||||
with context:
|
||||
func(*args, **kwargs)
|
||||
|
||||
@@ -43,13 +43,13 @@ from django.core.files.base import ContentFile
|
||||
from django.utils.timezone import now
|
||||
from django_countries.fields import Country
|
||||
from django_scopes import scope, scopes_disabled
|
||||
from tests import assert_num_queries
|
||||
from tests.const import SAMPLE_PNG
|
||||
|
||||
from pretix.base.models import (
|
||||
Event, InvoiceAddress, Order, OrderPosition, Organizer, SeatingPlan,
|
||||
)
|
||||
from pretix.base.models.orders import OrderFee
|
||||
from pretix.testutils.queries import assert_num_queries
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
|
||||
@@ -28,10 +28,10 @@ import pytest
|
||||
from django.utils.timezone import now
|
||||
from django_scopes import scopes_disabled
|
||||
from freezegun import freeze_time
|
||||
from tests import assert_num_queries
|
||||
|
||||
from pretix.base.models import CartPosition, Discount, Event, Organizer
|
||||
from pretix.base.services.cross_selling import CrossSellingService
|
||||
from pretix.testutils.queries import assert_num_queries
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
|
||||
@@ -23,11 +23,11 @@ import pytest
|
||||
from django.test import override_settings
|
||||
from django.utils.timezone import now
|
||||
from django_scopes import scopes_disabled
|
||||
from tests import assert_num_queries
|
||||
|
||||
from pretix.base.models import Event, Organizer
|
||||
from pretix.multidomain.models import KnownDomain
|
||||
from pretix.multidomain.urlreverse import build_absolute_uri, eventreverse
|
||||
from pretix.testutils.queries import assert_num_queries
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
|
||||
Reference in New Issue
Block a user