Add some tests

This commit is contained in:
Raphael Michel
2019-10-18 13:08:25 +02:00
parent a1c7a6f2b0
commit f8433b5cc9
10 changed files with 555 additions and 15 deletions

View File

@@ -1074,6 +1074,17 @@ class OrderTestCase(BaseQuotaTestCase):
self.event.settings.cancel_allow_user = False
assert not self.order.user_cancel_allowed
@classscope(attr='o')
def test_can_cancel_order_with_giftcard(self):
item1 = Item.objects.create(event=self.event, name="Ticket", default_price=23,
admission=True, allow_cancel=True, issue_giftcard=True)
p = OrderPosition.objects.create(order=self.order, item=item1,
variation=None, price=23)
self.event.organizer.issued_gift_cards.create(
currency="EUR", issued_in=p
)
assert not self.order.user_cancel_allowed
@classscope(attr='o')
def test_can_cancel_order_free(self):
self.order.status = Order.STATUS_PAID

View File

@@ -592,6 +592,52 @@ class OrderCancelTests(TestCase):
assert self.order.all_logentries().filter(action_type='pretix.event.order.refund.created').exists()
assert not self.order.all_logentries().filter(action_type='pretix.event.order.refund.requested').exists()
@classscope(attr='o')
def test_auto_refund_possible_giftcard(self):
gc = self.o.issued_gift_cards.create(currency="EUR")
p1 = self.order.payments.create(
amount=Decimal('46.00'),
state=OrderPayment.PAYMENT_STATE_CONFIRMED,
provider='giftcard',
info='{"gift_card": %d}' % gc.pk
)
cancel_order(self.order.pk, cancellation_fee=2, try_auto_refund=True)
r = self.order.refunds.get()
assert r.state == OrderRefund.REFUND_STATE_DONE
assert r.amount == Decimal('44.00')
assert r.source == OrderRefund.REFUND_SOURCE_BUYER
assert r.payment == p1
assert self.order.all_logentries().filter(action_type='pretix.event.order.refund.created').exists()
assert not self.order.all_logentries().filter(action_type='pretix.event.order.refund.requested').exists()
assert gc.value == Decimal('44.00')
@classscope(attr='o')
def test_auto_refund_possible_issued_giftcard(self):
gc = self.o.issued_gift_cards.create(currency="EUR", issued_in=self.op1)
gc.transactions.create(value=23)
self.order.payments.create(
amount=Decimal('46.00'),
state=OrderPayment.PAYMENT_STATE_CONFIRMED,
provider='testdummy_partialrefund'
)
cancel_order(self.order.pk, cancellation_fee=2, try_auto_refund=True)
r = self.order.refunds.get()
assert r.state == OrderRefund.REFUND_STATE_DONE
assert gc.value == Decimal('0.00')
@classscope(attr='o')
def test_auto_refund_impossible_issued_giftcard_used(self):
gc = self.o.issued_gift_cards.create(currency="EUR", issued_in=self.op1)
gc.transactions.create(value=20)
self.order.payments.create(
amount=Decimal('46.00'),
state=OrderPayment.PAYMENT_STATE_CONFIRMED,
provider='testdummy_partialrefund'
)
with pytest.raises(OrderError):
cancel_order(self.order.pk, cancellation_fee=2, try_auto_refund=True)
assert gc.value == Decimal('20.00')
@classscope(attr='o')
def test_auto_refund_impossible(self):
self.order.payments.create(
@@ -859,6 +905,22 @@ class OrderChangeManagerTests(TestCase):
assert self.op1.price == Decimal('24.00')
assert self.order.status == Order.STATUS_PENDING
@classscope(attr='o')
def test_cancel_issued_giftcard(self):
gc = self.o.issued_gift_cards.create(currency="EUR", issued_in=self.op1)
gc.transactions.create(value=23)
self.ocm.cancel(self.op1)
self.ocm.commit()
assert gc.value == Decimal('0.00')
@classscope(attr='o')
def test_cancel_issued_giftcard_used(self):
gc = self.o.issued_gift_cards.create(currency="EUR", issued_in=self.op1)
gc.transactions.create(value=20)
self.ocm.cancel(self.op1)
with self.assertRaises(OrderError):
self.ocm.commit()
@classscope(attr='o')
def test_cancel_all_in_order(self):
self.ocm.cancel(self.op1)