From b872fe25fc59d4b6d366ef141103a13d5d565d14 Mon Sep 17 00:00:00 2001 From: maitris Date: Sat, 12 Sep 2020 17:33:42 +0530 Subject: [PATCH] chore: Enable dredd tests for some of the Orders API endpoints (#7261) --- app/api/custom/orders.py | 2 +- docs/api/blueprint/order/orders.apib | 202 ++++++++++----------------- tests/hook_main.py | 52 +++++-- 3 files changed, 115 insertions(+), 141 deletions(-) diff --git a/app/api/custom/orders.py b/app/api/custom/orders.py index 737f91c408..e4b57e7ba6 100644 --- a/app/api/custom/orders.py +++ b/app/api/custom/orders.py @@ -167,7 +167,7 @@ def create_order(): db.session.commit() order.populate_and_save() - return OrderSchema().dumps(order) + return OrderSchema().dump(order) @order_blueprint.route('/complete-order/', methods=['PATCH']) diff --git a/docs/api/blueprint/order/orders.apib b/docs/api/blueprint/order/orders.apib index 049d17b973..bfc52e74a5 100644 --- a/docs/api/blueprint/order/orders.apib +++ b/docs/api/blueprint/order/orders.apib @@ -50,167 +50,113 @@ Get a list of all orders } } +## Create Order [/v1/orders/create-order] + ### Create Order [POST] Create a new Order -+ Request (application/vnd.api+json) ++ Request (application/json) + Headers + Accept: application/json + Authorization: JWT + Body - { - "data": { - "attributes": { - "payment-mode": "paypal", - "country": "India", - "status": "pending", - "amount": "10", - "order-notes": "example" - }, - "type": "order", - "relationships": { - "attendees": { - "data": [ - { - "id": "1", - "type": "attendee" - } - ] - }, - "event": { - "data": { - "id": "1", - "type": "event" - } - } - } - } - } -+ Response 201 (application/vnd.api+json) + { + "tickets": [ + {"id": 1, "quantity": 2}, + {"id": 2, "quantity": 4}, + {"id": 3, "quantity": 3, "price": 789.7}, + {"id": 4, "quantity": 3} + ], + "discount_code": "1" + } + ++ Response 200 (application/json) { - "included": [ - { - "relationships": { - "ticket": { - "links": { - "self": "/v1/attendees/1/relationships/ticket", - "related": "/v1/attendees/1/ticket" - } - }, - "event": { - "links": { - "self": "/v1/attendees/1/relationships/event", - "related": "/v1/attendees/1/event" - } - } - }, - "attributes": { - "city": null, - "firstname": "Open Event User", - "lastname": null, - "ticket-id": "1", - "is-checked-in": false, - "checkin-times": null, - "is-checked-out": null, - "checkout-times": null, - "state": null, - "address": null, - "pdf-url": "http://example.com", - "country": null, - "email": null, - "created-at": "2018-07-08T01:05:09.904696+00:00", - "order-notes": "example" - }, - "type": "attendee", - "id": "1", - "links": { - "self": "/v1/attendees/1" - } - } - ], "data": { + "type": "order", + "attributes": { + "completed-at": null, + "paid-via": null, + "exp-year": null, + "discount-code-id": "1", + "status": "initializing", + "deleted-at": null, + "exp-month": null, + "country": null, + "is-billing-enabled": false, + "transaction-id": null, + "order-notes": null, + "tickets-pdf-url": null, + "payment-mode": null, + "city": null, + "tax-business-info": null, + "amount": 4745.81, + "identifier": "300d7722-7005-4776-89d7-037cc7ceec0d", + "brand": null, + "created-at": "2020-09-11T12:11:24.169351+00:00", + "zipcode": null, + "company": null, + "last4": null, + "state": null, + "cancel-note": null, + "address": null + }, + "id": "1", "relationships": { "tickets": { "links": { - "self": "/v1/orders/617ed24c-9a07-4084-b076-ed73552db27e/relationships/ticket", - "related": "/v1/orders/11/tickets" + "self": "/v1/orders/300d7722-7005-4776-89d7-037cc7ceec0d/relationships/ticket", + "related": "/v1/orders/300d7722-7005-4776-89d7-037cc7ceec0d/tickets" } }, - "attendees": { - "data": [ - { - "type": "attendee", - "id": "1" - } - ], + "user": { "links": { - "self": "/v1/orders/617ed24c-9a07-4084-b076-ed73552db27e/relationships/attendee", - "related": "/v1/orders/11/attendees" + "self": "/v1/orders/300d7722-7005-4776-89d7-037cc7ceec0d/relationships/user", + "related": "/v1/users/1" } }, - "marketer": { + "discount-code": { "links": { - "self": "/v1/orders/617ed24c-9a07-4084-b076-ed73552db27e/relationships/marketer" + "self": "/v1/orders/300d7722-7005-4776-89d7-037cc7ceec0d/relationships/discount-code", + "related": "/v1/discount-codes/1" } }, - "user": { + "attendees": { "links": { - "self": "/v1/orders/617ed24c-9a07-4084-b076-ed73552db27e/relationships/user" + "self": "/v1/orders/300d7722-7005-4776-89d7-037cc7ceec0d/relationships/attendee", + "related": "/v1/orders/300d7722-7005-4776-89d7-037cc7ceec0d/attendees" } }, - "discount-code": { + "event": { "links": { - "self": "/v1/orders/617ed24c-9a07-4084-b076-ed73552db27e/relationships/discount-code" + "self": "/v1/orders/300d7722-7005-4776-89d7-037cc7ceec0d/relationships/event", + "related": "/v1/events/1" } }, - "event": { + "event-invoice": { "links": { - "self": "/v1/orders/617ed24c-9a07-4084-b076-ed73552db27e/relationships/event", - "related": "/v1/events/1" + "self": "/v1/orders/300d7722-7005-4776-89d7-037cc7ceec0d/relationships/event-invoice/", + "related": "/v1/event-invoices/1" + } + }, + "marketer": { + "links": { + "self": "/v1/orders/300d7722-7005-4776-89d7-037cc7ceec0d/relationships/marketer" } } }, - "attributes": { - "status": "pending", - "city": null, - "identifier": "617ed24c-9a07-4084-b076-ed73552db27e", - "paid-via": null, - "exp-year": null, - "transaction-id": null, - "discount-code-id": null, - "brand": null, - "zipcode": null, - "company": null, - "tax-business-info": null, - "is-billing-enabled": false, - "payment-mode": "paypal", - "last4": null, - "state": null, - "payment-url": "https://www.sandbox.paypal.com/cgi-bin/webscr?token=EC-62113287PK247472B&cmd=_express-checkout", - "address": null, - "exp-month": null, - "amount": 10.0, - "country": "India", - "completed-at": null, - "created-at": "2018-07-08T01:05:09.904696+00:00", - "order-notes": "example", - "tickets-pdf-url": "https://example.com/media/attendees/tickets/pdf/order_identifier.pdf" - }, - "type": "order", - "id": "11", "links": { - "self": "/v1/orders/1" + "self": "/v1/orders/300d7722-7005-4776-89d7-037cc7ceec0d" } }, - "jsonapi": { - "version": "1.0" - }, "links": { - "self": "/v1/orders/11" + "self": "/v1/orders/300d7722-7005-4776-89d7-037cc7ceec0d" } } @@ -281,8 +227,7 @@ Get a single Order detail. "company": null, "tax-business-info": null, "is-billing-enabled": false, - "payment-mode": "paypal", - "payment-url": "https://www.sandbox.paypal.com/cgi-bin/webscr?token=EC-62113287PK247472B&cmd=_express-checkout", + "payment-mode": "free", "last4": null, "state": null, "address": null, @@ -307,8 +252,6 @@ Get a single Order detail. "self": "/v1/orders/ab25a170-f36d-4dd6-b99c-9c202e693afc" } } - - ### Update Order [PATCH] Update a single custom form with `id`. @@ -325,7 +268,7 @@ Update a single custom form with `id`. { "data": { "attributes": { - "status": "confirmed", + "payment-mode": "paypal", "order-notes": "example" }, "type": "order", @@ -387,7 +330,6 @@ Update a single custom form with `id`. "tax-business-info": null, "is-billing-enabled": false, "payment-mode": "paypal", - "payment-url": "https://www.sandbox.paypal.com/cgi-bin/webscr?token=EC-62113287PK247472B&cmd=_express-checkout", "last4": null, "state": null, "address": null, @@ -549,7 +491,7 @@ Create a new Order with on site attendees "payment-mode": "free", "last4": null, "state": null, - "payment-url": "https://www.sandbox.paypal.com/cgi-bin/webscr?token=EC-62113287PK247472B&cmd=_express-checkout", + "payment-url": "https://www.sandbox.paypal.com/cgi-bin/webscr?token=EC-62113287PK247472B&cmd=_express-checkout", "address": null, "exp-month": null, "amount": null, diff --git a/tests/hook_main.py b/tests/hook_main.py index abe7b71f8a..0b1b0b6f85 100644 --- a/tests/hook_main.py +++ b/tests/hook_main.py @@ -33,7 +33,11 @@ from tests.factories.event_copyright import EventCopyrightFactory from tests.factories.setting import SettingFactory from tests.factories.event_type import EventTypeFactory -from tests.factories.discount_code import DiscountCodeFactory, DiscountCodeTicketFactory +from tests.factories.discount_code import ( + DiscountCodeFactory, + DiscountCodeTicketFactory, + DiscountCodeTicketSubFactory, +) from tests.factories.access_code import AccessCodeFactory from tests.factories.custom_form import CustomFormFactory from tests.factories.faq import FaqFactory @@ -68,6 +72,10 @@ from tests.factories.message_setting import MessageSettingsFactory from tests.factories.user_favourite_events import UserFavouriteEventFactory +from tests.all.integration.api.helpers.order.test_calculate_order_amount import ( + _create_taxed_tickets, +) + stash = {} api_username = "open_event_test_user@fossasia.org" @@ -4201,17 +4209,27 @@ def orders_get_collection(transaction): :param transaction: :return: """ - transaction['skip'] = True + with stash['app'].app_context(): + order = OrderFactory() + db.session.add(order) + db.session.commit() -@hooks.before("Orders > Orders Collection > Create Order") +@hooks.before("Orders > Create Order > Create Order") def create_order(transaction): """ - GET /orders + POST /orders/create-order :param transaction: :return: """ - transaction['skip'] = True + with stash['app'].app_context(): + discount_code = DiscountCodeTicketSubFactory( + type='percent', value=10.0, tickets=[] + ) + tickets_dict = _create_taxed_tickets( + db, tax_included=False, discount_code=discount_code + ) + db.session.commit() @hooks.before( @@ -4219,7 +4237,7 @@ def create_order(transaction): ) def create_order_with_on_site_attendee(transaction): """ - GET /orders?onsite=true + POST /orders?onsite=true :param transaction: :return: """ @@ -4233,7 +4251,10 @@ def order_detail(transaction): :param transaction: :return: """ - transaction['skip'] = True + with stash['app'].app_context(): + order = OrderFactory() + db.session.add(order) + db.session.commit() @hooks.before("Orders > Order Detail > Update Order") @@ -4243,7 +4264,10 @@ def update_order(transaction): :param transaction: :return: """ - transaction['skip'] = True + with stash['app'].app_context(): + order = OrderFactory() + db.session.add(order) + db.session.commit() @hooks.before("Orders > Order Detail > Delete Order") @@ -4253,7 +4277,10 @@ def delete_order(transaction): :param transaction: :return: """ - transaction['skip'] = True + with stash['app'].app_context(): + order = OrderFactory() + db.session.add(order) + db.session.commit() @hooks.before("Orders > Orders under an Event > List all Orders under an Event") @@ -4263,7 +4290,12 @@ def event_order_get_list(transaction): :param transaction: :return: """ - transaction['skip'] = True + with stash['app'].app_context(): + event = EventFactoryBasic() + order = OrderFactory(event_id=event.id) + db.session.add(event) + db.session.add(order) + db.session.commit() @hooks.before("Orders > Charge > Charge for an Order")