Skip to content

Commit

Permalink
fix flask versioning issues
Browse files Browse the repository at this point in the history
  • Loading branch information
AndrewPlayer3 committed Jul 1, 2024
1 parent d92f4ea commit 415d9a6
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 15 deletions.
3 changes: 1 addition & 2 deletions api/src/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
from json import JSONEncoder

from flask import Flask, abort, jsonify
from flask_api.status import HTTP_404_NOT_FOUND
from flask_cors import CORS
from serverless_wsgi import handle_request

Expand Down Expand Up @@ -35,7 +34,7 @@ def get_event_by_id(event_id):
try:
event = database.get_event(event_id)
except ValueError:
abort(HTTP_404_NOT_FOUND)
abort(404)
event['products'] = database.get_products_for_event(event_id, status_code='SUCCEEDED')
return jsonify(event)

Expand Down
4 changes: 1 addition & 3 deletions requirements-api.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
flask==2.3.3
flask_api==3.1
werkzeug==2.3.8
flask==3.0.3
Flask-Cors==4.0.1
serverless_wsgi==3.0.4
./database
18 changes: 8 additions & 10 deletions tests/test_api.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
from datetime import datetime, timedelta, timezone
from decimal import Decimal

from flask_api import status

from api import lambda_handler


Expand Down Expand Up @@ -52,43 +50,43 @@ def seed_data(tables):

def test_events(api_client, tables):
response = api_client.get('/events')
assert response.status_code == status.HTTP_200_OK
assert response.status_code == 200
assert response.get_json() == []

seed_data(tables)

response = api_client.get('/events')
assert response.status_code == status.HTTP_200_OK
assert response.status_code == 200
assert len(response.get_json()) == 2


def test_event_by_id(api_client, tables):
response = api_client.get('/events/event1')
assert response.status_code == status.HTTP_404_NOT_FOUND
assert response.status_code == 404

seed_data(tables)

response = api_client.get('/events/event1')
assert response.status_code == status.HTTP_200_OK
assert response.status_code == 200
assert response.get_json()['event_id'] == 'event1'
assert response.get_json()['products'] == []

response = api_client.get('/events/event2')
assert response.status_code == status.HTTP_200_OK
assert response.status_code == 200
assert response.get_json()['event_id'] == 'event2'
product_ids = [p['product_id'] for p in response.get_json()['products']]
assert sorted(product_ids) == ['product1', 'product3', 'product4']


def test_recent_products(api_client, tables):
response = api_client.get('/recent_products')
assert response.status_code == status.HTTP_200_OK
assert response.status_code == 200
assert response.get_json() == []

seed_data(tables)

response = api_client.get('/recent_products')
assert response.status_code == status.HTTP_200_OK
assert response.status_code == 200
product_ids = [p['product_id'] for p in response.get_json()]
assert sorted(product_ids) == ['product1', 'product3']

Expand All @@ -113,6 +111,6 @@ def test_lambda_handler():
'headers': {},
}
response = lambda_handler(event, None)
assert response['statusCode'] == status.HTTP_404_NOT_FOUND
assert response['statusCode'] == 404
assert response['headers']['Content-Type'] == 'text/html; charset=utf-8'
assert response['isBase64Encoded'] is False

0 comments on commit 415d9a6

Please sign in to comment.