Skip to content
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

Merged

Conversation

iamareebjamal
Copy link
Member

  • 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')

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: .*'

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}',

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]

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Black would make changes.

)
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))

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)

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))

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)

)

if len(ticket_holders) != len(ticket_holder_ids):
logger.warning("Ticket Holders not found in", extra=dict(ticket_holder_ids=ticket_holder_ids))

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
@iamareebjamal iamareebjamal force-pushed the test/discount-validation branch from f4586dc to ea3f0e7 Compare May 14, 2020 11:26

if len(ticket_holders) != len(ticket_holder_ids):
logger.warning(
"Ticket Holders not found in", extra=dict(ticket_holder_ids=ticket_holder_ids)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Black would make changes.

@niranjan94
Copy link
Member

Codacy Here is an overview of what got changed by this pull request:

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):
Copy link
Member

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):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@codecov
Copy link

codecov bot commented May 14, 2020

Codecov Report

Merging #7004 into development will increase coverage by 0.26%.
The diff coverage is 96.70%.

Impacted file tree graph

@@               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     
Impacted Files Coverage Δ
app/api/orders.py 27.05% <25.00%> (+0.60%) ⬆️
app/api/helpers/db.py 100.00% <100.00%> (ø)
app/api/helpers/order.py 62.71% <100.00%> (-1.00%) ⬇️
app/api/helpers/ticketing.py 49.39% <100.00%> (+24.16%) ⬆️
app/models/discount_code.py 93.75% <100.00%> (+1.85%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update eeaa8b9...ea3f0e7. Read the comment docs.

@iamareebjamal iamareebjamal merged commit 0e3c6bb into fossasia:development May 14, 2020
@iamareebjamal iamareebjamal deleted the test/discount-validation branch May 14, 2020 11:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants