-
Notifications
You must be signed in to change notification settings - Fork 1.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
test: Validation of tickets, discount code #7004
test: Validation of tickets, discount code #7004
Conversation
iamareebjamal
commented
May 14, 2020
- Deduplicate validation logic
- Test validation of ticket, attendees and discount
- Validate discount code in calculate_order_amount
- Fix multiple issues related to deleted items
- Simplify validation interface of discount
|
||
order_without_discount = OrderFactory(status='completed') | ||
order_without_discount = OrderFactory(status='completed') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Black would make changes.
db.session.commit() | ||
|
||
with pytest.raises( | ||
UnprocessableEntity, match=r'All tickets must belong to same event. Found: .*' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Black would make changes.
|
||
with pytest.raises( | ||
ConflictException, | ||
match=f'Order already exists for attendee with id {attendees[-1].id}', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Black would make changes.
discount = DiscountCodeTicketSubFactory(tickets_number=5, tickets=tickets) | ||
db.session.commit() | ||
|
||
return discount, [{'id': ticket.id} for ticket in tickets] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Black would make changes.
app/api/helpers/ticketing.py
Outdated
) | ||
ticket_events = {ticket.event_id for ticket in fetched_tickets} | ||
if len(ticket_events) != 1: | ||
logger.warning("Tickets with different event IDs requested for Order", extra=dict(ticket_events=ticket_events)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
line too long (119 > 90 characters)
app/api/helpers/ticketing.py
Outdated
for ticket_holder in ticket_holders: | ||
# Ensuring that the attendee exists and doesn't have an associated order. | ||
if ticket_holder.order_id: | ||
logger.warning("Order already exists for attendee", extra=dict(attendee_id=ticket_holder.id)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
line too long (105 > 90 characters)
app/api/helpers/ticketing.py
Outdated
) | ||
|
||
if len(ticket_holders) != len(ticket_holder_ids): | ||
logger.warning("Ticket Holders not found in", extra=dict(ticket_holder_ids=ticket_holder_ids)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Black would make changes.
line too long (102 > 90 characters)
- Deduplicate validation logic - Test validation of ticket, attendees and discount - Validate discount code in calculate_order_amount - Fix multiple issues related to deleted items - Simplify validation interface of discount
f4586dc
to
ea3f0e7
Compare
|
||
if len(ticket_holders) != len(ticket_holder_ids): | ||
logger.warning( | ||
"Ticket Holders not found in", extra=dict(ticket_holder_ids=ticket_holder_ids) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Black would make changes.
Issues
======
- Added 2
Complexity increasing per file
==============================
- tests/all/integration/api/helpers/order/test_validate_tickets.py 3
- tests/all/integration/api/helpers/order/test_validate_discount_code.py 4
- tests/all/integration/api/helpers/order/test_validate_ticket_holders.py 3
- tests/all/integration/api/helpers/test_ticketing.py 2
- app/models/discount_code.py 1
- app/api/helpers/ticketing.py 1
Complexity decreasing per file
==============================
+ app/api/helpers/order.py -1
See the complete overview on Codacy |
assert validate_discount_code(str(discount.id), tickets=tickets) == discount | ||
|
||
|
||
def test_validate_discount_code_require_tickets_or_holders(db): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
discount.validate(tickets=[{'id': ticket.id} for ticket in deleted_tickets]) | ||
|
||
|
||
def test_validate_discount_code_accept_mix_deleted_tickets(db): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Codecov Report
@@ Coverage Diff @@
## development #7004 +/- ##
===============================================
+ Coverage 60.30% 60.56% +0.26%
===============================================
Files 259 259
Lines 12853 12893 +40
===============================================
+ Hits 7751 7809 +58
+ Misses 5102 5084 -18
Continue to review full report at Codecov.
|