API - fix max workouts per page in order to display up to 100 workouts
This commit is contained in:
parent
b72959338a
commit
d27385b24d
@ -249,7 +249,7 @@
|
|||||||
<dd class="field-even"><ul class="simple">
|
<dd class="field-even"><ul class="simple">
|
||||||
<li><p><strong>page</strong> (<em>integer</em>) – page if using pagination (default: 1)</p></li>
|
<li><p><strong>page</strong> (<em>integer</em>) – page if using pagination (default: 1)</p></li>
|
||||||
<li><p><strong>per_page</strong> (<em>integer</em>) – number of workouts per page
|
<li><p><strong>per_page</strong> (<em>integer</em>) – number of workouts per page
|
||||||
(default: 5, max: 50)</p></li>
|
(default: 5, max: 100)</p></li>
|
||||||
<li><p><strong>sport_id</strong> (<em>integer</em>) – sport id</p></li>
|
<li><p><strong>sport_id</strong> (<em>integer</em>) – sport id</p></li>
|
||||||
<li><p><strong>from</strong> (<em>string</em>) – start date (format: <code class="docutils literal notranslate"><span class="pre">%Y-%m-%d</span></code>)</p></li>
|
<li><p><strong>from</strong> (<em>string</em>) – start date (format: <code class="docutils literal notranslate"><span class="pre">%Y-%m-%d</span></code>)</p></li>
|
||||||
<li><p><strong>to</strong> (<em>string</em>) – end date (format: <code class="docutils literal notranslate"><span class="pre">%Y-%m-%d</span></code>)</p></li>
|
<li><p><strong>to</strong> (<em>string</em>) – end date (format: <code class="docutils literal notranslate"><span class="pre">%Y-%m-%d</span></code>)</p></li>
|
||||||
|
File diff suppressed because one or more lines are too long
@ -1,4 +1,5 @@
|
|||||||
import json
|
import json
|
||||||
|
from unittest.mock import patch
|
||||||
from uuid import uuid4
|
from uuid import uuid4
|
||||||
|
|
||||||
from flask import Flask
|
from flask import Flask
|
||||||
@ -278,7 +279,8 @@ class TestGetWorkoutsWithPagination:
|
|||||||
in data['message']
|
in data['message']
|
||||||
)
|
)
|
||||||
|
|
||||||
def test_it_gets_5_workouts_per_page(
|
@patch('fittrackee.workouts.workouts.MAX_WORKOUTS_PER_PAGE', 6)
|
||||||
|
def test_it_gets_max_workouts_per_page_if_per_page_exceeds_max(
|
||||||
self,
|
self,
|
||||||
app: Flask,
|
app: Flask,
|
||||||
user_1: User,
|
user_1: User,
|
||||||
@ -303,17 +305,18 @@ class TestGetWorkoutsWithPagination:
|
|||||||
data = json.loads(response.data.decode())
|
data = json.loads(response.data.decode())
|
||||||
assert response.status_code == 200
|
assert response.status_code == 200
|
||||||
assert 'success' in data['status']
|
assert 'success' in data['status']
|
||||||
assert len(data['data']['workouts']) == 7
|
assert len(data['data']['workouts']) == 6
|
||||||
assert (
|
assert (
|
||||||
'Wed, 09 May 2018 00:00:00 GMT'
|
'Wed, 09 May 2018 00:00:00 GMT'
|
||||||
== data['data']['workouts'][0]['workout_date']
|
== data['data']['workouts'][0]['workout_date']
|
||||||
)
|
)
|
||||||
assert (
|
assert (
|
||||||
'Mon, 20 Mar 2017 00:00:00 GMT'
|
'Thu, 01 Jun 2017 00:00:00 GMT'
|
||||||
== data['data']['workouts'][6]['workout_date']
|
== data['data']['workouts'][5]['workout_date']
|
||||||
)
|
)
|
||||||
|
|
||||||
def test_it_gets_3_workouts_per_page(
|
@patch('fittrackee.workouts.workouts.MAX_WORKOUTS_PER_PAGE', 6)
|
||||||
|
def test_it_gets_given_number_of_workouts_per_page(
|
||||||
self,
|
self,
|
||||||
app: Flask,
|
app: Flask,
|
||||||
user_1: User,
|
user_1: User,
|
||||||
|
@ -44,7 +44,8 @@ from .utils_id import decode_short_id
|
|||||||
|
|
||||||
workouts_blueprint = Blueprint('workouts', __name__)
|
workouts_blueprint = Blueprint('workouts', __name__)
|
||||||
|
|
||||||
WORKOUTS_PER_PAGE = 5
|
DEFAULT_WORKOUTS_PER_PAGE = 5
|
||||||
|
MAX_WORKOUTS_PER_PAGE = 100
|
||||||
|
|
||||||
|
|
||||||
@workouts_blueprint.route('/workouts', methods=['GET'])
|
@workouts_blueprint.route('/workouts', methods=['GET'])
|
||||||
@ -168,7 +169,7 @@ def get_workouts(auth_user_id: int) -> Union[Dict, HttpResponse]:
|
|||||||
|
|
||||||
:query integer page: page if using pagination (default: 1)
|
:query integer page: page if using pagination (default: 1)
|
||||||
:query integer per_page: number of workouts per page
|
:query integer per_page: number of workouts per page
|
||||||
(default: 5, max: 50)
|
(default: 5, max: 100)
|
||||||
:query integer sport_id: sport id
|
:query integer sport_id: sport id
|
||||||
:query string from: start date (format: ``%Y-%m-%d``)
|
:query string from: start date (format: ``%Y-%m-%d``)
|
||||||
:query string to: end date (format: ``%Y-%m-%d``)
|
:query string to: end date (format: ``%Y-%m-%d``)
|
||||||
@ -219,10 +220,10 @@ def get_workouts(auth_user_id: int) -> Union[Dict, HttpResponse]:
|
|||||||
per_page = (
|
per_page = (
|
||||||
int(params.get('per_page'))
|
int(params.get('per_page'))
|
||||||
if params.get('per_page')
|
if params.get('per_page')
|
||||||
else WORKOUTS_PER_PAGE
|
else DEFAULT_WORKOUTS_PER_PAGE
|
||||||
)
|
)
|
||||||
if per_page > 50:
|
if per_page > MAX_WORKOUTS_PER_PAGE:
|
||||||
per_page = 50
|
per_page = MAX_WORKOUTS_PER_PAGE
|
||||||
workouts = (
|
workouts = (
|
||||||
Workout.query.filter(
|
Workout.query.filter(
|
||||||
Workout.user_id == auth_user_id,
|
Workout.user_id == auth_user_id,
|
||||||
|
Loading…
Reference in New Issue
Block a user