Ticket tokens and badge tokens can be blank since we generate them on save. Also use the correct method for generating badge tokens, and do a small regression test for that.

This commit is contained in:
Víðir Valberg Guðmundsson 2019-08-03 22:42:15 +02:00
parent b842bb99e7
commit 7be4aa6545
4 changed files with 72 additions and 3 deletions

View file

@ -7,6 +7,7 @@ from .models import TicketType, SponsorTicket, DiscountTicket, ShopTicket
class BaseTicketAdmin(admin.ModelAdmin):
actions = ["generate_pdf"]
exclude = ["qrcode_base64"]
readonly_fields = ['token', 'badge_token']
def generate_pdf(self, request, queryset):
for ticket in queryset.all():

View file

@ -0,0 +1,43 @@
# Generated by Django 2.2.3 on 2019-08-03 20:41
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('tickets', '0013_tickettype_single_ticket_per_product'),
]
operations = [
migrations.AlterField(
model_name='discountticket',
name='badge_token',
field=models.CharField(blank=True, max_length=64),
),
migrations.AlterField(
model_name='discountticket',
name='token',
field=models.CharField(blank=True, max_length=64),
),
migrations.AlterField(
model_name='shopticket',
name='badge_token',
field=models.CharField(blank=True, max_length=64),
),
migrations.AlterField(
model_name='shopticket',
name='token',
field=models.CharField(blank=True, max_length=64),
),
migrations.AlterField(
model_name='sponsorticket',
name='badge_token',
field=models.CharField(blank=True, max_length=64),
),
migrations.AlterField(
model_name='sponsorticket',
name='token',
field=models.CharField(blank=True, max_length=64),
),
]

View file

@ -50,8 +50,8 @@ class BaseTicket(CampRelatedModel, UUIDModel):
ticket_type = models.ForeignKey("TicketType", on_delete=models.PROTECT)
used = models.BooleanField(default=False)
badge_handed_out = models.BooleanField(default=False)
token = models.CharField(max_length=64)
badge_token = models.CharField(max_length=64)
token = models.CharField(max_length=64, blank=True)
badge_token = models.CharField(max_length=64, blank=True)
class Meta:
abstract = True
@ -62,7 +62,7 @@ class BaseTicket(CampRelatedModel, UUIDModel):
def save(self, **kwargs):
self.token = self._get_token()
self.badge_token = self._get_token()
self.badge_token = self._get_badge_token()
super().save(**kwargs)
def _get_token(self):

25
src/tickets/tests.py Normal file
View file

@ -0,0 +1,25 @@
from django.test import TestCase
from shop.factories import OrderProductRelationFactory
from .factories import TicketTypeFactory
from .models import ShopTicket
class TicketTests(TestCase):
def test_correct_token_and_badge_token_are_different(self):
ticket_type = TicketTypeFactory()
orp = OrderProductRelationFactory()
shop_ticket = ShopTicket.objects.create(
ticket_type=ticket_type,
product=orp.product,
order=orp.order,
)
self.assertNotEqual(shop_ticket.token, shop_ticket.badge_token)
self.assertEqual(shop_ticket.token, shop_ticket._get_token())
self.assertEqual(shop_ticket.badge_token, shop_ticket._get_badge_token())