2021-01-02 19:28:03 +01:00
|
|
|
from typing import Dict, Optional
|
|
|
|
|
|
|
|
from fittrackee.users.models import User
|
2021-01-10 11:16:43 +01:00
|
|
|
from fittrackee.workouts.models import Sport, Workout
|
2021-01-02 19:28:03 +01:00
|
|
|
from flask import Flask
|
|
|
|
|
|
|
|
|
2020-05-10 15:55:56 +02:00
|
|
|
class TestSportModel:
|
|
|
|
@staticmethod
|
2021-01-02 19:28:03 +01:00
|
|
|
def assert_sport_model(
|
|
|
|
sport: Sport, is_admin: Optional[bool] = False
|
|
|
|
) -> Dict:
|
2020-05-10 15:55:56 +02:00
|
|
|
assert 1 == sport.id
|
|
|
|
assert 'Cycling' == sport.label
|
|
|
|
assert '<Sport \'Cycling\'>' == str(sport)
|
2018-05-12 19:13:59 +02:00
|
|
|
|
2020-05-10 15:55:56 +02:00
|
|
|
serialized_sport = sport.serialize(is_admin)
|
|
|
|
assert 1 == serialized_sport['id']
|
|
|
|
assert 'Cycling' == serialized_sport['label']
|
|
|
|
assert serialized_sport['is_active'] is True
|
|
|
|
return serialized_sport
|
2019-09-23 14:09:26 +02:00
|
|
|
|
2021-01-02 19:28:03 +01:00
|
|
|
def test_sport_model(self, app: Flask, sport_1_cycling: Sport) -> None:
|
2020-05-10 15:55:56 +02:00
|
|
|
serialized_sport = self.assert_sport_model(sport_1_cycling)
|
2021-01-10 11:16:43 +01:00
|
|
|
assert 'has_workouts' not in serialized_sport
|
2019-09-23 14:09:26 +02:00
|
|
|
|
2021-01-10 11:16:43 +01:00
|
|
|
def test_sport_model_with_workout(
|
2021-01-02 19:28:03 +01:00
|
|
|
self,
|
|
|
|
app: Flask,
|
|
|
|
sport_1_cycling: Sport,
|
|
|
|
user_1: User,
|
2021-01-10 11:16:43 +01:00
|
|
|
workout_cycling_user_1: Workout,
|
2021-01-02 19:28:03 +01:00
|
|
|
) -> None:
|
2020-05-10 15:55:56 +02:00
|
|
|
serialized_sport = self.assert_sport_model(sport_1_cycling)
|
2021-01-10 11:16:43 +01:00
|
|
|
assert 'has_workouts' not in serialized_sport
|
2018-05-12 19:13:59 +02:00
|
|
|
|
2021-01-10 11:16:43 +01:00
|
|
|
def test_sport_model_with_workout_as_admin(
|
2021-01-02 19:28:03 +01:00
|
|
|
self,
|
|
|
|
app: Flask,
|
|
|
|
sport_1_cycling: Sport,
|
|
|
|
user_1: User,
|
2021-01-10 11:16:43 +01:00
|
|
|
workout_cycling_user_1: Workout,
|
2021-01-02 19:28:03 +01:00
|
|
|
) -> None:
|
2020-05-10 15:55:56 +02:00
|
|
|
serialized_sport = self.assert_sport_model(sport_1_cycling, True)
|
2021-01-10 11:16:43 +01:00
|
|
|
assert serialized_sport['has_workouts'] is True
|