add title filter tests for API
This commit is contained in:
parent
cbc44841d4
commit
24c08c34fb
@ -116,6 +116,7 @@ def seven_workouts_user_1() -> List[Workout]:
|
||||
distance=5,
|
||||
duration=datetime.timedelta(seconds=1024),
|
||||
)
|
||||
workout_1.title = "Workout 1 of 7"
|
||||
update_workout(workout_1)
|
||||
workout_1.ascent = 120
|
||||
workout_1.descent = 200
|
||||
@ -130,6 +131,7 @@ def seven_workouts_user_1() -> List[Workout]:
|
||||
distance=10,
|
||||
duration=datetime.timedelta(seconds=3456),
|
||||
)
|
||||
workout_2.title = "Workout 2 of 7"
|
||||
update_workout(workout_2)
|
||||
workout_2.ascent = 100
|
||||
workout_2.descent = 80
|
||||
@ -144,6 +146,7 @@ def seven_workouts_user_1() -> List[Workout]:
|
||||
distance=10,
|
||||
duration=datetime.timedelta(seconds=1024),
|
||||
)
|
||||
workout_3.title = "Workout 3 of 7"
|
||||
update_workout(workout_3)
|
||||
workout_3.ascent = 80
|
||||
workout_3.descent = 100
|
||||
@ -160,6 +163,7 @@ def seven_workouts_user_1() -> List[Workout]:
|
||||
distance=1,
|
||||
duration=datetime.timedelta(seconds=600),
|
||||
)
|
||||
workout_4.title = "Workout 4 of 7"
|
||||
update_workout(workout_4)
|
||||
workout_4.ascent = 120
|
||||
workout_4.descent = 180
|
||||
@ -174,6 +178,7 @@ def seven_workouts_user_1() -> List[Workout]:
|
||||
distance=10,
|
||||
duration=datetime.timedelta(seconds=1000),
|
||||
)
|
||||
workout_5.title = "Workout 5 of 7"
|
||||
update_workout(workout_5)
|
||||
workout_5.ascent = 100
|
||||
workout_5.descent = 200
|
||||
@ -188,6 +193,7 @@ def seven_workouts_user_1() -> List[Workout]:
|
||||
distance=8,
|
||||
duration=datetime.timedelta(seconds=6000),
|
||||
)
|
||||
workout_6.title = "Workout 6 of 7"
|
||||
update_workout(workout_6)
|
||||
workout_6.ascent = 40
|
||||
workout_6.descent = 20
|
||||
@ -202,6 +208,7 @@ def seven_workouts_user_1() -> List[Workout]:
|
||||
distance=10,
|
||||
duration=datetime.timedelta(seconds=3000),
|
||||
)
|
||||
workout_7.title = "Workout 7 of 7"
|
||||
update_workout(workout_7)
|
||||
db.session.add(workout_7)
|
||||
db.session.commit()
|
||||
|
@ -950,6 +950,55 @@ class TestGetWorkoutsWithFilters(ApiTestCaseMixin):
|
||||
'total': 1,
|
||||
}
|
||||
|
||||
def test_it_gets_one_workout_with_title_filter(
|
||||
self,
|
||||
app: Flask,
|
||||
user_1: User,
|
||||
sport_1_cycling: Sport,
|
||||
seven_workouts_user_1: List[Workout],
|
||||
) -> None:
|
||||
client, auth_token = self.get_test_client_and_auth_token(
|
||||
app, user_1.email
|
||||
)
|
||||
|
||||
response = client.get(
|
||||
'/api/workouts?title=3 of 7',
|
||||
headers=dict(Authorization=f'Bearer {auth_token}'),
|
||||
)
|
||||
|
||||
data = json.loads(response.data.decode())
|
||||
assert response.status_code == 200
|
||||
assert 'success' in data['status']
|
||||
workouts = data['data']['workouts']
|
||||
assert len(workouts) == 1
|
||||
assert 'Workout 3 of 7' == workouts[0]['title']
|
||||
assert (
|
||||
'Mon, 01 Jan 2018 00:00:00 GMT'
|
||||
== workouts[0]['workout_date']
|
||||
)
|
||||
|
||||
def test_it_gets_no_workouts_with_title_filter(
|
||||
self,
|
||||
app: Flask,
|
||||
user_1: User,
|
||||
sport_1_cycling: Sport,
|
||||
seven_workouts_user_1: List[Workout],
|
||||
) -> None:
|
||||
client, auth_token = self.get_test_client_and_auth_token(
|
||||
app, user_1.email
|
||||
)
|
||||
|
||||
response = client.get(
|
||||
'/api/workouts?title=no_such_title',
|
||||
headers=dict(Authorization=f'Bearer {auth_token}'),
|
||||
)
|
||||
|
||||
data = json.loads(response.data.decode())
|
||||
assert response.status_code == 200
|
||||
assert 'success' in data['status']
|
||||
workouts = data['data']['workouts']
|
||||
assert len(workouts) == 0
|
||||
|
||||
|
||||
class TestGetWorkoutsWithFiltersAndPagination(ApiTestCaseMixin):
|
||||
def test_it_gets_page_2_with_date_filter(
|
||||
@ -1025,6 +1074,38 @@ class TestGetWorkoutsWithFiltersAndPagination(ApiTestCaseMixin):
|
||||
}
|
||||
|
||||
|
||||
def test_it_gets_all_workouts_with_title_filter(
|
||||
self,
|
||||
app: Flask,
|
||||
user_1: User,
|
||||
sport_1_cycling: Sport,
|
||||
seven_workouts_user_1: List[Workout],
|
||||
) -> None:
|
||||
client, auth_token = self.get_test_client_and_auth_token(
|
||||
app, user_1.email
|
||||
)
|
||||
|
||||
response = client.get(
|
||||
'/api/workouts?title=of 7',
|
||||
headers=dict(Authorization=f'Bearer {auth_token}'),
|
||||
)
|
||||
|
||||
data = json.loads(response.data.decode())
|
||||
assert response.status_code == 200
|
||||
assert 'success' in data['status']
|
||||
assert len(data['data']['workouts']) == 5
|
||||
assert (
|
||||
'Wed, 09 May 2018 00:00:00 GMT'
|
||||
== data['data']['workouts'][0]['workout_date']
|
||||
)
|
||||
assert data['pagination'] == {
|
||||
'has_next': True,
|
||||
'has_prev': False,
|
||||
'page': 1,
|
||||
'pages': 2,
|
||||
'total': 7,
|
||||
}
|
||||
|
||||
class TestGetWorkout(ApiTestCaseMixin):
|
||||
def test_it_gets_a_workout(
|
||||
self,
|
||||
|
Loading…
Reference in New Issue
Block a user