Customer accounts & Memberships (#2024)

This commit is contained in:
Raphael Michel
2021-05-04 16:56:06 +02:00
committed by GitHub
parent 62e412bbc0
commit 8e79eb570e
116 changed files with 7975 additions and 279 deletions

View File

@@ -115,6 +115,7 @@ def team(organizer):
can_change_vouchers=True,
can_view_vouchers=True,
can_change_orders=True,
can_manage_customers=True,
can_change_organizer_settings=True
)

View File

@@ -0,0 +1,130 @@
#
# This file is part of pretix (Community Edition).
#
# Copyright (C) 2014-2020 Raphael Michel and contributors
# Copyright (C) 2020-2021 rami.io GmbH and contributors
#
# This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General
# Public License as published by the Free Software Foundation in version 3 of the License.
#
# ADDITIONAL TERMS APPLY: Pursuant to Section 7 of the GNU Affero General Public License, additional terms are
# applicable granting you additional permissions and placing additional restrictions on your usage of this software.
# Please refer to the pretix LICENSE file to obtain the full terms applicable to this work. If you did not receive
# this file, see <https://pretix.eu/about/en/license>.
#
# This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied
# warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
# details.
#
# 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/>.
#
import pytest
from django_scopes import scopes_disabled
@pytest.fixture
def customer(organizer, event):
return organizer.customers.create(
identifier="8WSAJCJ",
email="foo@example.org",
name_parts={"_legacy": "Foo"},
name_cached="Foo",
is_verified=False,
)
TEST_CUSTOMER_RES = {
"identifier": "8WSAJCJ",
"email": "foo@example.org",
"name": "Foo",
"name_parts": {
"_legacy": "Foo",
},
"is_active": True,
"is_verified": False,
"last_login": None,
"date_joined": "2021-04-06T13:44:22.809216Z",
"locale": "en",
"last_modified": "2021-04-06T13:44:22.809377Z"
}
@pytest.mark.django_db
def test_customer_list(token_client, organizer, customer):
res = dict(TEST_CUSTOMER_RES)
res["date_joined"] = customer.date_joined.isoformat().replace('+00:00', 'Z')
res["last_modified"] = customer.last_modified.isoformat().replace('+00:00', 'Z')
resp = token_client.get('/api/v1/organizers/{}/customers/'.format(organizer.slug))
assert resp.status_code == 200
assert [res] == resp.data['results']
@pytest.mark.django_db
def test_customer_detail(token_client, organizer, customer):
res = dict(TEST_CUSTOMER_RES)
res["date_joined"] = customer.date_joined.isoformat().replace('+00:00', 'Z')
res["last_modified"] = customer.last_modified.isoformat().replace('+00:00', 'Z')
resp = token_client.get('/api/v1/organizers/{}/customers/{}/'.format(organizer.slug, customer.identifier))
assert resp.status_code == 200
assert res == resp.data
@pytest.mark.django_db
def test_customer_create(token_client, organizer):
resp = token_client.post(
'/api/v1/organizers/{}/customers/'.format(organizer.slug),
format='json',
data={
'identifier': 'IGNORED',
'email': 'bar@example.com',
'name_parts': {
"_scheme": "given_family",
'given_name': 'John',
'family_name': 'Doe',
},
'is_active': True,
'is_verified': True,
}
)
assert resp.status_code == 201
with scopes_disabled():
customer = organizer.customers.get(identifier=resp.data['identifier'])
assert customer.identifier != 'IGNORED'
assert customer.email == 'bar@example.com'
assert customer.is_active
assert customer.name == 'John Doe'
assert customer.is_verified
@pytest.mark.django_db
def test_customer_patch(token_client, organizer, customer):
resp = token_client.patch(
'/api/v1/organizers/{}/customers/{}/'.format(organizer.slug, customer.identifier),
format='json',
data={
'email': 'blubb@example.org',
}
)
assert resp.status_code == 200
customer.refresh_from_db()
assert customer.email == 'blubb@example.org'
@pytest.mark.django_db
def test_customer_anonymize(token_client, organizer, customer):
resp = token_client.post(
'/api/v1/organizers/{}/customers/{}/anonymize/'.format(organizer.slug, customer.identifier),
)
assert resp.status_code == 200
customer.refresh_from_db()
assert customer.email is None
@pytest.mark.django_db
def test_customer_delete(token_client, organizer, customer):
resp = token_client.delete(
'/api/v1/organizers/{}/customers/{}/'.format(organizer.slug, customer.identifier),
)
assert resp.status_code == 405

View File

@@ -283,7 +283,13 @@ TEST_ITEM_RES = {
"original_price": None,
"meta_data": {
"day": "Tuesday"
}
},
"require_membership": False,
"require_membership_types": [],
"grant_membership_type": None,
"grant_membership_duration_like_event": True,
"grant_membership_duration_days": 0,
"grant_membership_duration_months": 0,
}

View File

@@ -0,0 +1,151 @@
#
# This file is part of pretix (Community Edition).
#
# Copyright (C) 2014-2020 Raphael Michel and contributors
# Copyright (C) 2020-2021 rami.io GmbH and contributors
#
# This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General
# Public License as published by the Free Software Foundation in version 3 of the License.
#
# ADDITIONAL TERMS APPLY: Pursuant to Section 7 of the GNU Affero General Public License, additional terms are
# applicable granting you additional permissions and placing additional restrictions on your usage of this software.
# Please refer to the pretix LICENSE file to obtain the full terms applicable to this work. If you did not receive
# this file, see <https://pretix.eu/about/en/license>.
#
# This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied
# warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
# details.
#
# 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 datetime import datetime
import pytest
import pytz
from django_scopes import scopes_disabled
from i18nfield.strings import LazyI18nString
from pretix.base.models import Membership
@pytest.fixture
def membershiptype(organizer):
return organizer.membership_types.create(
name=LazyI18nString({"en": "Week pass"}),
transferable=True,
allow_parallel_usage=False,
max_usages=15,
)
@pytest.fixture
def customer(organizer):
return organizer.customers.create(
identifier="8WSAJCJ",
email="foo@example.org",
name_parts={"_legacy": "Foo"},
name_cached="Foo",
is_verified=False,
)
@pytest.fixture
def membership(organizer, customer, membershiptype):
return customer.memberships.create(
membership_type=membershiptype,
date_start=datetime(2021, 4, 1, 0, 0, 0, 0, tzinfo=pytz.UTC),
date_end=datetime(2021, 4, 8, 23, 59, 59, 999999, tzinfo=pytz.UTC),
attendee_name_parts={
"_scheme": "given_family",
'given_name': 'John',
'family_name': 'Doe',
}
)
TEST_MEMBERSHIP_RES = {
"customer": "8WSAJCJ",
"date_start": "2021-04-01T00:00:00Z",
"date_end": "2021-04-08T23:59:59.999999Z",
"attendee_name_parts": {
"_scheme": "given_family",
'given_name': 'John',
'family_name': 'Doe',
}
}
@pytest.mark.django_db
def test_membership_list(token_client, organizer, membershiptype, membership):
res = dict(TEST_MEMBERSHIP_RES)
res['membership_type'] = membershiptype.pk
res['id'] = membership.pk
resp = token_client.get('/api/v1/organizers/{}/memberships/'.format(organizer.slug))
assert resp.status_code == 200
assert [res] == resp.data['results']
@pytest.mark.django_db
def test_membership_detail(token_client, organizer, membershiptype, membership):
res = dict(TEST_MEMBERSHIP_RES)
res['membership_type'] = membershiptype.pk
res['id'] = membership.pk
resp = token_client.get('/api/v1/organizers/{}/memberships/{}/'.format(organizer.slug, membershiptype.pk))
assert resp.status_code == 200
assert res == resp.data
@pytest.mark.django_db
def test_membership_create(token_client, organizer, membershiptype, customer):
resp = token_client.post(
'/api/v1/organizers/{}/memberships/'.format(organizer.slug),
format='json',
data={
"customer": customer.identifier,
"membership_type": membershiptype.pk,
"date_start": "2021-04-01T00:00:00.000Z",
"date_end": "2021-04-08T23:59:59.999999Z",
}
)
assert resp.status_code == 201
with scopes_disabled():
membership = Membership.objects.get(id=resp.data['id'])
assert membership.customer == customer
assert membership.membership_type == membershiptype
@pytest.mark.django_db
def test_membership_patch(token_client, organizer, customer, membership):
resp = token_client.patch(
'/api/v1/organizers/{}/memberships/{}/'.format(organizer.slug, membership.pk),
format='json',
data={
"date_end": "2021-04-03T23:59:59.999999Z",
}
)
assert resp.status_code == 200
membership.refresh_from_db()
assert membership.date_end.isoformat() == "2021-04-03T23:59:59.999999+00:00"
with scopes_disabled():
other_customer = organizer.customers.create()
resp = token_client.patch(
'/api/v1/organizers/{}/memberships/{}/'.format(organizer.slug, membership.pk),
format='json',
data={
"customer": other_customer.identifier,
}
)
assert resp.status_code == 200
membership.refresh_from_db()
assert membership.customer == customer # change is ignored
@pytest.mark.django_db
def test_membership_delete(token_client, organizer, membership):
resp = token_client.delete(
'/api/v1/organizers/{}/memberships/{}/'.format(organizer.slug, membership.pk),
)
assert resp.status_code == 405

View File

@@ -0,0 +1,108 @@
#
# This file is part of pretix (Community Edition).
#
# Copyright (C) 2014-2020 Raphael Michel and contributors
# Copyright (C) 2020-2021 rami.io GmbH and contributors
#
# This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General
# Public License as published by the Free Software Foundation in version 3 of the License.
#
# ADDITIONAL TERMS APPLY: Pursuant to Section 7 of the GNU Affero General Public License, additional terms are
# applicable granting you additional permissions and placing additional restrictions on your usage of this software.
# Please refer to the pretix LICENSE file to obtain the full terms applicable to this work. If you did not receive
# this file, see <https://pretix.eu/about/en/license>.
#
# This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied
# warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
# details.
#
# 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/>.
#
import pytest
from django_scopes import scopes_disabled
from i18nfield.strings import LazyI18nString
@pytest.fixture
def membershiptype(organizer, event):
return organizer.membership_types.create(
name=LazyI18nString({"en": "Week pass"}),
transferable=True,
allow_parallel_usage=False,
max_usages=15,
)
TEST_TYPE_RES = {
"name": {
"en": "Week pass"
},
"transferable": True,
"allow_parallel_usage": False,
"max_usages": 15,
}
@pytest.mark.django_db
def test_membershiptype_list(token_client, organizer, membershiptype):
res = dict(TEST_TYPE_RES)
res["id"] = membershiptype.pk
resp = token_client.get('/api/v1/organizers/{}/membershiptypes/'.format(organizer.slug))
assert resp.status_code == 200
assert [res] == resp.data['results']
@pytest.mark.django_db
def test_membershiptype_detail(token_client, organizer, membershiptype):
res = dict(TEST_TYPE_RES)
res["id"] = membershiptype.pk
resp = token_client.get('/api/v1/organizers/{}/membershiptypes/{}/'.format(organizer.slug, membershiptype.pk))
assert resp.status_code == 200
assert res == resp.data
@pytest.mark.django_db
def test_membershiptype_create(token_client, organizer):
resp = token_client.post(
'/api/v1/organizers/{}/membershiptypes/'.format(organizer.slug),
format='json',
data={
"name": {
"en": "Week pass"
},
"transferable": True,
"allow_parallel_usage": False,
"max_usages": 15,
}
)
assert resp.status_code == 201
with scopes_disabled():
membershiptype = organizer.membership_types.get(id=resp.data['id'])
assert str(membershiptype.name) == "Week pass"
assert membershiptype.transferable
assert not membershiptype.allow_parallel_usage
@pytest.mark.django_db
def test_membershiptype_patch(token_client, organizer, membershiptype):
resp = token_client.patch(
'/api/v1/organizers/{}/membershiptypes/{}/'.format(organizer.slug, membershiptype.pk),
format='json',
data={
'transferable': False,
}
)
assert resp.status_code == 200
membershiptype.refresh_from_db()
assert not membershiptype.transferable
@pytest.mark.django_db
def test_membershiptype_delete(token_client, organizer, membershiptype):
resp = token_client.delete(
'/api/v1/organizers/{}/membershiptypes/{}/'.format(organizer.slug, membershiptype.pk),
)
assert resp.status_code == 204
assert not organizer.membership_types.exists()

View File

@@ -236,6 +236,7 @@ TEST_ORDER_RES = {
"email": "dummy@dummy.test",
"phone": None,
"locale": "en",
"customer": None,
"datetime": "2017-12-01T10:00:00Z",
"expires": "2017-12-10T10:00:00Z",
"payment_date": "2017-12-01",
@@ -1633,6 +1634,9 @@ def test_order_create(token_client, organizer, event, item, quota, question):
res = copy.deepcopy(ORDER_CREATE_PAYLOAD)
res['positions'][0]['item'] = item.pk
res['positions'][0]['answers'][0]['question'] = question.pk
with scopes_disabled():
customer = organizer.customers.create()
res['customer'] = customer.identifier
resp = token_client.post(
'/api/v1/organizers/{}/events/{}/orders/'.format(
organizer.slug, event.slug
@@ -1641,6 +1645,7 @@ def test_order_create(token_client, organizer, event, item, quota, question):
assert resp.status_code == 201
with scopes_disabled():
o = Order.objects.get(code=resp.data['code'])
assert o.customer == customer
assert o.email == "dummy@dummy.test"
assert o.phone == "+49622112345"
assert o.locale == "en"
@@ -1712,6 +1717,7 @@ def test_order_create_simulate(token_client, organizer, event, item, quota, ques
'testmode': False,
'email': 'dummy@dummy.test',
'phone': '+49622112345',
'customer': None,
'locale': 'en',
'datetime': None,
'payment_date': None,

View File

@@ -179,6 +179,25 @@ org_permission_sub_urls = [
('put', 'can_change_organizer_settings', 'webhooks/1/', 404),
('patch', 'can_change_organizer_settings', 'webhooks/1/', 404),
('delete', 'can_change_organizer_settings', 'webhooks/1/', 404),
('get', 'can_manage_customers', 'customers/', 200),
('post', 'can_manage_customers', 'customers/', 201),
('get', 'can_manage_customers', 'customers/1/', 404),
('patch', 'can_manage_customers', 'customers/1/', 404),
('post', 'can_manage_customers', 'customers/1/anonymize/', 404),
('put', 'can_manage_customers', 'customers/1/', 404),
('delete', 'can_manage_customers', 'customers/1/', 404),
('get', 'can_manage_customers', 'memberships/', 200),
('post', 'can_manage_customers', 'memberships/', 400),
('get', 'can_manage_customers', 'memberships/1/', 404),
('patch', 'can_manage_customers', 'memberships/1/', 404),
('put', 'can_manage_customers', 'memberships/1/', 404),
('delete', 'can_manage_customers', 'memberships/1/', 404),
('get', 'can_change_organizer_settings', 'membershiptypes/', 200),
('post', 'can_change_organizer_settings', 'membershiptypes/', 400),
('get', 'can_change_organizer_settings', 'membershiptypes/1/', 404),
('patch', 'can_change_organizer_settings', 'membershiptypes/1/', 404),
('put', 'can_change_organizer_settings', 'membershiptypes/1/', 404),
('delete', 'can_change_organizer_settings', 'membershiptypes/1/', 404),
('get', 'can_manage_gift_cards', 'giftcards/', 200),
('post', 'can_manage_gift_cards', 'giftcards/', 400),
('get', 'can_manage_gift_cards', 'giftcards/1/', 404),

View File

@@ -39,6 +39,7 @@ def second_team(organizer, event):
TEST_TEAM_RES = {
'id': 1, 'name': 'Test-Team', 'all_events': True, 'limit_events': [], 'can_create_events': True,
'can_change_teams': True, 'can_change_organizer_settings': True, 'can_manage_gift_cards': True,
'can_manage_customers': True,
'can_change_event_settings': True, 'can_change_items': True, 'can_view_orders': True, 'can_change_orders': True,
'can_view_vouchers': True, 'can_change_vouchers': True, 'can_checkin_orders': False
}
@@ -46,6 +47,7 @@ TEST_TEAM_RES = {
SECOND_TEAM_RES = {
'id': 1, 'name': 'User team', 'all_events': False, 'limit_events': ['dummy'],
'can_create_events': False,
'can_manage_customers': False,
'can_change_teams': False, 'can_change_organizer_settings': False, 'can_manage_gift_cards': False,
'can_change_event_settings': False, 'can_change_items': False, 'can_view_orders': False, 'can_change_orders': False,
'can_view_vouchers': False, 'can_change_vouchers': False, 'can_checkin_orders': False