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: Fix and test calculate_order_amount #6997

Merged
merged 5 commits into from
May 14, 2020

Conversation

iamareebjamal
Copy link
Member

@iamareebjamal iamareebjamal commented May 13, 2020

Fixes #6999

@auto-label auto-label bot added the testing label May 13, 2020


def _create_ticket_dict(tickets, quantities):
return [dict(id=ticket.id, quantity=quantity) for ticket, quantity in zip(tickets, quantities)]

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

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

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(

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

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
Copy link

codecov bot commented May 13, 2020

Codecov Report

Merging #6997 into development will increase coverage by 0.48%.
The diff coverage is 22.81%.

Impacted file tree graph

@@               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     
Impacted Files Coverage Δ
app/api/access_codes.py 51.21% <0.00%> (ø)
app/api/attendees.py 41.17% <0.00%> (ø)
app/api/custom_forms.py 70.83% <0.00%> (ø)
app/api/custom_placeholders.py 53.06% <ø> (ø)
app/api/custom_system_roles.py 67.74% <0.00%> (ø)
app/api/data_layers/EventCopyLayer.py 20.22% <ø> (ø)
app/api/discount_codes.py 22.27% <0.00%> (ø)
app/api/email_notifications.py 86.84% <0.00%> (ø)
app/api/event_copy.py 28.57% <0.00%> (ø)
app/api/event_copyright.py 63.63% <0.00%> (ø)
... and 37 more

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 09049eb...fad1de4. Read the comment docs.

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.



def _expect_donation_error(ticket_dict):
with pytest.raises(UnprocessableEntity, match='Price for donation ticket should be present and within range '

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

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

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

Choose a reason for hiding this comment

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

Black would make changes.

@@ -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}"

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)

@@ -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 "

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)

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

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)

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

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

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

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)

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

Choose a reason for hiding this comment

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

Black would make changes.

@lgtm-com
Copy link
Contributor

lgtm-com bot commented May 13, 2020

This pull request introduces 2 alerts and fixes 1 when merging ff3df8b into 09049eb - view on LGTM.com

new alerts:

  • 2 for Unused import

fixed alerts:

  • 1 for Testing equality to None


event = EventFactoryBasic()
save_to_db(event)
obj = safe_query(Event, 'id', event.id, 'event_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.

@niranjan94
Copy link
Member

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

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

@iamareebjamal iamareebjamal merged commit eeaa8b9 into fossasia:development May 14, 2020
@iamareebjamal iamareebjamal deleted the test/order-amount branch May 14, 2020 06:48
@lgtm-com
Copy link
Contributor

lgtm-com bot commented May 14, 2020

This pull request introduces 1 alert and fixes 1 when merging fad1de4 into 9e8c40a - view on LGTM.com

new alerts:

  • 1 for Unused import

fixed alerts:

  • 1 for Testing equality to None

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add more tests for order amount and creation
3 participants