-
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: Fix and test calculate_order_amount #6997
test: Fix and test calculate_order_amount #6997
Conversation
|
||
|
||
def _create_ticket_dict(tickets, quantities): | ||
return [dict(id=ticket.id, quantity=quantity) for ticket, quantity in zip(tickets, quantities)] |
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 (99 > 90 characters)
def test_no_amount(): | ||
amount_data = calculate_order_amount([]) | ||
|
||
assert amount_data['total_amount'] == 0.0 |
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.
@@ -0,0 +1,82 @@ | |||
from app.api.helpers.order import calculate_order_amount | |||
from tests.factories.tax import TaxSubFactory | |||
from tests.factories.ticket import TicketFactory, TicketSubFactory, TicketFactoryBase |
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.
'tests.factories.ticket.TicketFactory' imported but unused
'tests.factories.ticket.TicketFactoryBase' imported but unused
@@ -99,8 +101,9 @@ def resend_emails(): | |||
) | |||
return jsonify( | |||
status=True, | |||
message="Verification emails for order : {} has been sent successfully" | |||
.format(order_identifier), | |||
message="Verification emails for order : {} has been sent successfully".format( |
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 (95 > 90 characters)
@@ -8,17 +8,19 @@ | |||
from app.api.auth import return_file | |||
from app.api.helpers.db import get_count, safe_query | |||
from app.api.helpers.files import make_frontend_url | |||
from app.api.helpers.errors import ForbiddenError, NotFoundError, \ | |||
UnprocessableEntityError | |||
from app.api.helpers.errors import ForbiddenError, NotFoundError, UnprocessableEntityError |
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.
Codecov Report
@@ Coverage Diff @@
## development #6997 +/- ##
===============================================
+ Coverage 59.82% 60.30% +0.48%
===============================================
Files 259 259
Lines 12875 12853 -22
===============================================
+ Hits 7702 7751 +49
+ Misses 5173 5102 -71
Continue to review full report at Codecov.
|
def _create_taxed_tickets(db, tax_included=True): | ||
tax = TaxSubFactory(rate=18.0, is_tax_included_in_price=tax_included) | ||
tickets = _create_tickets([123.5, 456.3], event=tax.event) | ||
tickets.append(TicketSubFactory(type='donation', event=tax.event, min_price=500.0, max_price=1000.0)) |
This comment was marked as outdated.
This comment was marked as outdated.
Sorry, something went wrong.
|
||
|
||
def _expect_donation_error(ticket_dict): | ||
with pytest.raises(UnprocessableEntity, match='Price for donation ticket should be present and within range ' |
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 (113 > 90 characters)
def _create_donation_tickets(db): | ||
event = EventFactoryBasic() | ||
tickets = _create_tickets([10, 20], event=event) | ||
tickets.append(TicketSubFactory(type='donation', max_price=20, min_price=10, event=event)) |
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 (94 > 90 characters)
|
||
ticket_dict = _create_ticket_dict([ticket1, ticket2], [1, 2]) | ||
|
||
with pytest.raises(UnprocessableEntity, match='All tickets must belong to same event'): |
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 (91 > 90 characters)
def test_no_amount(): | ||
amount_data = calculate_order_amount([]) | ||
|
||
assert amount_data['total'] == 0.0 |
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/order.py
Outdated
@@ -220,7 +218,8 @@ def calculate_order_amount(tickets, discount_code): | |||
price = ticket_info.get('price') | |||
if not price or price > ticket.max_price or price < ticket.min_price: | |||
raise UnprocessableEntity( | |||
{'source': 'data/tickets'}, "Price for donation ticket invalid" | |||
{'pointer': 'tickets/price'}, f"Price for donation ticket should be present and within range " | |||
f"{ticket.min_price} to {ticket.max_price}" |
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 (93 > 90 characters)
app/api/helpers/order.py
Outdated
@@ -220,7 +218,8 @@ def calculate_order_amount(tickets, discount_code): | |||
price = ticket_info.get('price') | |||
if not price or price > ticket.max_price or price < ticket.min_price: | |||
raise UnprocessableEntity( | |||
{'source': 'data/tickets'}, "Price for donation ticket invalid" | |||
{'pointer': 'tickets/price'}, f"Price for donation ticket should be present and within range " |
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 (114 > 90 characters)
app/api/helpers/order.py
Outdated
ticket = safe_query_without_soft_deleted_entries( | ||
db, Ticket, 'id', ticket_identifier, 'id' | ||
) | ||
if not event: | ||
event = ticket.event | ||
fees = TicketFees.query.filter_by(currency=event.payment_currency).first() | ||
elif ticket.event.id != event.id: | ||
raise UnprocessableEntity({'source': 'data/tickets'}, "Invalid Ticket") | ||
raise UnprocessableEntity({'pointer': 'tickets'}, "All tickets must belong to same event") |
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 (102 > 90 characters)
app/api/helpers/order.py
Outdated
ticket = safe_query_without_soft_deleted_entries( | ||
db, Ticket, 'id', ticket_identifier, 'id' | ||
) | ||
if not event: | ||
event = ticket.event | ||
|
||
if event.deleted_at: | ||
raise ObjectNotFound({'pointer': 'tickets/event'}, f'Event: {event.id} not 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.
line too long (98 > 90 characters)
ticket_b = TicketSubFactory(price=495.8, event=ticket_a.event) | ||
ticket_c = TicketSubFactory(price=321.3, event=ticket_a.event) | ||
|
||
discount = DiscountCodeTicketSubFactory(type='percent', value=50.0, tickets=[ticket_a, ticket_b]) |
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 (101 > 90 characters)
|
||
def test_discount_code(db): | ||
ticket = TicketSubFactory(price=100.0) | ||
discount_code = DiscountCodeTicketSubFactory(type='percent', value=10.0, tickets=[ticket]) |
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 (94 > 90 characters)
6fd3df9
to
85c5e57
Compare
@@ -27,15 +27,15 @@ def test_safe_query(self): | |||
with self.app.test_request_context(): | |||
event = EventFactoryBasic() | |||
save_to_db(event) | |||
obj = safe_query(db, Event, 'id', event.id, 'event_id') | |||
obj = safe_query(Event, 'id', event.id, 'event_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.
a09e6de
to
419cd21
Compare
419cd21
to
ff3df8b
Compare
This pull request introduces 2 alerts and fixes 1 when merging ff3df8b into 09049eb - view on LGTM.com new alerts:
fixed alerts:
|
ff3df8b
to
fad1de4
Compare
|
||
event = EventFactoryBasic() | ||
save_to_db(event) | ||
obj = safe_query(Event, 'id', event.id, 'event_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.
Complexity increasing per file
==============================
- tests/all/integration/api/helpers/order/test_calculate_order_amount.py 19
- app/api/helpers/order.py 1
- tests/all/integration/api/helpers/test_db.py 3
Clones added
============
- tests/all/integration/api/helpers/order/test_calculate_order_amount.py 4
Clones removed
==============
+ app/api/user_emails.py -1
+ app/api/email_notifications.py -1
See the complete overview on Codacy |
This pull request introduces 1 alert and fixes 1 when merging fad1de4 into 9e8c40a - view on LGTM.com new alerts:
fixed alerts:
|
Fixes #6999