def test_reverse_double(): session = cashdesk_session_before_factory() trans = transaction_factory(session) transaction_position_factory(transaction=trans, product=product_factory(items=True)) transaction_position_factory(transaction=trans) reverse_transaction(trans_id=trans.pk, current_session=session) with pytest.raises(FlowError) as excinfo: reverse_transaction(trans_id=trans.pk, current_session=session) assert excinfo.value.message == 'At least one position of this transaction has already been reversed.'
def test_simple_valid(): pp = preorder_position_factory(paid=True, redeemed=False) pos = redeem_preorder_ticket(secret=pp.secret) assert isinstance(pos, TransactionPosition) assert pos.value == Decimal('0.00') assert pos.product == pp.product pos.transaction = transaction_factory() pos.save() assert is_redeemed(pp)
def test_reverse_position_wrong_session_troubleshooter(): session1 = cashdesk_session_before_factory() session2 = cashdesk_session_before_factory(user=user_factory( troubleshooter=True)) trans = transaction_factory(session1) tpos = transaction_position_factory(transaction=trans) reverse_transaction_position( tpos.pk, current_session=session2, authorized_by=user_factory(troubleshooter=True))
def test_reverse_whole_session(): session = cashdesk_session_before_factory() pp = preorder_position_factory(paid=True) trans = transaction_factory(session) transaction_position_factory(transaction=trans, product=product_factory(items=True)) pos = redeem_preorder_ticket(secret=pp.secret) pos.transaction = trans pos.save() assert is_redeemed(pp) reverse_session(session) assert not is_redeemed(pp)
def test_cash_transaction_total(): session = cashdesk_session_before_factory(create_items=False) prod_full = Product.objects.create(name='Full ticket', price=23, tax_rate=19) for i in range(3): transaction_position_factory(transaction_factory(session), prod_full) trans = transaction_position_factory(transaction_factory(session), prod_full).transaction reverse_transaction(trans_id=trans.pk, current_session=session) TransactionPosition.objects.create( type='redeem', value=10, tax_rate=19, product=prod_full, transaction=transaction_factory(session), has_constraint_bypass=True) assert session.get_cash_transaction_total() == 23 * 3 + 10
def test_preorder_list_constraint_bypass_success(): pp = preorder_position_factory(paid=True) list_constraint = list_constraint_factory(product=pp.product, price=Decimal('23.00')) with pytest.raises(FlowError) as excinfo: redeem_preorder_ticket(secret=pp.secret) assert excinfo.value.message == 'This ticket can only redeemed by persons on the list "{}".'.format( list_constraint.name) assert excinfo.value.type == 'input' assert excinfo.value.missing_field == 'list_{}'.format(list_constraint.pk) assert excinfo.value.bypass_price == Decimal('23.00') pos = redeem_preorder_ticket(secret=pp.secret, bypass_price=23.0) assert pos.value == Decimal('23.00') assert pos.tax_rate == Decimal('19.00') pos.transaction = transaction_factory() pos.save() assert pp.is_redeemed assert pos.transaction.value == Decimal('23.00')
def test_reverse_success(): session = cashdesk_session_before_factory() trans = transaction_factory(session) pos = [transaction_position_factory(transaction=trans, product=product_factory(items=True)), transaction_position_factory(transaction=trans)] revtransid = reverse_transaction(trans_id=trans.pk, current_session=session) revtrans = Transaction.objects.get(pk=revtransid) assert revtrans.session == session revpos = revtrans.positions.all() assert len(revpos) == len(pos) for lp, rp in zip(pos, revpos): assert rp.reverses == lp assert rp.type == 'reverse' assert rp.value == -1 * lp.value assert rp.tax_value == -1 * lp.tax_value assert rp.product == lp.product assert {i.id for i in lp.items.all()} == {i.id for i in rp.items.all()} ls = TransactionPositionItem.objects.filter(position=lp).aggregate(s=Sum('amount'))['s'] if ls: rs = TransactionPositionItem.objects.filter(position=rp).aggregate(s=Sum('amount'))['s'] assert rs == ls * -1