add title filter tests for API

This commit is contained in:
Joshua Taillon
2023-03-18 12:57:44 -06:00
parent cbc44841d4
commit 24c08c34fb
2 changed files with 88 additions and 0 deletions

View File

@ -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,