Skip to content

Commit

Permalink
Add tests for deleted ticket and event
Browse files Browse the repository at this point in the history
  • Loading branch information
iamareebjamal committed May 13, 2020
1 parent 4164370 commit 230df98
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
5 changes: 5 additions & 0 deletions app/api/helpers/order.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from datetime import datetime, timedelta, timezone

from flask import render_template
from flask_rest_jsonapi.exceptions import ObjectNotFound

from app.api.helpers.db import (
get_count,
Expand Down Expand Up @@ -206,6 +207,10 @@ def calculate_order_amount(tickets, discount_code=None):
)
if not event:
event = ticket.event

if event.deleted_at:
raise ObjectNotFound({'pointer': 'tickets/event'}, f'Event: {event.id} not found')

fees = TicketFees.query.filter_by(currency=event.payment_currency).first()
elif ticket.event.id != event.id:
raise UnprocessableEntity({'pointer': 'tickets'}, "All tickets must belong to same event")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
from datetime import datetime

import pytest
from flask_rest_jsonapi.exceptions import ObjectNotFound

from app.api.helpers.exceptions import UnprocessableEntity
from app.api.helpers.order import calculate_order_amount
Expand Down Expand Up @@ -172,3 +175,19 @@ def test_tax_excluded(db):
assert amount_data['tax_percent'] == 18.0
assert amount_data['tax'] == 799.43
assert amount_data['discount'] == 0.0


def test_deleted_ticket(db):
ticket = TicketSubFactory(deleted_at=datetime.now())
db.session.commit()

with pytest.raises(ObjectNotFound):
calculate_order_amount([{'id': ticket.id}])


def test_ticket_of_deleted_event(db):
ticket = TicketSubFactory(event__deleted_at=datetime.now())
db.session.commit()

with pytest.raises(ObjectNotFound):
calculate_order_amount([{'id': ticket.id}])

0 comments on commit 230df98

Please sign in to comment.