FitTrackee/fittrackee/tests/activities/test_sports_model.py

46 lines
1.5 KiB
Python
Raw Normal View History

2021-01-02 19:28:03 +01:00
from typing import Dict, Optional
from fittrackee.activities.models import Activity, Sport
from fittrackee.users.models import User
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
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)
assert 'has_activities' not in serialized_sport
2020-05-10 15:55:56 +02:00
def test_sport_model_with_activity(
2021-01-02 19:28:03 +01:00
self,
app: Flask,
sport_1_cycling: Sport,
user_1: User,
activity_cycling_user_1: Activity,
) -> None:
2020-05-10 15:55:56 +02:00
serialized_sport = self.assert_sport_model(sport_1_cycling)
assert 'has_activities' not in serialized_sport
2018-05-12 19:13:59 +02:00
2020-05-10 15:55:56 +02:00
def test_sport_model_with_activity_as_admin(
2021-01-02 19:28:03 +01:00
self,
app: Flask,
sport_1_cycling: Sport,
user_1: User,
activity_cycling_user_1: Activity,
) -> None:
2020-05-10 15:55:56 +02:00
serialized_sport = self.assert_sport_model(sport_1_cycling, True)
assert serialized_sport['has_activities'] is True