mirror of
https://github.com/pretix/pretix.git
synced 2026-05-06 15:24:02 +00:00
Integrate django-scopes (#1319)
* Install django-scopes * Fix tests.api * Update tasks and cronjobs * Fix remaining tests * Remove unused import * Fix tests after rebase * Disable scopes for get_Events_with_any_permission * Disable scopes for a management command
This commit is contained in:
@@ -5,6 +5,7 @@ from unittest import mock
|
||||
|
||||
import pytest
|
||||
from django.utils.timezone import now
|
||||
from django_scopes import scopes_disabled
|
||||
from pytz import UTC
|
||||
|
||||
from pretix.base.models import Question
|
||||
@@ -175,7 +176,8 @@ def test_cartpos_create(token_client, organizer, event, item, quota, question):
|
||||
), format='json', data=res
|
||||
)
|
||||
assert resp.status_code == 201
|
||||
cp = CartPosition.objects.get(pk=resp.data['id'])
|
||||
with scopes_disabled():
|
||||
cp = CartPosition.objects.get(pk=resp.data['id'])
|
||||
assert cp.price == Decimal('23.00')
|
||||
assert cp.item == item
|
||||
assert cp.attendee_name_parts == {'full_name': 'Peter'}
|
||||
@@ -193,7 +195,8 @@ def test_cartpos_create_name_optional(token_client, organizer, event, item, quot
|
||||
), format='json', data=res
|
||||
)
|
||||
assert resp.status_code == 201
|
||||
cp = CartPosition.objects.get(pk=resp.data['id'])
|
||||
with scopes_disabled():
|
||||
cp = CartPosition.objects.get(pk=resp.data['id'])
|
||||
assert cp.price == Decimal('23.00')
|
||||
assert cp.item == item
|
||||
assert cp.attendee_name_parts == {}
|
||||
@@ -217,7 +220,8 @@ def test_cartpos_create_legacy_name(token_client, organizer, event, item, quota,
|
||||
), format='json', data=res
|
||||
)
|
||||
assert resp.status_code == 201
|
||||
cp = CartPosition.objects.get(pk=resp.data['id'])
|
||||
with scopes_disabled():
|
||||
cp = CartPosition.objects.get(pk=resp.data['id'])
|
||||
assert cp.price == Decimal('23.00')
|
||||
assert cp.item == item
|
||||
assert cp.attendee_name_parts == {'_legacy': 'Peter'}
|
||||
@@ -247,7 +251,8 @@ def test_cartpos_cart_id_optional(token_client, organizer, event, item, quota, q
|
||||
), format='json', data=res
|
||||
)
|
||||
assert resp.status_code == 201
|
||||
cp = CartPosition.objects.get(pk=resp.data['id'])
|
||||
with scopes_disabled():
|
||||
cp = CartPosition.objects.get(pk=resp.data['id'])
|
||||
assert cp.price == Decimal('23.00')
|
||||
assert cp.item == item
|
||||
assert len(cp.cart_id) > 48
|
||||
@@ -300,7 +305,8 @@ def test_cartpos_create_item_validation(token_client, organizer, event, item, it
|
||||
assert resp.status_code == 400
|
||||
assert resp.data == {'item': ['The specified item does not belong to this event.']}
|
||||
|
||||
var2 = item2.variations.create(value="A")
|
||||
with scopes_disabled():
|
||||
var2 = item2.variations.create(value="A")
|
||||
|
||||
res['item'] = item.pk
|
||||
res['variation'] = var2.pk
|
||||
@@ -312,7 +318,8 @@ def test_cartpos_create_item_validation(token_client, organizer, event, item, it
|
||||
assert resp.status_code == 400
|
||||
assert resp.data == {'non_field_errors': ['You cannot specify a variation for this item.']}
|
||||
|
||||
var1 = item.variations.create(value="A")
|
||||
with scopes_disabled():
|
||||
var1 = item.variations.create(value="A")
|
||||
res['item'] = item.pk
|
||||
res['variation'] = var1.pk
|
||||
resp = token_client.post(
|
||||
@@ -361,7 +368,8 @@ def test_cartpos_expires_optional(token_client, organizer, event, item, quota, q
|
||||
), format='json', data=res
|
||||
)
|
||||
assert resp.status_code == 201
|
||||
cp = CartPosition.objects.get(pk=resp.data['id'])
|
||||
with scopes_disabled():
|
||||
cp = CartPosition.objects.get(pk=resp.data['id'])
|
||||
assert cp.price == Decimal('23.00')
|
||||
assert cp.item == item
|
||||
assert cp.expires - now() > datetime.timedelta(minutes=25)
|
||||
@@ -410,7 +418,8 @@ def test_cartpos_create_answer_validation(token_client, organizer, event, item,
|
||||
assert resp.data == {
|
||||
'answers': [{'non_field_errors': ['You need to specify options if the question is of a choice type.']}]}
|
||||
|
||||
question.options.create(answer="L")
|
||||
with scopes_disabled():
|
||||
question.options.create(answer="L")
|
||||
res['answers'][0]['options'] = [
|
||||
question.options.first().pk,
|
||||
question.options.last().pk,
|
||||
@@ -445,8 +454,9 @@ def test_cartpos_create_answer_validation(token_client, organizer, event, item,
|
||||
), format='json', data=res
|
||||
)
|
||||
assert resp.status_code == 201
|
||||
pos = CartPosition.objects.get(pk=resp.data['id'])
|
||||
answ = pos.answers.first()
|
||||
with scopes_disabled():
|
||||
pos = CartPosition.objects.get(pk=resp.data['id'])
|
||||
answ = pos.answers.first()
|
||||
assert answ.question == question
|
||||
assert answ.answer == "XL, L"
|
||||
|
||||
@@ -460,8 +470,9 @@ def test_cartpos_create_answer_validation(token_client, organizer, event, item,
|
||||
), format='json', data=res
|
||||
)
|
||||
assert resp.status_code == 201
|
||||
pos = CartPosition.objects.get(pk=resp.data['id'])
|
||||
answ = pos.answers.first()
|
||||
with scopes_disabled():
|
||||
pos = CartPosition.objects.get(pk=resp.data['id'])
|
||||
answ = pos.answers.first()
|
||||
assert answ.answer == "3.45"
|
||||
|
||||
question.type = Question.TYPE_NUMBER
|
||||
@@ -486,8 +497,9 @@ def test_cartpos_create_answer_validation(token_client, organizer, event, item,
|
||||
), format='json', data=res
|
||||
)
|
||||
assert resp.status_code == 201
|
||||
pos = CartPosition.objects.get(pk=resp.data['id'])
|
||||
answ = pos.answers.first()
|
||||
with scopes_disabled():
|
||||
pos = CartPosition.objects.get(pk=resp.data['id'])
|
||||
answ = pos.answers.first()
|
||||
assert answ.answer == "True"
|
||||
|
||||
question.type = Question.TYPE_BOOLEAN
|
||||
@@ -499,8 +511,9 @@ def test_cartpos_create_answer_validation(token_client, organizer, event, item,
|
||||
), format='json', data=res
|
||||
)
|
||||
assert resp.status_code == 201
|
||||
pos = CartPosition.objects.get(pk=resp.data['id'])
|
||||
answ = pos.answers.first()
|
||||
with scopes_disabled():
|
||||
pos = CartPosition.objects.get(pk=resp.data['id'])
|
||||
answ = pos.answers.first()
|
||||
assert answ.answer == "False"
|
||||
|
||||
question.type = Question.TYPE_BOOLEAN
|
||||
@@ -523,8 +536,9 @@ def test_cartpos_create_answer_validation(token_client, organizer, event, item,
|
||||
), format='json', data=res
|
||||
)
|
||||
assert resp.status_code == 201
|
||||
pos = CartPosition.objects.get(pk=resp.data['id'])
|
||||
answ = pos.answers.first()
|
||||
with scopes_disabled():
|
||||
pos = CartPosition.objects.get(pk=resp.data['id'])
|
||||
answ = pos.answers.first()
|
||||
assert answ.answer == "2018-05-14"
|
||||
|
||||
question.type = Question.TYPE_DATE
|
||||
@@ -548,8 +562,9 @@ def test_cartpos_create_answer_validation(token_client, organizer, event, item,
|
||||
), format='json', data=res
|
||||
)
|
||||
assert resp.status_code == 201
|
||||
pos = CartPosition.objects.get(pk=resp.data['id'])
|
||||
answ = pos.answers.first()
|
||||
with scopes_disabled():
|
||||
pos = CartPosition.objects.get(pk=resp.data['id'])
|
||||
answ = pos.answers.first()
|
||||
assert answ.answer == "2018-05-14 13:00:00+00:00"
|
||||
|
||||
question.type = Question.TYPE_DATETIME
|
||||
@@ -574,8 +589,9 @@ def test_cartpos_create_answer_validation(token_client, organizer, event, item,
|
||||
), format='json', data=res
|
||||
)
|
||||
assert resp.status_code == 201
|
||||
pos = CartPosition.objects.get(pk=resp.data['id'])
|
||||
answ = pos.answers.first()
|
||||
with scopes_disabled():
|
||||
pos = CartPosition.objects.get(pk=resp.data['id'])
|
||||
answ = pos.answers.first()
|
||||
assert answ.answer == "13:00:00"
|
||||
|
||||
question.type = Question.TYPE_TIME
|
||||
|
||||
Reference in New Issue
Block a user