Skip to content

Commit

Permalink
test: Re-enable discount code creation test (#7012)
Browse files Browse the repository at this point in the history
  • Loading branch information
iamareebjamal authored May 15, 2020
1 parent 61a6cf0 commit 1831bab
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 29 deletions.
4 changes: 4 additions & 0 deletions app/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
def create_app():
from .instance import app

return app
2 changes: 1 addition & 1 deletion app/api/discount_codes.py
Original file line number Diff line number Diff line change
Expand Up @@ -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':
Expand Down
18 changes: 6 additions & 12 deletions docs/api/blueprint/discount_codes.apib
Original file line number Diff line number Diff line change
Expand Up @@ -167,16 +167,10 @@ 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"
}
}
},
Expand Down Expand Up @@ -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)
Expand All @@ -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",
Expand Down Expand Up @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions dredd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ dry-run: null
hookfiles: ./tests/hook_main.py
language: python
sandbox: false
server: python manage.py runserver
server: env APP_CONFIG=config.TestingConfig python manage.py runserver -p 5555
server-wait: 2
init: false
custom:
Expand Down Expand Up @@ -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'
endpoint: 'http://localhost:5555'
21 changes: 7 additions & 14 deletions tests/hook_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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():
Expand Down Expand Up @@ -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(
Expand All @@ -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(
Expand Down

0 comments on commit 1831bab

Please sign in to comment.