From 068d836622a905da7f9884e9cb6bb8c167cf2b38 Mon Sep 17 00:00:00 2001 From: iamareebjamal Date: Sat, 16 May 2020 00:48:51 +0530 Subject: [PATCH 1/3] chore: Setup dredd as isolated env --- app/__init__.py | 4 ++++ dredd.yml | 4 ++-- tests/hook_main.py | 2 +- 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/app/__init__.py b/app/__init__.py index e69de29bb2..77f9c4d4fc 100644 --- a/app/__init__.py +++ b/app/__init__.py @@ -0,0 +1,4 @@ +def create_app(): + from .instance import app + + return app diff --git a/dredd.yml b/dredd.yml index 7de8b78b37..86ea1878a4 100644 --- a/dredd.yml +++ b/dredd.yml @@ -2,7 +2,7 @@ dry-run: null hookfiles: ./tests/hook_main.py language: python sandbox: false -server: python manage.py runserver +server: APP_CONFIG=config.TestingConfig python manage.py runserver -p 5555 server-wait: 2 init: false custom: @@ -32,4 +32,4 @@ hooks-worker-handler-host: 127.0.0.1 hooks-worker-handler-port: 61321 config: ./dredd.yml blueprint: docs/api/api_blueprint.apib -endpoint: 'http://localhost:5000' \ No newline at end of file +endpoint: 'http://localhost:5555' diff --git a/tests/hook_main.py b/tests/hook_main.py index 73e764678b..5a1e981445 100644 --- a/tests/hook_main.py +++ b/tests/hook_main.py @@ -72,7 +72,7 @@ stash = {} api_username = "open_event_test_user@fossasia.org" api_password = "fossasia" -api_uri = "http://localhost:5000/v1/auth/login" +api_uri = "http://localhost:5555/v1/auth/login" def obtain_token(): From dcfe0b170e34b19bcfce39dda16410836647ed14 Mon Sep 17 00:00:00 2001 From: iamareebjamal Date: Sat, 16 May 2020 01:58:35 +0530 Subject: [PATCH 2/3] fix --- app/api/discount_codes.py | 2 +- docs/api/blueprint/discount_codes.apib | 20 +++++++------------- dredd.yml | 2 +- tests/hook_main.py | 19 ++++++------------- 4 files changed, 15 insertions(+), 28 deletions(-) diff --git a/app/api/discount_codes.py b/app/api/discount_codes.py index 6fae132114..f877c26f02 100644 --- a/app/api/discount_codes.py +++ b/app/api/discount_codes.py @@ -69,7 +69,7 @@ def before_post(self, args, kwargs, data): {'source': ''}, "Please verify your permission or check your relationship" ) - data['user_id'] = current_user.id + data['marketer_id'] = current_user.id def before_create_object(self, data, view_kwargs): if data['used_for'] == 'event': diff --git a/docs/api/blueprint/discount_codes.apib b/docs/api/blueprint/discount_codes.apib index 3b097173a1..cc504b3d3a 100644 --- a/docs/api/blueprint/discount_codes.apib +++ b/docs/api/blueprint/discount_codes.apib @@ -167,18 +167,12 @@ Create a new Discount Code for event. (Only Admin) { "data": { "relationships": { - "events": { - "links": { - "self": "/v1/discount-codes/4/relationships/events", - "related": "/v1/discount-codes/4/events" - } - }, - "tickets": { + "event": { "links": { - "self": "/v1/discount-codes/1/relationships/tickets", - "related": "/v1/discount-codes/1/tickets" + "self": "/v1/discount-codes/1/relationships/event", + "related": "/v1/discount-codes/1/event" } - } + } }, "attributes": { "code": "DC101", @@ -217,7 +211,7 @@ Create a new Discount Code for event. (Only Admin) + sort (optional, string, `code`) - Sort the resources according to the given attribute in ascending order. Append '-' to sort in descending order. + filter (optional, string, `[]`) - Filter according to the flask-rest-jsonapi filtering system. Please refer: http://flask-rest-jsonapi.readthedocs.io/en/latest/filtering.html for more. -### Create Ticket Discount Code [POST /v1/discount-codes{?page%5bsize%5d,page%5bnumber%5d,sort,filter}] +### Create Ticket Discount Code [POST /v1/discount-codes] Create a new Discount Code for event. (Only by Co-organizers) + Request (application/vnd.api+json) @@ -234,7 +228,7 @@ Create a new Discount Code for event. (Only by Co-organizers) "code": "DC101", "discount-url": "https://my-discount-url.com", "value": "100", - "type": "amount", + "type": "percent", "is-active": "false", "tickets-number": "404", "min-quantity": "0", @@ -276,7 +270,7 @@ Create a new Discount Code for event. (Only by Co-organizers) "max-quantity": 100, "valid-till": "2017-06-24T18:30:00+00:00", "is-active": false, - "type": "amount", + "type": "percent", "code": "DC101", "valid-from": "2017-06-18T18:30:00+00:00", "tickets-number": 404, diff --git a/dredd.yml b/dredd.yml index 86ea1878a4..485a7b563a 100644 --- a/dredd.yml +++ b/dredd.yml @@ -2,7 +2,7 @@ dry-run: null hookfiles: ./tests/hook_main.py language: python sandbox: false -server: APP_CONFIG=config.TestingConfig python manage.py runserver -p 5555 +server: env APP_CONFIG=config.TestingConfig python manage.py runserver -p 5555 server-wait: 2 init: false custom: diff --git a/tests/hook_main.py b/tests/hook_main.py index 5a1e981445..5a0be3d95c 100644 --- a/tests/hook_main.py +++ b/tests/hook_main.py @@ -2872,14 +2872,9 @@ def event_discount_code_post(transaction): :param transaction: :return: """ - transaction['skip'] = True - - -# TODO: This is breaking the build, we need to repair it eventually. -# with stash['app'].app_context(): + transaction['skip'] = True -# event = EventFactoryBasic() -# db.session.add(event) -# db.session.commit() + with stash['app'].app_context(): + EventFactoryBasic() + db.session.commit() @hooks.before( @@ -2891,11 +2886,9 @@ def ticket_discount_code_post(transaction): :param transaction: :return: """ - transaction['skip'] = True - # with stash['app'].app_context(): - # event = EventFactoryBasic() - # db.session.add(event) - # db.session.commit() + with stash['app'].app_context(): + TicketFactory() + db.session.commit() @hooks.before( From 37ee313c0745a47d955b98c803802a5baf6e2286 Mon Sep 17 00:00:00 2001 From: Areeb Jamal Date: Sat, 16 May 2020 03:47:16 +0530 Subject: [PATCH 3/3] Update docs/api/blueprint/discount_codes.apib --- docs/api/blueprint/discount_codes.apib | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/api/blueprint/discount_codes.apib b/docs/api/blueprint/discount_codes.apib index cc504b3d3a..e60ed60bf8 100644 --- a/docs/api/blueprint/discount_codes.apib +++ b/docs/api/blueprint/discount_codes.apib @@ -172,7 +172,7 @@ Create a new Discount Code for event. (Only Admin) "self": "/v1/discount-codes/1/relationships/event", "related": "/v1/discount-codes/1/event" } - } + } }, "attributes": { "code": "DC101",