API - add typing
This commit is contained in:
		@@ -1,21 +1,25 @@
 | 
			
		||||
import json
 | 
			
		||||
from uuid import uuid4
 | 
			
		||||
 | 
			
		||||
from fittrackee.activities.models import Activity, Sport
 | 
			
		||||
from fittrackee.users.models import User
 | 
			
		||||
from flask import Flask
 | 
			
		||||
 | 
			
		||||
from .utils import get_random_short_id
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
class TestGetActivities:
 | 
			
		||||
    def test_it_gets_all_activities_for_authenticated_user(
 | 
			
		||||
        self,
 | 
			
		||||
        app,
 | 
			
		||||
        user_1,
 | 
			
		||||
        user_2,
 | 
			
		||||
        sport_1_cycling,
 | 
			
		||||
        sport_2_running,
 | 
			
		||||
        activity_cycling_user_1,
 | 
			
		||||
        activity_cycling_user_2,
 | 
			
		||||
        activity_running_user_1,
 | 
			
		||||
    ):
 | 
			
		||||
        app: Flask,
 | 
			
		||||
        user_1: User,
 | 
			
		||||
        user_2: User,
 | 
			
		||||
        sport_1_cycling: Sport,
 | 
			
		||||
        sport_2_running: Sport,
 | 
			
		||||
        activity_cycling_user_1: Activity,
 | 
			
		||||
        activity_cycling_user_2: Activity,
 | 
			
		||||
        activity_running_user_1: Activity,
 | 
			
		||||
    ) -> None:
 | 
			
		||||
        client = app.test_client()
 | 
			
		||||
        resp_login = client.post(
 | 
			
		||||
            '/api/auth/login',
 | 
			
		||||
@@ -57,14 +61,14 @@ class TestGetActivities:
 | 
			
		||||
 | 
			
		||||
    def test_it_gets_no_activities_for_authenticated_user_with_no_activities(
 | 
			
		||||
        self,
 | 
			
		||||
        app,
 | 
			
		||||
        user_1,
 | 
			
		||||
        user_2,
 | 
			
		||||
        sport_1_cycling,
 | 
			
		||||
        sport_2_running,
 | 
			
		||||
        activity_cycling_user_1,
 | 
			
		||||
        activity_running_user_1,
 | 
			
		||||
    ):
 | 
			
		||||
        app: Flask,
 | 
			
		||||
        user_1: User,
 | 
			
		||||
        user_2: User,
 | 
			
		||||
        sport_1_cycling: Sport,
 | 
			
		||||
        sport_2_running: Sport,
 | 
			
		||||
        activity_cycling_user_1: Activity,
 | 
			
		||||
        activity_running_user_1: Activity,
 | 
			
		||||
    ) -> None:
 | 
			
		||||
        client = app.test_client()
 | 
			
		||||
        resp_login = client.post(
 | 
			
		||||
            '/api/auth/login',
 | 
			
		||||
@@ -85,7 +89,9 @@ class TestGetActivities:
 | 
			
		||||
        assert 'success' in data['status']
 | 
			
		||||
        assert len(data['data']['activities']) == 0
 | 
			
		||||
 | 
			
		||||
    def test_it_returns_401_if_user_is_not_authenticated(self, app):
 | 
			
		||||
    def test_it_returns_401_if_user_is_not_authenticated(
 | 
			
		||||
        self, app: Flask
 | 
			
		||||
    ) -> None:
 | 
			
		||||
        client = app.test_client()
 | 
			
		||||
 | 
			
		||||
        response = client.get('/api/activities')
 | 
			
		||||
@@ -98,8 +104,12 @@ class TestGetActivities:
 | 
			
		||||
 | 
			
		||||
class TestGetActivitiesWithPagination:
 | 
			
		||||
    def test_it_gets_activities_with_default_pagination(
 | 
			
		||||
        self, app, user_1, sport_1_cycling, seven_activities_user_1
 | 
			
		||||
    ):
 | 
			
		||||
        self,
 | 
			
		||||
        app: Flask,
 | 
			
		||||
        user_1: User,
 | 
			
		||||
        sport_1_cycling: Sport,
 | 
			
		||||
        seven_activities_user_1: Activity,
 | 
			
		||||
    ) -> None:
 | 
			
		||||
        client = app.test_client()
 | 
			
		||||
        resp_login = client.post(
 | 
			
		||||
            '/api/auth/login',
 | 
			
		||||
@@ -133,8 +143,12 @@ class TestGetActivitiesWithPagination:
 | 
			
		||||
        assert '0:17:04' == data['data']['activities'][4]['duration']
 | 
			
		||||
 | 
			
		||||
    def test_it_gets_first_page(
 | 
			
		||||
        self, app, user_1, sport_1_cycling, seven_activities_user_1
 | 
			
		||||
    ):
 | 
			
		||||
        self,
 | 
			
		||||
        app: Flask,
 | 
			
		||||
        user_1: User,
 | 
			
		||||
        sport_1_cycling: Sport,
 | 
			
		||||
        seven_activities_user_1: Activity,
 | 
			
		||||
    ) -> None:
 | 
			
		||||
        client = app.test_client()
 | 
			
		||||
        resp_login = client.post(
 | 
			
		||||
            '/api/auth/login',
 | 
			
		||||
@@ -168,8 +182,12 @@ class TestGetActivitiesWithPagination:
 | 
			
		||||
        assert '0:17:04' == data['data']['activities'][4]['duration']
 | 
			
		||||
 | 
			
		||||
    def test_it_gets_second_page(
 | 
			
		||||
        self, app, user_1, sport_1_cycling, seven_activities_user_1
 | 
			
		||||
    ):
 | 
			
		||||
        self,
 | 
			
		||||
        app: Flask,
 | 
			
		||||
        user_1: User,
 | 
			
		||||
        sport_1_cycling: Sport,
 | 
			
		||||
        seven_activities_user_1: Activity,
 | 
			
		||||
    ) -> None:
 | 
			
		||||
        client = app.test_client()
 | 
			
		||||
        resp_login = client.post(
 | 
			
		||||
            '/api/auth/login',
 | 
			
		||||
@@ -203,8 +221,12 @@ class TestGetActivitiesWithPagination:
 | 
			
		||||
        assert '0:17:04' == data['data']['activities'][1]['duration']
 | 
			
		||||
 | 
			
		||||
    def test_it_gets_empty_third_page(
 | 
			
		||||
        self, app, user_1, sport_1_cycling, seven_activities_user_1
 | 
			
		||||
    ):
 | 
			
		||||
        self,
 | 
			
		||||
        app: Flask,
 | 
			
		||||
        user_1: User,
 | 
			
		||||
        sport_1_cycling: Sport,
 | 
			
		||||
        seven_activities_user_1: Activity,
 | 
			
		||||
    ) -> None:
 | 
			
		||||
        client = app.test_client()
 | 
			
		||||
        resp_login = client.post(
 | 
			
		||||
            '/api/auth/login',
 | 
			
		||||
@@ -226,8 +248,12 @@ class TestGetActivitiesWithPagination:
 | 
			
		||||
        assert len(data['data']['activities']) == 0
 | 
			
		||||
 | 
			
		||||
    def test_it_returns_error_on_invalid_page_value(
 | 
			
		||||
        self, app, user_1, sport_1_cycling, seven_activities_user_1
 | 
			
		||||
    ):
 | 
			
		||||
        self,
 | 
			
		||||
        app: Flask,
 | 
			
		||||
        user_1: User,
 | 
			
		||||
        sport_1_cycling: Sport,
 | 
			
		||||
        seven_activities_user_1: Activity,
 | 
			
		||||
    ) -> None:
 | 
			
		||||
        client = app.test_client()
 | 
			
		||||
        resp_login = client.post(
 | 
			
		||||
            '/api/auth/login',
 | 
			
		||||
@@ -252,8 +278,12 @@ class TestGetActivitiesWithPagination:
 | 
			
		||||
        )
 | 
			
		||||
 | 
			
		||||
    def test_it_gets_5_activities_per_page(
 | 
			
		||||
        self, app, user_1, sport_1_cycling, seven_activities_user_1
 | 
			
		||||
    ):
 | 
			
		||||
        self,
 | 
			
		||||
        app: Flask,
 | 
			
		||||
        user_1: User,
 | 
			
		||||
        sport_1_cycling: Sport,
 | 
			
		||||
        seven_activities_user_1: Activity,
 | 
			
		||||
    ) -> None:
 | 
			
		||||
        client = app.test_client()
 | 
			
		||||
        resp_login = client.post(
 | 
			
		||||
            '/api/auth/login',
 | 
			
		||||
@@ -283,8 +313,12 @@ class TestGetActivitiesWithPagination:
 | 
			
		||||
        )
 | 
			
		||||
 | 
			
		||||
    def test_it_gets_3_activities_per_page(
 | 
			
		||||
        self, app, user_1, sport_1_cycling, seven_activities_user_1
 | 
			
		||||
    ):
 | 
			
		||||
        self,
 | 
			
		||||
        app: Flask,
 | 
			
		||||
        user_1: User,
 | 
			
		||||
        sport_1_cycling: Sport,
 | 
			
		||||
        seven_activities_user_1: Activity,
 | 
			
		||||
    ) -> None:
 | 
			
		||||
        client = app.test_client()
 | 
			
		||||
        resp_login = client.post(
 | 
			
		||||
            '/api/auth/login',
 | 
			
		||||
@@ -316,8 +350,12 @@ class TestGetActivitiesWithPagination:
 | 
			
		||||
 | 
			
		||||
class TestGetActivitiesWithFilters:
 | 
			
		||||
    def test_it_gets_activities_with_date_filter(
 | 
			
		||||
        self, app, user_1, sport_1_cycling, seven_activities_user_1
 | 
			
		||||
    ):
 | 
			
		||||
        self,
 | 
			
		||||
        app: Flask,
 | 
			
		||||
        user_1: User,
 | 
			
		||||
        sport_1_cycling: Sport,
 | 
			
		||||
        seven_activities_user_1: Activity,
 | 
			
		||||
    ) -> None:
 | 
			
		||||
        client = app.test_client()
 | 
			
		||||
        resp_login = client.post(
 | 
			
		||||
            '/api/auth/login',
 | 
			
		||||
@@ -351,8 +389,12 @@ class TestGetActivitiesWithFilters:
 | 
			
		||||
        assert '0:16:40' == data['data']['activities'][1]['duration']
 | 
			
		||||
 | 
			
		||||
    def test_it_gets_no_activities_with_date_filter(
 | 
			
		||||
        self, app, user_1, sport_1_cycling, seven_activities_user_1
 | 
			
		||||
    ):
 | 
			
		||||
        self,
 | 
			
		||||
        app: Flask,
 | 
			
		||||
        user_1: User,
 | 
			
		||||
        sport_1_cycling: Sport,
 | 
			
		||||
        seven_activities_user_1: Activity,
 | 
			
		||||
    ) -> None:
 | 
			
		||||
        client = app.test_client()
 | 
			
		||||
        resp_login = client.post(
 | 
			
		||||
            '/api/auth/login',
 | 
			
		||||
@@ -374,8 +416,12 @@ class TestGetActivitiesWithFilters:
 | 
			
		||||
        assert len(data['data']['activities']) == 0
 | 
			
		||||
 | 
			
		||||
    def test_if_gets_activities_with_date_filter_from(
 | 
			
		||||
        self, app, user_1, sport_1_cycling, seven_activities_user_1
 | 
			
		||||
    ):
 | 
			
		||||
        self,
 | 
			
		||||
        app: Flask,
 | 
			
		||||
        user_1: User,
 | 
			
		||||
        sport_1_cycling: Sport,
 | 
			
		||||
        seven_activities_user_1: Activity,
 | 
			
		||||
    ) -> None:
 | 
			
		||||
        client = app.test_client()
 | 
			
		||||
        resp_login = client.post(
 | 
			
		||||
            '/api/auth/login',
 | 
			
		||||
@@ -406,8 +452,12 @@ class TestGetActivitiesWithFilters:
 | 
			
		||||
        )
 | 
			
		||||
 | 
			
		||||
    def test_it_gets_activities_with_date_filter_to(
 | 
			
		||||
        self, app, user_1, sport_1_cycling, seven_activities_user_1
 | 
			
		||||
    ):
 | 
			
		||||
        self,
 | 
			
		||||
        app: Flask,
 | 
			
		||||
        user_1: User,
 | 
			
		||||
        sport_1_cycling: Sport,
 | 
			
		||||
        seven_activities_user_1: Activity,
 | 
			
		||||
    ) -> None:
 | 
			
		||||
        client = app.test_client()
 | 
			
		||||
        resp_login = client.post(
 | 
			
		||||
            '/api/auth/login',
 | 
			
		||||
@@ -437,8 +487,12 @@ class TestGetActivitiesWithFilters:
 | 
			
		||||
        )
 | 
			
		||||
 | 
			
		||||
    def test_it_gets_activities_with_ascending_order(
 | 
			
		||||
        self, app, user_1, sport_1_cycling, seven_activities_user_1
 | 
			
		||||
    ):
 | 
			
		||||
        self,
 | 
			
		||||
        app: Flask,
 | 
			
		||||
        user_1: User,
 | 
			
		||||
        sport_1_cycling: Sport,
 | 
			
		||||
        seven_activities_user_1: Activity,
 | 
			
		||||
    ) -> None:
 | 
			
		||||
        client = app.test_client()
 | 
			
		||||
        resp_login = client.post(
 | 
			
		||||
            '/api/auth/login',
 | 
			
		||||
@@ -468,8 +522,12 @@ class TestGetActivitiesWithFilters:
 | 
			
		||||
        )
 | 
			
		||||
 | 
			
		||||
    def test_it_gets_activities_with_distance_filter(
 | 
			
		||||
        self, app, user_1, sport_1_cycling, seven_activities_user_1
 | 
			
		||||
    ):
 | 
			
		||||
        self,
 | 
			
		||||
        app: Flask,
 | 
			
		||||
        user_1: User,
 | 
			
		||||
        sport_1_cycling: Sport,
 | 
			
		||||
        seven_activities_user_1: Activity,
 | 
			
		||||
    ) -> None:
 | 
			
		||||
        client = app.test_client()
 | 
			
		||||
        resp_login = client.post(
 | 
			
		||||
            '/api/auth/login',
 | 
			
		||||
@@ -499,8 +557,12 @@ class TestGetActivitiesWithFilters:
 | 
			
		||||
        )
 | 
			
		||||
 | 
			
		||||
    def test_it_gets_activities_with_duration_filter(
 | 
			
		||||
        self, app, user_1, sport_1_cycling, seven_activities_user_1
 | 
			
		||||
    ):
 | 
			
		||||
        self,
 | 
			
		||||
        app: Flask,
 | 
			
		||||
        user_1: User,
 | 
			
		||||
        sport_1_cycling: Sport,
 | 
			
		||||
        seven_activities_user_1: Activity,
 | 
			
		||||
    ) -> None:
 | 
			
		||||
        client = app.test_client()
 | 
			
		||||
        resp_login = client.post(
 | 
			
		||||
            '/api/auth/login',
 | 
			
		||||
@@ -526,8 +588,12 @@ class TestGetActivitiesWithFilters:
 | 
			
		||||
        )
 | 
			
		||||
 | 
			
		||||
    def test_it_gets_activities_with_average_speed_filter(
 | 
			
		||||
        self, app, user_1, sport_1_cycling, seven_activities_user_1
 | 
			
		||||
    ):
 | 
			
		||||
        self,
 | 
			
		||||
        app: Flask,
 | 
			
		||||
        user_1: User,
 | 
			
		||||
        sport_1_cycling: Sport,
 | 
			
		||||
        seven_activities_user_1: Activity,
 | 
			
		||||
    ) -> None:
 | 
			
		||||
        client = app.test_client()
 | 
			
		||||
        resp_login = client.post(
 | 
			
		||||
            '/api/auth/login',
 | 
			
		||||
@@ -554,13 +620,13 @@ class TestGetActivitiesWithFilters:
 | 
			
		||||
 | 
			
		||||
    def test_it_gets_activities_with_max_speed_filter(
 | 
			
		||||
        self,
 | 
			
		||||
        app,
 | 
			
		||||
        user_1,
 | 
			
		||||
        sport_1_cycling,
 | 
			
		||||
        sport_2_running,
 | 
			
		||||
        activity_cycling_user_1,
 | 
			
		||||
        activity_running_user_1,
 | 
			
		||||
    ):
 | 
			
		||||
        app: Flask,
 | 
			
		||||
        user_1: User,
 | 
			
		||||
        sport_1_cycling: Sport,
 | 
			
		||||
        sport_2_running: Sport,
 | 
			
		||||
        activity_cycling_user_1: Activity,
 | 
			
		||||
        activity_running_user_1: Activity,
 | 
			
		||||
    ) -> None:
 | 
			
		||||
        activity_cycling_user_1.max_speed = 25
 | 
			
		||||
        activity_running_user_1.max_speed = 11
 | 
			
		||||
        client = app.test_client()
 | 
			
		||||
@@ -589,13 +655,13 @@ class TestGetActivitiesWithFilters:
 | 
			
		||||
 | 
			
		||||
    def test_it_gets_activities_with_sport_filter(
 | 
			
		||||
        self,
 | 
			
		||||
        app,
 | 
			
		||||
        user_1,
 | 
			
		||||
        sport_1_cycling,
 | 
			
		||||
        seven_activities_user_1,
 | 
			
		||||
        sport_2_running,
 | 
			
		||||
        activity_running_user_1,
 | 
			
		||||
    ):
 | 
			
		||||
        app: Flask,
 | 
			
		||||
        user_1: User,
 | 
			
		||||
        sport_1_cycling: Sport,
 | 
			
		||||
        seven_activities_user_1: Activity,
 | 
			
		||||
        sport_2_running: Sport,
 | 
			
		||||
        activity_running_user_1: Activity,
 | 
			
		||||
    ) -> None:
 | 
			
		||||
        client = app.test_client()
 | 
			
		||||
        resp_login = client.post(
 | 
			
		||||
            '/api/auth/login',
 | 
			
		||||
@@ -623,8 +689,12 @@ class TestGetActivitiesWithFilters:
 | 
			
		||||
 | 
			
		||||
class TestGetActivitiesWithFiltersAndPagination:
 | 
			
		||||
    def test_it_gets_page_2_with_date_filter(
 | 
			
		||||
        self, app, user_1, sport_1_cycling, seven_activities_user_1
 | 
			
		||||
    ):
 | 
			
		||||
        self,
 | 
			
		||||
        app: Flask,
 | 
			
		||||
        user_1: User,
 | 
			
		||||
        sport_1_cycling: Sport,
 | 
			
		||||
        seven_activities_user_1: Activity,
 | 
			
		||||
    ) -> None:
 | 
			
		||||
        client = app.test_client()
 | 
			
		||||
        resp_login = client.post(
 | 
			
		||||
            '/api/auth/login',
 | 
			
		||||
@@ -654,8 +724,12 @@ class TestGetActivitiesWithFiltersAndPagination:
 | 
			
		||||
        )
 | 
			
		||||
 | 
			
		||||
    def test_it_get_page_2_with_date_filter_and_ascending_order(
 | 
			
		||||
        self, app, user_1, sport_1_cycling, seven_activities_user_1
 | 
			
		||||
    ):
 | 
			
		||||
        self,
 | 
			
		||||
        app: Flask,
 | 
			
		||||
        user_1: User,
 | 
			
		||||
        sport_1_cycling: Sport,
 | 
			
		||||
        seven_activities_user_1: Activity,
 | 
			
		||||
    ) -> None:
 | 
			
		||||
        client = app.test_client()
 | 
			
		||||
        resp_login = client.post(
 | 
			
		||||
            '/api/auth/login',
 | 
			
		||||
@@ -687,8 +761,12 @@ class TestGetActivitiesWithFiltersAndPagination:
 | 
			
		||||
 | 
			
		||||
class TestGetActivity:
 | 
			
		||||
    def test_it_gets_an_activity(
 | 
			
		||||
        self, app, user_1, sport_1_cycling, activity_cycling_user_1
 | 
			
		||||
    ):
 | 
			
		||||
        self,
 | 
			
		||||
        app: Flask,
 | 
			
		||||
        user_1: User,
 | 
			
		||||
        sport_1_cycling: Sport,
 | 
			
		||||
        activity_cycling_user_1: Activity,
 | 
			
		||||
    ) -> None:
 | 
			
		||||
        client = app.test_client()
 | 
			
		||||
        resp_login = client.post(
 | 
			
		||||
            '/api/auth/login',
 | 
			
		||||
@@ -719,8 +797,13 @@ class TestGetActivity:
 | 
			
		||||
        assert '1:00:00' == data['data']['activities'][0]['duration']
 | 
			
		||||
 | 
			
		||||
    def test_it_returns_403_if_activity_belongs_to_a_different_user(
 | 
			
		||||
        self, app, user_1, user_2, sport_1_cycling, activity_cycling_user_2
 | 
			
		||||
    ):
 | 
			
		||||
        self,
 | 
			
		||||
        app: Flask,
 | 
			
		||||
        user_1: User,
 | 
			
		||||
        user_2: User,
 | 
			
		||||
        sport_1_cycling: Sport,
 | 
			
		||||
        activity_cycling_user_2: Activity,
 | 
			
		||||
    ) -> None:
 | 
			
		||||
        client = app.test_client()
 | 
			
		||||
        resp_login = client.post(
 | 
			
		||||
            '/api/auth/login',
 | 
			
		||||
@@ -741,7 +824,9 @@ class TestGetActivity:
 | 
			
		||||
        assert 'error' in data['status']
 | 
			
		||||
        assert 'You do not have permissions.' in data['message']
 | 
			
		||||
 | 
			
		||||
    def test_it_returns_404_if_activity_does_not_exist(self, app, user_1):
 | 
			
		||||
    def test_it_returns_404_if_activity_does_not_exist(
 | 
			
		||||
        self, app: Flask, user_1: User
 | 
			
		||||
    ) -> None:
 | 
			
		||||
        client = app.test_client()
 | 
			
		||||
        resp_login = client.post(
 | 
			
		||||
            '/api/auth/login',
 | 
			
		||||
@@ -763,8 +848,8 @@ class TestGetActivity:
 | 
			
		||||
        assert len(data['data']['activities']) == 0
 | 
			
		||||
 | 
			
		||||
    def test_it_returns_404_on_getting_gpx_if_activity_does_not_exist(
 | 
			
		||||
        self, app, user_1
 | 
			
		||||
    ):
 | 
			
		||||
        self, app: Flask, user_1: User
 | 
			
		||||
    ) -> None:
 | 
			
		||||
        random_short_id = get_random_short_id()
 | 
			
		||||
        client = app.test_client()
 | 
			
		||||
        resp_login = client.post(
 | 
			
		||||
@@ -788,8 +873,8 @@ class TestGetActivity:
 | 
			
		||||
        assert data['data']['gpx'] == ''
 | 
			
		||||
 | 
			
		||||
    def test_it_returns_404_on_getting_chart_data_if_activity_does_not_exist(
 | 
			
		||||
        self, app, user_1
 | 
			
		||||
    ):
 | 
			
		||||
        self, app: Flask, user_1: User
 | 
			
		||||
    ) -> None:
 | 
			
		||||
        random_short_id = get_random_short_id()
 | 
			
		||||
        client = app.test_client()
 | 
			
		||||
        resp_login = client.post(
 | 
			
		||||
@@ -813,8 +898,12 @@ class TestGetActivity:
 | 
			
		||||
        assert data['data']['chart_data'] == ''
 | 
			
		||||
 | 
			
		||||
    def test_it_returns_404_on_getting_gpx_if_activity_have_no_gpx(
 | 
			
		||||
        self, app, user_1, sport_1_cycling, activity_cycling_user_1
 | 
			
		||||
    ):
 | 
			
		||||
        self,
 | 
			
		||||
        app: Flask,
 | 
			
		||||
        user_1: User,
 | 
			
		||||
        sport_1_cycling: Sport,
 | 
			
		||||
        activity_cycling_user_1: Activity,
 | 
			
		||||
    ) -> None:
 | 
			
		||||
        activity_short_id = activity_cycling_user_1.short_id
 | 
			
		||||
        client = app.test_client()
 | 
			
		||||
        resp_login = client.post(
 | 
			
		||||
@@ -840,8 +929,12 @@ class TestGetActivity:
 | 
			
		||||
        )
 | 
			
		||||
 | 
			
		||||
    def test_it_returns_404_if_activity_have_no_chart_data(
 | 
			
		||||
        self, app, user_1, sport_1_cycling, activity_cycling_user_1
 | 
			
		||||
    ):
 | 
			
		||||
        self,
 | 
			
		||||
        app: Flask,
 | 
			
		||||
        user_1: User,
 | 
			
		||||
        sport_1_cycling: Sport,
 | 
			
		||||
        activity_cycling_user_1: Activity,
 | 
			
		||||
    ) -> None:
 | 
			
		||||
        activity_short_id = activity_cycling_user_1.short_id
 | 
			
		||||
        client = app.test_client()
 | 
			
		||||
        resp_login = client.post(
 | 
			
		||||
@@ -867,8 +960,12 @@ class TestGetActivity:
 | 
			
		||||
        )
 | 
			
		||||
 | 
			
		||||
    def test_it_returns_500_on_getting_gpx_if_an_activity_has_invalid_gpx_pathname(  # noqa
 | 
			
		||||
        self, app, user_1, sport_1_cycling, activity_cycling_user_1
 | 
			
		||||
    ):
 | 
			
		||||
        self,
 | 
			
		||||
        app: Flask,
 | 
			
		||||
        user_1: User,
 | 
			
		||||
        sport_1_cycling: Sport,
 | 
			
		||||
        activity_cycling_user_1: Activity,
 | 
			
		||||
    ) -> None:
 | 
			
		||||
        activity_cycling_user_1.gpx = "some path"
 | 
			
		||||
        client = app.test_client()
 | 
			
		||||
        resp_login = client.post(
 | 
			
		||||
@@ -895,8 +992,12 @@ class TestGetActivity:
 | 
			
		||||
        assert 'data' not in data
 | 
			
		||||
 | 
			
		||||
    def test_it_returns_500_on_getting_chart_data_if_an_activity_has_invalid_gpx_pathname(  # noqa
 | 
			
		||||
        self, app, user_1, sport_1_cycling, activity_cycling_user_1
 | 
			
		||||
    ):
 | 
			
		||||
        self,
 | 
			
		||||
        app: Flask,
 | 
			
		||||
        user_1: User,
 | 
			
		||||
        sport_1_cycling: Sport,
 | 
			
		||||
        activity_cycling_user_1: Activity,
 | 
			
		||||
    ) -> None:
 | 
			
		||||
        activity_cycling_user_1.gpx = 'some path'
 | 
			
		||||
        client = app.test_client()
 | 
			
		||||
        resp_login = client.post(
 | 
			
		||||
@@ -922,7 +1023,9 @@ class TestGetActivity:
 | 
			
		||||
        )
 | 
			
		||||
        assert 'data' not in data
 | 
			
		||||
 | 
			
		||||
    def test_it_returns_404_if_activity_has_no_map(self, app, user_1):
 | 
			
		||||
    def test_it_returns_404_if_activity_has_no_map(
 | 
			
		||||
        self, app: Flask, user_1: User
 | 
			
		||||
    ) -> None:
 | 
			
		||||
        client = app.test_client()
 | 
			
		||||
        resp_login = client.post(
 | 
			
		||||
            '/api/auth/login',
 | 
			
		||||
 
 | 
			
		||||
@@ -2,12 +2,15 @@ import json
 | 
			
		||||
import os
 | 
			
		||||
from datetime import datetime
 | 
			
		||||
from io import BytesIO
 | 
			
		||||
from typing import Dict
 | 
			
		||||
 | 
			
		||||
from fittrackee.activities.models import Activity
 | 
			
		||||
from fittrackee.activities.models import Activity, Sport
 | 
			
		||||
from fittrackee.activities.utils_id import decode_short_id
 | 
			
		||||
from fittrackee.users.models import User
 | 
			
		||||
from flask import Flask
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
def assert_activity_data_with_gpx(data):
 | 
			
		||||
def assert_activity_data_with_gpx(data: Dict) -> None:
 | 
			
		||||
    assert 'creation_date' in data['data']['activities'][0]
 | 
			
		||||
    assert (
 | 
			
		||||
        'Tue, 13 Mar 2018 12:44:45 GMT'
 | 
			
		||||
@@ -70,7 +73,7 @@ def assert_activity_data_with_gpx(data):
 | 
			
		||||
    assert records[3]['value'] == 4.61
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
def assert_activity_data_with_gpx_segments(data):
 | 
			
		||||
def assert_activity_data_with_gpx_segments(data: Dict) -> None:
 | 
			
		||||
    assert 'creation_date' in data['data']['activities'][0]
 | 
			
		||||
    assert (
 | 
			
		||||
        'Tue, 13 Mar 2018 12:44:45 GMT'
 | 
			
		||||
@@ -144,7 +147,7 @@ def assert_activity_data_with_gpx_segments(data):
 | 
			
		||||
    assert records[2]['value'] == 4.59
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
def assert_activity_data_wo_gpx(data):
 | 
			
		||||
def assert_activity_data_wo_gpx(data: Dict) -> None:
 | 
			
		||||
    assert 'creation_date' in data['data']['activities'][0]
 | 
			
		||||
    assert (
 | 
			
		||||
        data['data']['activities'][0]['activity_date']
 | 
			
		||||
@@ -200,8 +203,8 @@ def assert_activity_data_wo_gpx(data):
 | 
			
		||||
 | 
			
		||||
class TestPostActivityWithGpx:
 | 
			
		||||
    def test_it_adds_an_activity_with_gpx_file(
 | 
			
		||||
        self, app, user_1, sport_1_cycling, gpx_file
 | 
			
		||||
    ):
 | 
			
		||||
        self, app: Flask, user_1: User, sport_1_cycling: Sport, gpx_file: str
 | 
			
		||||
    ) -> None:
 | 
			
		||||
        client = app.test_client()
 | 
			
		||||
        resp_login = client.post(
 | 
			
		||||
            '/api/auth/login',
 | 
			
		||||
@@ -230,8 +233,12 @@ class TestPostActivityWithGpx:
 | 
			
		||||
        assert_activity_data_with_gpx(data)
 | 
			
		||||
 | 
			
		||||
    def test_it_adds_an_activity_with_gpx_without_name(
 | 
			
		||||
        self, app, user_1, sport_1_cycling, gpx_file_wo_name
 | 
			
		||||
    ):
 | 
			
		||||
        self,
 | 
			
		||||
        app: Flask,
 | 
			
		||||
        user_1: User,
 | 
			
		||||
        sport_1_cycling: Sport,
 | 
			
		||||
        gpx_file_wo_name: str,
 | 
			
		||||
    ) -> None:
 | 
			
		||||
        client = app.test_client()
 | 
			
		||||
        resp_login = client.post(
 | 
			
		||||
            '/api/auth/login',
 | 
			
		||||
@@ -263,8 +270,12 @@ class TestPostActivityWithGpx:
 | 
			
		||||
        assert_activity_data_with_gpx(data)
 | 
			
		||||
 | 
			
		||||
    def test_it_adds_an_activity_with_gpx_without_name_timezone(
 | 
			
		||||
        self, app, user_1, sport_1_cycling, gpx_file_wo_name
 | 
			
		||||
    ):
 | 
			
		||||
        self,
 | 
			
		||||
        app: Flask,
 | 
			
		||||
        user_1: User,
 | 
			
		||||
        sport_1_cycling: Sport,
 | 
			
		||||
        gpx_file_wo_name: str,
 | 
			
		||||
    ) -> None:
 | 
			
		||||
        user_1.timezone = 'Europe/Paris'
 | 
			
		||||
        client = app.test_client()
 | 
			
		||||
        resp_login = client.post(
 | 
			
		||||
@@ -297,8 +308,8 @@ class TestPostActivityWithGpx:
 | 
			
		||||
        assert_activity_data_with_gpx(data)
 | 
			
		||||
 | 
			
		||||
    def test_it_adds_get_an_activity_with_gpx_notes(
 | 
			
		||||
        self, app, user_1, sport_1_cycling, gpx_file
 | 
			
		||||
    ):
 | 
			
		||||
        self, app: Flask, user_1: User, sport_1_cycling: Sport, gpx_file: str
 | 
			
		||||
    ) -> None:
 | 
			
		||||
        client = app.test_client()
 | 
			
		||||
        resp_login = client.post(
 | 
			
		||||
            '/api/auth/login',
 | 
			
		||||
@@ -327,8 +338,12 @@ class TestPostActivityWithGpx:
 | 
			
		||||
        assert 'test activity' == data['data']['activities'][0]['notes']
 | 
			
		||||
 | 
			
		||||
    def test_it_returns_500_if_gpx_file_has_not_tracks(
 | 
			
		||||
        self, app, user_1, sport_1_cycling, gpx_file_wo_track
 | 
			
		||||
    ):
 | 
			
		||||
        self,
 | 
			
		||||
        app: Flask,
 | 
			
		||||
        user_1: User,
 | 
			
		||||
        sport_1_cycling: Sport,
 | 
			
		||||
        gpx_file_wo_track: str,
 | 
			
		||||
    ) -> None:
 | 
			
		||||
        client = app.test_client()
 | 
			
		||||
        resp_login = client.post(
 | 
			
		||||
            '/api/auth/login',
 | 
			
		||||
@@ -352,12 +367,16 @@ class TestPostActivityWithGpx:
 | 
			
		||||
        data = json.loads(response.data.decode())
 | 
			
		||||
        assert response.status_code == 500
 | 
			
		||||
        assert 'error' in data['status']
 | 
			
		||||
        assert 'Error during gpx file parsing.' in data['message']
 | 
			
		||||
        assert 'Error during gpx processing.' in data['message']
 | 
			
		||||
        assert 'data' not in data
 | 
			
		||||
 | 
			
		||||
    def test_it_returns_500_if_gpx_has_invalid_xml(
 | 
			
		||||
        self, app, user_1, sport_1_cycling, gpx_file_invalid_xml
 | 
			
		||||
    ):
 | 
			
		||||
        self,
 | 
			
		||||
        app: Flask,
 | 
			
		||||
        user_1: User,
 | 
			
		||||
        sport_1_cycling: Sport,
 | 
			
		||||
        gpx_file_invalid_xml: str,
 | 
			
		||||
    ) -> None:
 | 
			
		||||
        client = app.test_client()
 | 
			
		||||
        resp_login = client.post(
 | 
			
		||||
            '/api/auth/login',
 | 
			
		||||
@@ -388,8 +407,8 @@ class TestPostActivityWithGpx:
 | 
			
		||||
        assert 'data' not in data
 | 
			
		||||
 | 
			
		||||
    def test_it_returns_400_if_activity_gpx_has_invalid_extension(
 | 
			
		||||
        self, app, user_1, sport_1_cycling, gpx_file
 | 
			
		||||
    ):
 | 
			
		||||
        self, app: Flask, user_1: User, sport_1_cycling: Sport, gpx_file: str
 | 
			
		||||
    ) -> None:
 | 
			
		||||
        client = app.test_client()
 | 
			
		||||
        resp_login = client.post(
 | 
			
		||||
            '/api/auth/login',
 | 
			
		||||
@@ -416,8 +435,8 @@ class TestPostActivityWithGpx:
 | 
			
		||||
        assert data['message'] == 'File extension not allowed.'
 | 
			
		||||
 | 
			
		||||
    def test_it_returns_400_if_sport_id_is_not_provided(
 | 
			
		||||
        self, app, user_1, sport_1_cycling, gpx_file
 | 
			
		||||
    ):
 | 
			
		||||
        self, app: Flask, user_1: User, sport_1_cycling: Sport, gpx_file: str
 | 
			
		||||
    ) -> None:
 | 
			
		||||
        client = app.test_client()
 | 
			
		||||
        resp_login = client.post(
 | 
			
		||||
            '/api/auth/login',
 | 
			
		||||
@@ -443,8 +462,8 @@ class TestPostActivityWithGpx:
 | 
			
		||||
        assert data['message'] == 'Invalid payload.'
 | 
			
		||||
 | 
			
		||||
    def test_it_returns_500_if_sport_id_does_not_exists(
 | 
			
		||||
        self, app, user_1, sport_1_cycling, gpx_file
 | 
			
		||||
    ):
 | 
			
		||||
        self, app: Flask, user_1: User, sport_1_cycling: Sport, gpx_file: str
 | 
			
		||||
    ) -> None:
 | 
			
		||||
        client = app.test_client()
 | 
			
		||||
        resp_login = client.post(
 | 
			
		||||
            '/api/auth/login',
 | 
			
		||||
@@ -471,8 +490,8 @@ class TestPostActivityWithGpx:
 | 
			
		||||
        assert data['message'] == 'Sport id: 2 does not exist'
 | 
			
		||||
 | 
			
		||||
    def test_returns_400_if_no_gpx_file_is_provided(
 | 
			
		||||
        self, app, user_1, sport_1_cycling
 | 
			
		||||
    ):
 | 
			
		||||
        self, app: Flask, user_1: User, sport_1_cycling: Sport
 | 
			
		||||
    ) -> None:
 | 
			
		||||
        client = app.test_client()
 | 
			
		||||
        resp_login = client.post(
 | 
			
		||||
            '/api/auth/login',
 | 
			
		||||
@@ -498,8 +517,8 @@ class TestPostActivityWithGpx:
 | 
			
		||||
 | 
			
		||||
class TestPostActivityWithoutGpx:
 | 
			
		||||
    def test_it_adds_an_activity_without_gpx(
 | 
			
		||||
        self, app, user_1, sport_1_cycling
 | 
			
		||||
    ):
 | 
			
		||||
        self, app: Flask, user_1: User, sport_1_cycling: Sport
 | 
			
		||||
    ) -> None:
 | 
			
		||||
        client = app.test_client()
 | 
			
		||||
        resp_login = client.post(
 | 
			
		||||
            '/api/auth/login',
 | 
			
		||||
@@ -531,8 +550,8 @@ class TestPostActivityWithoutGpx:
 | 
			
		||||
        assert_activity_data_wo_gpx(data)
 | 
			
		||||
 | 
			
		||||
    def test_it_returns_400_if_activity_date_is_missing(
 | 
			
		||||
        self, app, user_1, sport_1_cycling
 | 
			
		||||
    ):
 | 
			
		||||
        self, app: Flask, user_1: User, sport_1_cycling: Sport
 | 
			
		||||
    ) -> None:
 | 
			
		||||
        client = app.test_client()
 | 
			
		||||
        resp_login = client.post(
 | 
			
		||||
            '/api/auth/login',
 | 
			
		||||
@@ -556,8 +575,8 @@ class TestPostActivityWithoutGpx:
 | 
			
		||||
        assert 'Invalid payload.' in data['message']
 | 
			
		||||
 | 
			
		||||
    def test_it_returns_500_if_activity_format_is_invalid(
 | 
			
		||||
        self, app, user_1, sport_1_cycling
 | 
			
		||||
    ):
 | 
			
		||||
        self, app: Flask, user_1: User, sport_1_cycling: Sport
 | 
			
		||||
    ) -> None:
 | 
			
		||||
        client = app.test_client()
 | 
			
		||||
        resp_login = client.post(
 | 
			
		||||
            '/api/auth/login',
 | 
			
		||||
@@ -588,8 +607,12 @@ class TestPostActivityWithoutGpx:
 | 
			
		||||
        assert 'Error during activity save.' in data['message']
 | 
			
		||||
 | 
			
		||||
    def test_it_adds_activity_with_zero_value(
 | 
			
		||||
        self, app, user_1, sport_1_cycling, sport_2_running
 | 
			
		||||
    ):
 | 
			
		||||
        self,
 | 
			
		||||
        app: Flask,
 | 
			
		||||
        user_1: User,
 | 
			
		||||
        sport_1_cycling: Sport,
 | 
			
		||||
        sport_2_running: Sport,
 | 
			
		||||
    ) -> None:
 | 
			
		||||
        client = app.test_client()
 | 
			
		||||
        resp_login = client.post(
 | 
			
		||||
            '/api/auth/login',
 | 
			
		||||
@@ -645,8 +668,8 @@ class TestPostActivityWithoutGpx:
 | 
			
		||||
 | 
			
		||||
class TestPostActivityWithZipArchive:
 | 
			
		||||
    def test_it_adds_activities_with_zip_archive(
 | 
			
		||||
        self, app, user_1, sport_1_cycling
 | 
			
		||||
    ):
 | 
			
		||||
        self, app: Flask, user_1: User, sport_1_cycling: Sport
 | 
			
		||||
    ) -> None:
 | 
			
		||||
        file_path = os.path.join(app.root_path, 'tests/files/gpx_test.zip')
 | 
			
		||||
        # 'gpx_test.zip' contains 3 gpx files (same data) and 1 non-gpx file
 | 
			
		||||
        with open(file_path, 'rb') as zip_file:
 | 
			
		||||
@@ -679,8 +702,8 @@ class TestPostActivityWithZipArchive:
 | 
			
		||||
            assert_activity_data_with_gpx(data)
 | 
			
		||||
 | 
			
		||||
    def test_it_returns_400_if_folder_is_present_in_zpi_archive(
 | 
			
		||||
        self, app, user_1, sport_1_cycling
 | 
			
		||||
    ):
 | 
			
		||||
        self, app: Flask, user_1: User, sport_1_cycling: Sport
 | 
			
		||||
    ) -> None:
 | 
			
		||||
        file_path = os.path.join(
 | 
			
		||||
            app.root_path, 'tests/files/gpx_test_folder.zip'
 | 
			
		||||
        )
 | 
			
		||||
@@ -715,8 +738,8 @@ class TestPostActivityWithZipArchive:
 | 
			
		||||
            assert len(data['data']['activities']) == 0
 | 
			
		||||
 | 
			
		||||
    def test_it_returns_500_if_one_fle_in_zip_archive_is_invalid(
 | 
			
		||||
        self, app, user_1, sport_1_cycling
 | 
			
		||||
    ):
 | 
			
		||||
        self, app: Flask, user_1: User, sport_1_cycling: Sport
 | 
			
		||||
    ) -> None:
 | 
			
		||||
        file_path = os.path.join(
 | 
			
		||||
            app.root_path, 'tests/files/gpx_test_incorrect.zip'
 | 
			
		||||
        )
 | 
			
		||||
@@ -747,13 +770,15 @@ class TestPostActivityWithZipArchive:
 | 
			
		||||
            data = json.loads(response.data.decode())
 | 
			
		||||
            assert response.status_code == 500
 | 
			
		||||
            assert 'error' in data['status']
 | 
			
		||||
            assert 'Error during gpx file parsing.' in data['message']
 | 
			
		||||
            assert 'Error during gpx processing.' in data['message']
 | 
			
		||||
            assert 'data' not in data
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
class TestPostAndGetActivityWithGpx:
 | 
			
		||||
    @staticmethod
 | 
			
		||||
    def activity_assertion(app, gpx_file, with_segments):
 | 
			
		||||
    def activity_assertion(
 | 
			
		||||
        app: Flask, gpx_file: str, with_segments: bool
 | 
			
		||||
    ) -> None:
 | 
			
		||||
        client = app.test_client()
 | 
			
		||||
        resp_login = client.post(
 | 
			
		||||
            '/api/auth/login',
 | 
			
		||||
@@ -849,18 +874,22 @@ class TestPostAndGetActivityWithGpx:
 | 
			
		||||
        )
 | 
			
		||||
 | 
			
		||||
    def test_it_gets_an_activity_created_with_gpx(
 | 
			
		||||
        self, app, user_1, sport_1_cycling, gpx_file
 | 
			
		||||
    ):
 | 
			
		||||
        self, app: Flask, user_1: User, sport_1_cycling: Sport, gpx_file: str
 | 
			
		||||
    ) -> None:
 | 
			
		||||
        return self.activity_assertion(app, gpx_file, False)
 | 
			
		||||
 | 
			
		||||
    def test_it_gets_an_activity_created_with_gpx_with_segments(
 | 
			
		||||
        self, app, user_1, sport_1_cycling, gpx_file_with_segments
 | 
			
		||||
    ):
 | 
			
		||||
        self,
 | 
			
		||||
        app: Flask,
 | 
			
		||||
        user_1: User,
 | 
			
		||||
        sport_1_cycling: Sport,
 | 
			
		||||
        gpx_file_with_segments: str,
 | 
			
		||||
    ) -> None:
 | 
			
		||||
        return self.activity_assertion(app, gpx_file_with_segments, True)
 | 
			
		||||
 | 
			
		||||
    def test_it_gets_chart_data_for_an_activity_created_with_gpx(
 | 
			
		||||
        self, app, user_1, sport_1_cycling, gpx_file
 | 
			
		||||
    ):
 | 
			
		||||
        self, app: Flask, user_1: User, sport_1_cycling: Sport, gpx_file: str
 | 
			
		||||
    ) -> None:
 | 
			
		||||
        client = app.test_client()
 | 
			
		||||
        resp_login = client.post(
 | 
			
		||||
            '/api/auth/login',
 | 
			
		||||
@@ -897,8 +926,8 @@ class TestPostAndGetActivityWithGpx:
 | 
			
		||||
        assert data['data']['chart_data'] != ''
 | 
			
		||||
 | 
			
		||||
    def test_it_gets_segment_chart_data_for_an_activity_created_with_gpx(
 | 
			
		||||
        self, app, user_1, sport_1_cycling, gpx_file
 | 
			
		||||
    ):
 | 
			
		||||
        self, app: Flask, user_1: User, sport_1_cycling: Sport, gpx_file: str
 | 
			
		||||
    ) -> None:
 | 
			
		||||
        client = app.test_client()
 | 
			
		||||
        resp_login = client.post(
 | 
			
		||||
            '/api/auth/login',
 | 
			
		||||
@@ -935,8 +964,13 @@ class TestPostAndGetActivityWithGpx:
 | 
			
		||||
        assert data['data']['chart_data'] != ''
 | 
			
		||||
 | 
			
		||||
    def test_it_returns_403_on_getting_chart_data_if_activity_belongs_to_another_user(  # noqa
 | 
			
		||||
        self, app, user_1, user_2, sport_1_cycling, gpx_file
 | 
			
		||||
    ):
 | 
			
		||||
        self,
 | 
			
		||||
        app: Flask,
 | 
			
		||||
        user_1: User,
 | 
			
		||||
        user_2: User,
 | 
			
		||||
        sport_1_cycling: Sport,
 | 
			
		||||
        gpx_file: str,
 | 
			
		||||
    ) -> None:
 | 
			
		||||
        client = app.test_client()
 | 
			
		||||
        resp_login = client.post(
 | 
			
		||||
            '/api/auth/login',
 | 
			
		||||
@@ -977,8 +1011,8 @@ class TestPostAndGetActivityWithGpx:
 | 
			
		||||
        assert data['message'] == 'You do not have permissions.'
 | 
			
		||||
 | 
			
		||||
    def test_it_returns_500_on_invalid_segment_id(
 | 
			
		||||
        self, app, user_1, sport_1_cycling, gpx_file
 | 
			
		||||
    ):
 | 
			
		||||
        self, app: Flask, user_1: User, sport_1_cycling: Sport, gpx_file: str
 | 
			
		||||
    ) -> None:
 | 
			
		||||
        client = app.test_client()
 | 
			
		||||
        resp_login = client.post(
 | 
			
		||||
            '/api/auth/login',
 | 
			
		||||
@@ -1015,8 +1049,8 @@ class TestPostAndGetActivityWithGpx:
 | 
			
		||||
        assert 'data' not in data
 | 
			
		||||
 | 
			
		||||
    def test_it_returns_404_if_segment_id_does_not_exist(
 | 
			
		||||
        self, app, user_1, sport_1_cycling, gpx_file
 | 
			
		||||
    ):
 | 
			
		||||
        self, app: Flask, user_1: User, sport_1_cycling: Sport, gpx_file: str
 | 
			
		||||
    ) -> None:
 | 
			
		||||
        client = app.test_client()
 | 
			
		||||
        resp_login = client.post(
 | 
			
		||||
            '/api/auth/login',
 | 
			
		||||
@@ -1055,8 +1089,8 @@ class TestPostAndGetActivityWithGpx:
 | 
			
		||||
 | 
			
		||||
class TestPostAndGetActivityWithoutGpx:
 | 
			
		||||
    def test_it_add_and_gets_an_activity_wo_gpx(
 | 
			
		||||
        self, app, user_1, sport_1_cycling
 | 
			
		||||
    ):
 | 
			
		||||
        self, app: Flask, user_1: User, sport_1_cycling: Sport
 | 
			
		||||
    ) -> None:
 | 
			
		||||
        client = app.test_client()
 | 
			
		||||
        resp_login = client.post(
 | 
			
		||||
            '/api/auth/login',
 | 
			
		||||
@@ -1097,8 +1131,8 @@ class TestPostAndGetActivityWithoutGpx:
 | 
			
		||||
        assert_activity_data_wo_gpx(data)
 | 
			
		||||
 | 
			
		||||
    def test_it_adds_and_gets_an_activity_wo_gpx_notes(
 | 
			
		||||
        self, app, user_1, sport_1_cycling
 | 
			
		||||
    ):
 | 
			
		||||
        self, app: Flask, user_1: User, sport_1_cycling: Sport
 | 
			
		||||
    ) -> None:
 | 
			
		||||
        client = app.test_client()
 | 
			
		||||
        resp_login = client.post(
 | 
			
		||||
            '/api/auth/login',
 | 
			
		||||
@@ -1142,8 +1176,8 @@ class TestPostAndGetActivityWithoutGpx:
 | 
			
		||||
 | 
			
		||||
class TestPostAndGetActivityUsingTimezones:
 | 
			
		||||
    def test_it_add_and_gets_an_activity_wo_gpx_with_timezone(
 | 
			
		||||
        self, app, user_1, sport_1_cycling
 | 
			
		||||
    ):
 | 
			
		||||
        self, app: Flask, user_1: User, sport_1_cycling: Sport
 | 
			
		||||
    ) -> None:
 | 
			
		||||
        user_1.timezone = 'Europe/Paris'
 | 
			
		||||
        client = app.test_client()
 | 
			
		||||
        resp_login = client.post(
 | 
			
		||||
@@ -1192,8 +1226,8 @@ class TestPostAndGetActivityUsingTimezones:
 | 
			
		||||
        )
 | 
			
		||||
 | 
			
		||||
    def test_it_adds_and_gets_activities_date_filter_with_timezone_new_york(
 | 
			
		||||
        self, app, user_1_full, sport_1_cycling
 | 
			
		||||
    ):
 | 
			
		||||
        self, app: Flask, user_1_full: User, sport_1_cycling: Sport
 | 
			
		||||
    ) -> None:
 | 
			
		||||
        client = app.test_client()
 | 
			
		||||
        resp_login = client.post(
 | 
			
		||||
            '/api/auth/login',
 | 
			
		||||
@@ -1239,8 +1273,12 @@ class TestPostAndGetActivityUsingTimezones:
 | 
			
		||||
        )
 | 
			
		||||
 | 
			
		||||
    def test_it_adds_and_gets_activities_date_filter_with_timezone_paris(
 | 
			
		||||
        self, app, user_1_paris, sport_1_cycling, activity_cycling_user_1
 | 
			
		||||
    ):
 | 
			
		||||
        self,
 | 
			
		||||
        app: Flask,
 | 
			
		||||
        user_1_paris: User,
 | 
			
		||||
        sport_1_cycling: Sport,
 | 
			
		||||
        activity_cycling_user_1: Activity,
 | 
			
		||||
    ) -> None:
 | 
			
		||||
        client = app.test_client()
 | 
			
		||||
        resp_login = client.post(
 | 
			
		||||
            '/api/auth/login',
 | 
			
		||||
 
 | 
			
		||||
@@ -1,12 +1,15 @@
 | 
			
		||||
import json
 | 
			
		||||
from typing import Dict
 | 
			
		||||
 | 
			
		||||
from fittrackee.activities.models import Activity
 | 
			
		||||
from fittrackee.activities.models import Activity, Sport
 | 
			
		||||
from fittrackee.activities.utils_id import decode_short_id
 | 
			
		||||
from fittrackee.users.models import User
 | 
			
		||||
from flask import Flask
 | 
			
		||||
 | 
			
		||||
from .utils import get_random_short_id, post_an_activity
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
def assert_activity_data_with_gpx(data, sport_id):
 | 
			
		||||
def assert_activity_data_with_gpx(data: Dict, sport_id: int) -> None:
 | 
			
		||||
    assert 'creation_date' in data['data']['activities'][0]
 | 
			
		||||
    assert (
 | 
			
		||||
        'Tue, 13 Mar 2018 12:44:45 GMT'
 | 
			
		||||
@@ -51,8 +54,13 @@ def assert_activity_data_with_gpx(data, sport_id):
 | 
			
		||||
 | 
			
		||||
class TestEditActivityWithGpx:
 | 
			
		||||
    def test_it_updates_title_for_an_activity_with_gpx(
 | 
			
		||||
        self, app, user_1, sport_1_cycling, sport_2_running, gpx_file
 | 
			
		||||
    ):
 | 
			
		||||
        self,
 | 
			
		||||
        app: Flask,
 | 
			
		||||
        user_1: User,
 | 
			
		||||
        sport_1_cycling: Sport,
 | 
			
		||||
        sport_2_running: Sport,
 | 
			
		||||
        gpx_file: str,
 | 
			
		||||
    ) -> None:
 | 
			
		||||
        token, activity_short_id = post_an_activity(app, gpx_file)
 | 
			
		||||
        client = app.test_client()
 | 
			
		||||
 | 
			
		||||
@@ -72,8 +80,13 @@ class TestEditActivityWithGpx:
 | 
			
		||||
        assert_activity_data_with_gpx(data, sport_2_running.id)
 | 
			
		||||
 | 
			
		||||
    def test_it_adds_notes_for_an_activity_with_gpx(
 | 
			
		||||
        self, app, user_1, sport_1_cycling, sport_2_running, gpx_file
 | 
			
		||||
    ):
 | 
			
		||||
        self,
 | 
			
		||||
        app: Flask,
 | 
			
		||||
        user_1: User,
 | 
			
		||||
        sport_1_cycling: Sport,
 | 
			
		||||
        sport_2_running: Sport,
 | 
			
		||||
        gpx_file: str,
 | 
			
		||||
    ) -> None:
 | 
			
		||||
        token, activity_short_id = post_an_activity(app, gpx_file)
 | 
			
		||||
        client = app.test_client()
 | 
			
		||||
 | 
			
		||||
@@ -92,8 +105,14 @@ class TestEditActivityWithGpx:
 | 
			
		||||
        assert data['data']['activities'][0]['notes'] == 'test notes'
 | 
			
		||||
 | 
			
		||||
    def test_it_raises_403_when_editing_an_activity_from_different_user(
 | 
			
		||||
        self, app, user_1, user_2, sport_1_cycling, sport_2_running, gpx_file
 | 
			
		||||
    ):
 | 
			
		||||
        self,
 | 
			
		||||
        app: Flask,
 | 
			
		||||
        user_1: User,
 | 
			
		||||
        user_2: User,
 | 
			
		||||
        sport_1_cycling: Sport,
 | 
			
		||||
        sport_2_running: Sport,
 | 
			
		||||
        gpx_file: str,
 | 
			
		||||
    ) -> None:
 | 
			
		||||
        _, activity_short_id = post_an_activity(app, gpx_file)
 | 
			
		||||
        client = app.test_client()
 | 
			
		||||
        resp_login = client.post(
 | 
			
		||||
@@ -118,8 +137,13 @@ class TestEditActivityWithGpx:
 | 
			
		||||
        assert 'You do not have permissions.' in data['message']
 | 
			
		||||
 | 
			
		||||
    def test_it_updates_sport(
 | 
			
		||||
        self, app, user_1, sport_1_cycling, sport_2_running, gpx_file
 | 
			
		||||
    ):
 | 
			
		||||
        self,
 | 
			
		||||
        app: Flask,
 | 
			
		||||
        user_1: User,
 | 
			
		||||
        sport_1_cycling: Sport,
 | 
			
		||||
        sport_2_running: Sport,
 | 
			
		||||
        gpx_file: str,
 | 
			
		||||
    ) -> None:
 | 
			
		||||
        token, activity_short_id = post_an_activity(app, gpx_file)
 | 
			
		||||
        client = app.test_client()
 | 
			
		||||
 | 
			
		||||
@@ -139,8 +163,8 @@ class TestEditActivityWithGpx:
 | 
			
		||||
        assert_activity_data_with_gpx(data, sport_2_running.id)
 | 
			
		||||
 | 
			
		||||
    def test_it_returns_400_if_payload_is_empty(
 | 
			
		||||
        self, app, user_1, sport_1_cycling, gpx_file
 | 
			
		||||
    ):
 | 
			
		||||
        self, app: Flask, user_1: User, sport_1_cycling: Sport, gpx_file: str
 | 
			
		||||
    ) -> None:
 | 
			
		||||
        token, activity_short_id = post_an_activity(app, gpx_file)
 | 
			
		||||
        client = app.test_client()
 | 
			
		||||
 | 
			
		||||
@@ -157,8 +181,8 @@ class TestEditActivityWithGpx:
 | 
			
		||||
        assert 'Invalid payload.' in data['message']
 | 
			
		||||
 | 
			
		||||
    def test_it_raises_500_if_sport_does_not_exists(
 | 
			
		||||
        self, app, user_1, sport_1_cycling, gpx_file
 | 
			
		||||
    ):
 | 
			
		||||
        self, app: Flask, user_1: User, sport_1_cycling: Sport, gpx_file: str
 | 
			
		||||
    ) -> None:
 | 
			
		||||
        token, activity_short_id = post_an_activity(app, gpx_file)
 | 
			
		||||
        client = app.test_client()
 | 
			
		||||
 | 
			
		||||
@@ -181,12 +205,12 @@ class TestEditActivityWithGpx:
 | 
			
		||||
class TestEditActivityWithoutGpx:
 | 
			
		||||
    def test_it_updates_an_activity_wo_gpx(
 | 
			
		||||
        self,
 | 
			
		||||
        app,
 | 
			
		||||
        user_1,
 | 
			
		||||
        sport_1_cycling,
 | 
			
		||||
        sport_2_running,
 | 
			
		||||
        activity_cycling_user_1,
 | 
			
		||||
    ):
 | 
			
		||||
        app: Flask,
 | 
			
		||||
        user_1: User,
 | 
			
		||||
        sport_1_cycling: Sport,
 | 
			
		||||
        sport_2_running: Sport,
 | 
			
		||||
        activity_cycling_user_1: Activity,
 | 
			
		||||
    ) -> None:
 | 
			
		||||
        activity_short_id = activity_cycling_user_1.short_id
 | 
			
		||||
        client = app.test_client()
 | 
			
		||||
        resp_login = client.post(
 | 
			
		||||
@@ -266,8 +290,12 @@ class TestEditActivityWithoutGpx:
 | 
			
		||||
        assert records[3]['value'] == 8.0
 | 
			
		||||
 | 
			
		||||
    def test_it_adds_notes_to_an_activity_wo_gpx(
 | 
			
		||||
        self, app, user_1, sport_1_cycling, activity_cycling_user_1
 | 
			
		||||
    ):
 | 
			
		||||
        self,
 | 
			
		||||
        app: Flask,
 | 
			
		||||
        user_1: User,
 | 
			
		||||
        sport_1_cycling: Sport,
 | 
			
		||||
        activity_cycling_user_1: Activity,
 | 
			
		||||
    ) -> None:
 | 
			
		||||
        activity_short_id = activity_cycling_user_1.short_id
 | 
			
		||||
        client = app.test_client()
 | 
			
		||||
        resp_login = client.post(
 | 
			
		||||
@@ -338,8 +366,13 @@ class TestEditActivityWithoutGpx:
 | 
			
		||||
        assert records[3]['value'] == 10.0
 | 
			
		||||
 | 
			
		||||
    def test_returns_403_when_editing_an_activity_wo_gpx_from_different_user(
 | 
			
		||||
        self, app, user_1, user_2, sport_1_cycling, activity_cycling_user_2
 | 
			
		||||
    ):
 | 
			
		||||
        self,
 | 
			
		||||
        app: Flask,
 | 
			
		||||
        user_1: User,
 | 
			
		||||
        user_2: User,
 | 
			
		||||
        sport_1_cycling: Sport,
 | 
			
		||||
        activity_cycling_user_2: Activity,
 | 
			
		||||
    ) -> None:
 | 
			
		||||
        client = app.test_client()
 | 
			
		||||
        resp_login = client.post(
 | 
			
		||||
            '/api/auth/login',
 | 
			
		||||
@@ -372,12 +405,12 @@ class TestEditActivityWithoutGpx:
 | 
			
		||||
 | 
			
		||||
    def test_it_updates_an_activity_wo_gpx_with_timezone(
 | 
			
		||||
        self,
 | 
			
		||||
        app,
 | 
			
		||||
        user_1_paris,
 | 
			
		||||
        sport_1_cycling,
 | 
			
		||||
        sport_2_running,
 | 
			
		||||
        activity_cycling_user_1,
 | 
			
		||||
    ):
 | 
			
		||||
        app: Flask,
 | 
			
		||||
        user_1_paris: User,
 | 
			
		||||
        sport_1_cycling: Sport,
 | 
			
		||||
        sport_2_running: Sport,
 | 
			
		||||
        activity_cycling_user_1: Activity,
 | 
			
		||||
    ) -> None:
 | 
			
		||||
        activity_short_id = activity_cycling_user_1.short_id
 | 
			
		||||
        client = app.test_client()
 | 
			
		||||
        resp_login = client.post(
 | 
			
		||||
@@ -453,12 +486,12 @@ class TestEditActivityWithoutGpx:
 | 
			
		||||
 | 
			
		||||
    def test_it_updates_only_sport_and_distance_an_activity_wo_gpx(
 | 
			
		||||
        self,
 | 
			
		||||
        app,
 | 
			
		||||
        user_1,
 | 
			
		||||
        sport_1_cycling,
 | 
			
		||||
        sport_2_running,
 | 
			
		||||
        activity_cycling_user_1,
 | 
			
		||||
    ):
 | 
			
		||||
        app: Flask,
 | 
			
		||||
        user_1: User,
 | 
			
		||||
        sport_1_cycling: Sport,
 | 
			
		||||
        sport_2_running: Sport,
 | 
			
		||||
        activity_cycling_user_1: Activity,
 | 
			
		||||
    ) -> None:
 | 
			
		||||
        activity_short_id = activity_cycling_user_1.short_id
 | 
			
		||||
        client = app.test_client()
 | 
			
		||||
        resp_login = client.post(
 | 
			
		||||
@@ -525,8 +558,12 @@ class TestEditActivityWithoutGpx:
 | 
			
		||||
        assert records[3]['value'] == 20.0
 | 
			
		||||
 | 
			
		||||
    def test_it_returns_400_if_payload_is_empty(
 | 
			
		||||
        self, app, user_1, sport_1_cycling, activity_cycling_user_1
 | 
			
		||||
    ):
 | 
			
		||||
        self,
 | 
			
		||||
        app: Flask,
 | 
			
		||||
        user_1: User,
 | 
			
		||||
        sport_1_cycling: Sport,
 | 
			
		||||
        activity_cycling_user_1: Activity,
 | 
			
		||||
    ) -> None:
 | 
			
		||||
        client = app.test_client()
 | 
			
		||||
        resp_login = client.post(
 | 
			
		||||
            '/api/auth/login',
 | 
			
		||||
@@ -550,8 +587,12 @@ class TestEditActivityWithoutGpx:
 | 
			
		||||
        assert 'Invalid payload.' in data['message']
 | 
			
		||||
 | 
			
		||||
    def test_it_returns_500_if_date_format_is_invalid(
 | 
			
		||||
        self, app, user_1, sport_1_cycling, activity_cycling_user_1
 | 
			
		||||
    ):
 | 
			
		||||
        self,
 | 
			
		||||
        app: Flask,
 | 
			
		||||
        user_1: User,
 | 
			
		||||
        sport_1_cycling: Sport,
 | 
			
		||||
        activity_cycling_user_1: Activity,
 | 
			
		||||
    ) -> None:
 | 
			
		||||
        client = app.test_client()
 | 
			
		||||
        resp_login = client.post(
 | 
			
		||||
            '/api/auth/login',
 | 
			
		||||
@@ -585,8 +626,8 @@ class TestEditActivityWithoutGpx:
 | 
			
		||||
        )
 | 
			
		||||
 | 
			
		||||
    def test_it_returns_404_if_edited_activity_does_not_exists(
 | 
			
		||||
        self, app, user_1, sport_1_cycling
 | 
			
		||||
    ):
 | 
			
		||||
        self, app: Flask, user_1: User, sport_1_cycling: Sport
 | 
			
		||||
    ) -> None:
 | 
			
		||||
        client = app.test_client()
 | 
			
		||||
        resp_login = client.post(
 | 
			
		||||
            '/api/auth/login',
 | 
			
		||||
@@ -618,8 +659,13 @@ class TestEditActivityWithoutGpx:
 | 
			
		||||
 | 
			
		||||
class TestRefreshActivityWithGpx:
 | 
			
		||||
    def test_refresh_an_activity_with_gpx(
 | 
			
		||||
        self, app, user_1, sport_1_cycling, sport_2_running, gpx_file
 | 
			
		||||
    ):
 | 
			
		||||
        self,
 | 
			
		||||
        app: Flask,
 | 
			
		||||
        user_1: User,
 | 
			
		||||
        sport_1_cycling: Sport,
 | 
			
		||||
        sport_2_running: Sport,
 | 
			
		||||
        gpx_file: str,
 | 
			
		||||
    ) -> None:
 | 
			
		||||
        token, activity_short_id = post_an_activity(app, gpx_file)
 | 
			
		||||
        activity_uuid = decode_short_id(activity_short_id)
 | 
			
		||||
        client = app.test_client()
 | 
			
		||||
 
 | 
			
		||||
@@ -1,21 +1,23 @@
 | 
			
		||||
import json
 | 
			
		||||
import os
 | 
			
		||||
 | 
			
		||||
from fittrackee.activities.models import Activity
 | 
			
		||||
from fittrackee.activities.models import Activity, Sport
 | 
			
		||||
from fittrackee.activities.utils import get_absolute_file_path
 | 
			
		||||
from fittrackee.users.models import User
 | 
			
		||||
from flask import Flask
 | 
			
		||||
 | 
			
		||||
from .utils import get_random_short_id, post_an_activity
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
def get_gpx_filepath(activity_id):
 | 
			
		||||
def get_gpx_filepath(activity_id: int) -> str:
 | 
			
		||||
    activity = Activity.query.filter_by(id=activity_id).first()
 | 
			
		||||
    return activity.gpx
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
class TestDeleteActivityWithGpx:
 | 
			
		||||
    def test_it_deletes_an_activity_with_gpx(
 | 
			
		||||
        self, app, user_1, sport_1_cycling, gpx_file
 | 
			
		||||
    ):
 | 
			
		||||
        self, app: Flask, user_1: User, sport_1_cycling: Sport, gpx_file: str
 | 
			
		||||
    ) -> None:
 | 
			
		||||
        token, activity_short_id = post_an_activity(app, gpx_file)
 | 
			
		||||
        client = app.test_client()
 | 
			
		||||
 | 
			
		||||
@@ -27,8 +29,13 @@ class TestDeleteActivityWithGpx:
 | 
			
		||||
        assert response.status_code == 204
 | 
			
		||||
 | 
			
		||||
    def test_it_returns_403_when_deleting_an_activity_from_different_user(
 | 
			
		||||
        self, app, user_1, user_2, sport_1_cycling, gpx_file
 | 
			
		||||
    ):
 | 
			
		||||
        self,
 | 
			
		||||
        app: Flask,
 | 
			
		||||
        user_1: User,
 | 
			
		||||
        user_2: User,
 | 
			
		||||
        sport_1_cycling: Sport,
 | 
			
		||||
        gpx_file: str,
 | 
			
		||||
    ) -> None:
 | 
			
		||||
        _, activity_short_id = post_an_activity(app, gpx_file)
 | 
			
		||||
        client = app.test_client()
 | 
			
		||||
        resp_login = client.post(
 | 
			
		||||
@@ -51,7 +58,9 @@ class TestDeleteActivityWithGpx:
 | 
			
		||||
        assert 'error' in data['status']
 | 
			
		||||
        assert 'You do not have permissions.' in data['message']
 | 
			
		||||
 | 
			
		||||
    def test_it_returns_404_if_activity_does_not_exist(self, app, user_1):
 | 
			
		||||
    def test_it_returns_404_if_activity_does_not_exist(
 | 
			
		||||
        self, app: Flask, user_1: User
 | 
			
		||||
    ) -> None:
 | 
			
		||||
        client = app.test_client()
 | 
			
		||||
        resp_login = client.post(
 | 
			
		||||
            '/api/auth/login',
 | 
			
		||||
@@ -70,8 +79,8 @@ class TestDeleteActivityWithGpx:
 | 
			
		||||
        assert 'not found' in data['status']
 | 
			
		||||
 | 
			
		||||
    def test_it_returns_500_when_deleting_an_activity_with_gpx_invalid_file(
 | 
			
		||||
        self, app, user_1, sport_1_cycling, gpx_file
 | 
			
		||||
    ):
 | 
			
		||||
        self, app: Flask, user_1: User, sport_1_cycling: Sport, gpx_file: str
 | 
			
		||||
    ) -> None:
 | 
			
		||||
        token, activity_short_id = post_an_activity(app, gpx_file)
 | 
			
		||||
        client = app.test_client()
 | 
			
		||||
        gpx_filepath = get_gpx_filepath(1)
 | 
			
		||||
@@ -95,8 +104,12 @@ class TestDeleteActivityWithGpx:
 | 
			
		||||
 | 
			
		||||
class TestDeleteActivityWithoutGpx:
 | 
			
		||||
    def test_it_deletes_an_activity_wo_gpx(
 | 
			
		||||
        self, app, user_1, sport_1_cycling, activity_cycling_user_1
 | 
			
		||||
    ):
 | 
			
		||||
        self,
 | 
			
		||||
        app: Flask,
 | 
			
		||||
        user_1: User,
 | 
			
		||||
        sport_1_cycling: Sport,
 | 
			
		||||
        activity_cycling_user_1: Activity,
 | 
			
		||||
    ) -> None:
 | 
			
		||||
        client = app.test_client()
 | 
			
		||||
        resp_login = client.post(
 | 
			
		||||
            '/api/auth/login',
 | 
			
		||||
@@ -113,8 +126,13 @@ class TestDeleteActivityWithoutGpx:
 | 
			
		||||
        assert response.status_code == 204
 | 
			
		||||
 | 
			
		||||
    def test_it_returns_403_when_deleting_an_activity_from_different_user(
 | 
			
		||||
        self, app, user_1, user_2, sport_1_cycling, activity_cycling_user_1
 | 
			
		||||
    ):
 | 
			
		||||
        self,
 | 
			
		||||
        app: Flask,
 | 
			
		||||
        user_1: User,
 | 
			
		||||
        user_2: User,
 | 
			
		||||
        sport_1_cycling: Sport,
 | 
			
		||||
        activity_cycling_user_1: Activity,
 | 
			
		||||
    ) -> None:
 | 
			
		||||
        client = app.test_client()
 | 
			
		||||
        resp_login = client.post(
 | 
			
		||||
            '/api/auth/login',
 | 
			
		||||
 
 | 
			
		||||
@@ -1,12 +1,19 @@
 | 
			
		||||
from uuid import UUID
 | 
			
		||||
 | 
			
		||||
from fittrackee.activities.models import Activity, Sport
 | 
			
		||||
from fittrackee.activities.utils_id import decode_short_id
 | 
			
		||||
from fittrackee.users.models import User
 | 
			
		||||
from flask import Flask
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
class TestActivityModel:
 | 
			
		||||
    def test_activity_model(
 | 
			
		||||
        self, app, sport_1_cycling, user_1, activity_cycling_user_1
 | 
			
		||||
    ):
 | 
			
		||||
        self,
 | 
			
		||||
        app: Flask,
 | 
			
		||||
        sport_1_cycling: Sport,
 | 
			
		||||
        user_1: User,
 | 
			
		||||
        activity_cycling_user_1: Activity,
 | 
			
		||||
    ) -> None:
 | 
			
		||||
        activity_cycling_user_1.title = 'Test'
 | 
			
		||||
 | 
			
		||||
        assert 1 == activity_cycling_user_1.id
 | 
			
		||||
@@ -55,12 +62,12 @@ class TestActivityModel:
 | 
			
		||||
 | 
			
		||||
    def test_activity_segment_model(
 | 
			
		||||
        self,
 | 
			
		||||
        app,
 | 
			
		||||
        sport_1_cycling,
 | 
			
		||||
        user_1,
 | 
			
		||||
        activity_cycling_user_1,
 | 
			
		||||
        activity_cycling_user_1_segment,
 | 
			
		||||
    ):
 | 
			
		||||
        app: Flask,
 | 
			
		||||
        sport_1_cycling: Sport,
 | 
			
		||||
        user_1: User,
 | 
			
		||||
        activity_cycling_user_1: Activity,
 | 
			
		||||
        activity_cycling_user_1_segment: Activity,
 | 
			
		||||
    ) -> None:
 | 
			
		||||
        assert (
 | 
			
		||||
            f'<Segment \'{activity_cycling_user_1_segment.segment_id}\' '
 | 
			
		||||
            f'for activity \'{activity_cycling_user_1.short_id}\'>'
 | 
			
		||||
 
 | 
			
		||||
@@ -1,17 +1,21 @@
 | 
			
		||||
import json
 | 
			
		||||
 | 
			
		||||
from fittrackee.activities.models import Activity, Sport
 | 
			
		||||
from fittrackee.users.models import User
 | 
			
		||||
from flask import Flask
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
class TestGetRecords:
 | 
			
		||||
    def test_it_gets_records_for_authenticated_user(
 | 
			
		||||
        self,
 | 
			
		||||
        app,
 | 
			
		||||
        user_1,
 | 
			
		||||
        user_2,
 | 
			
		||||
        sport_1_cycling,
 | 
			
		||||
        sport_2_running,
 | 
			
		||||
        activity_cycling_user_1,
 | 
			
		||||
        activity_cycling_user_2,
 | 
			
		||||
    ):
 | 
			
		||||
        app: Flask,
 | 
			
		||||
        user_1: User,
 | 
			
		||||
        user_2: User,
 | 
			
		||||
        sport_1_cycling: Sport,
 | 
			
		||||
        sport_2_running: Sport,
 | 
			
		||||
        activity_cycling_user_1: Activity,
 | 
			
		||||
        activity_cycling_user_2: Activity,
 | 
			
		||||
    ) -> None:
 | 
			
		||||
        client = app.test_client()
 | 
			
		||||
        resp_login = client.post(
 | 
			
		||||
            '/api/auth/login',
 | 
			
		||||
@@ -85,13 +89,13 @@ class TestGetRecords:
 | 
			
		||||
 | 
			
		||||
    def test_it_gets_no_records_if_user_has_no_activity(
 | 
			
		||||
        self,
 | 
			
		||||
        app,
 | 
			
		||||
        user_1,
 | 
			
		||||
        user_2,
 | 
			
		||||
        sport_1_cycling,
 | 
			
		||||
        sport_2_running,
 | 
			
		||||
        activity_cycling_user_2,
 | 
			
		||||
    ):
 | 
			
		||||
        app: Flask,
 | 
			
		||||
        user_1: User,
 | 
			
		||||
        user_2: User,
 | 
			
		||||
        sport_1_cycling: Sport,
 | 
			
		||||
        sport_2_running: Sport,
 | 
			
		||||
        activity_cycling_user_2: Activity,
 | 
			
		||||
    ) -> None:
 | 
			
		||||
        client = app.test_client()
 | 
			
		||||
        resp_login = client.post(
 | 
			
		||||
            '/api/auth/login',
 | 
			
		||||
@@ -112,8 +116,12 @@ class TestGetRecords:
 | 
			
		||||
        assert len(data['data']['records']) == 0
 | 
			
		||||
 | 
			
		||||
    def test_it_gets_no_records_if_activity_has_zero_value(
 | 
			
		||||
        self, app, user_1, sport_1_cycling, sport_2_running
 | 
			
		||||
    ):
 | 
			
		||||
        self,
 | 
			
		||||
        app: Flask,
 | 
			
		||||
        user_1: User,
 | 
			
		||||
        sport_1_cycling: Sport,
 | 
			
		||||
        sport_2_running: Sport,
 | 
			
		||||
    ) -> None:
 | 
			
		||||
        client = app.test_client()
 | 
			
		||||
        resp_login = client.post(
 | 
			
		||||
            '/api/auth/login',
 | 
			
		||||
@@ -151,8 +159,8 @@ class TestGetRecords:
 | 
			
		||||
        assert len(data['data']['records']) == 0
 | 
			
		||||
 | 
			
		||||
    def test_it_gets_updated_records_after_activities_post_and_patch(
 | 
			
		||||
        self, app, user_1, sport_1_cycling
 | 
			
		||||
    ):
 | 
			
		||||
        self, app: Flask, user_1: User, sport_1_cycling: Sport
 | 
			
		||||
    ) -> None:
 | 
			
		||||
        client = app.test_client()
 | 
			
		||||
        resp_login = client.post(
 | 
			
		||||
            '/api/auth/login',
 | 
			
		||||
@@ -696,8 +704,12 @@ class TestGetRecords:
 | 
			
		||||
        assert len(data['data']['records']) == 0
 | 
			
		||||
 | 
			
		||||
    def test_it_gets_updated_records_after_sport_change(
 | 
			
		||||
        self, app, user_1, sport_1_cycling, sport_2_running
 | 
			
		||||
    ):
 | 
			
		||||
        self,
 | 
			
		||||
        app: Flask,
 | 
			
		||||
        user_1: User,
 | 
			
		||||
        sport_1_cycling: Sport,
 | 
			
		||||
        sport_2_running: Sport,
 | 
			
		||||
    ) -> None:
 | 
			
		||||
        client = app.test_client()
 | 
			
		||||
        resp_login = client.post(
 | 
			
		||||
            '/api/auth/login',
 | 
			
		||||
 
 | 
			
		||||
@@ -1,12 +1,18 @@
 | 
			
		||||
import datetime
 | 
			
		||||
 | 
			
		||||
from fittrackee.activities.models import Record
 | 
			
		||||
from fittrackee.activities.models import Activity, Record, Sport
 | 
			
		||||
from fittrackee.users.models import User
 | 
			
		||||
from flask import Flask
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
class TestRecordModel:
 | 
			
		||||
    def test_record_model(
 | 
			
		||||
        self, app, user_1, sport_1_cycling, activity_cycling_user_1
 | 
			
		||||
    ):
 | 
			
		||||
        self,
 | 
			
		||||
        app: Flask,
 | 
			
		||||
        user_1: User,
 | 
			
		||||
        sport_1_cycling: Sport,
 | 
			
		||||
        activity_cycling_user_1: Activity,
 | 
			
		||||
    ) -> None:
 | 
			
		||||
        record_ld = Record.query.filter_by(
 | 
			
		||||
            user_id=activity_cycling_user_1.user_id,
 | 
			
		||||
            sport_id=activity_cycling_user_1.sport_id,
 | 
			
		||||
@@ -29,8 +35,12 @@ class TestRecordModel:
 | 
			
		||||
        assert 'value' in record_serialize
 | 
			
		||||
 | 
			
		||||
    def test_record_model_with_none_value(
 | 
			
		||||
        self, app, user_1, sport_1_cycling, activity_cycling_user_1
 | 
			
		||||
    ):
 | 
			
		||||
        self,
 | 
			
		||||
        app: Flask,
 | 
			
		||||
        user_1: User,
 | 
			
		||||
        sport_1_cycling: Sport,
 | 
			
		||||
        activity_cycling_user_1: Activity,
 | 
			
		||||
    ) -> None:
 | 
			
		||||
        record_ld = Record.query.filter_by(
 | 
			
		||||
            user_id=activity_cycling_user_1.user_id,
 | 
			
		||||
            sport_id=activity_cycling_user_1.sport_id,
 | 
			
		||||
@@ -49,8 +59,12 @@ class TestRecordModel:
 | 
			
		||||
        assert record_serialize['value'] is None
 | 
			
		||||
 | 
			
		||||
    def test_average_speed_records(
 | 
			
		||||
        self, app, user_1, sport_1_cycling, activity_cycling_user_1
 | 
			
		||||
    ):
 | 
			
		||||
        self,
 | 
			
		||||
        app: Flask,
 | 
			
		||||
        user_1: User,
 | 
			
		||||
        sport_1_cycling: Sport,
 | 
			
		||||
        activity_cycling_user_1: Activity,
 | 
			
		||||
    ) -> None:
 | 
			
		||||
        record_as = Record.query.filter_by(
 | 
			
		||||
            user_id=activity_cycling_user_1.user_id,
 | 
			
		||||
            sport_id=activity_cycling_user_1.sport_id,
 | 
			
		||||
@@ -66,8 +80,12 @@ class TestRecordModel:
 | 
			
		||||
        assert isinstance(record_serialize.get('value'), float)
 | 
			
		||||
 | 
			
		||||
    def test_add_farest_distance_records(
 | 
			
		||||
        self, app, user_1, sport_1_cycling, activity_cycling_user_1
 | 
			
		||||
    ):
 | 
			
		||||
        self,
 | 
			
		||||
        app: Flask,
 | 
			
		||||
        user_1: User,
 | 
			
		||||
        sport_1_cycling: Sport,
 | 
			
		||||
        activity_cycling_user_1: Activity,
 | 
			
		||||
    ) -> None:
 | 
			
		||||
        record_fd = Record.query.filter_by(
 | 
			
		||||
            user_id=activity_cycling_user_1.user_id,
 | 
			
		||||
            sport_id=activity_cycling_user_1.sport_id,
 | 
			
		||||
@@ -83,8 +101,12 @@ class TestRecordModel:
 | 
			
		||||
        assert isinstance(record_serialize.get('value'), float)
 | 
			
		||||
 | 
			
		||||
    def test_add_longest_duration_records(
 | 
			
		||||
        self, app, user_1, sport_1_cycling, activity_cycling_user_1
 | 
			
		||||
    ):
 | 
			
		||||
        self,
 | 
			
		||||
        app: Flask,
 | 
			
		||||
        user_1: User,
 | 
			
		||||
        sport_1_cycling: Sport,
 | 
			
		||||
        activity_cycling_user_1: Activity,
 | 
			
		||||
    ) -> None:
 | 
			
		||||
        record_ld = Record.query.filter_by(
 | 
			
		||||
            user_id=activity_cycling_user_1.user_id,
 | 
			
		||||
            sport_id=activity_cycling_user_1.sport_id,
 | 
			
		||||
@@ -100,8 +122,12 @@ class TestRecordModel:
 | 
			
		||||
        assert isinstance(record_serialize.get('value'), str)
 | 
			
		||||
 | 
			
		||||
    def test_add_longest_duration_records_with_zero(
 | 
			
		||||
        self, app, user_1, sport_1_cycling, activity_cycling_user_1
 | 
			
		||||
    ):
 | 
			
		||||
        self,
 | 
			
		||||
        app: Flask,
 | 
			
		||||
        user_1: User,
 | 
			
		||||
        sport_1_cycling: Sport,
 | 
			
		||||
        activity_cycling_user_1: Activity,
 | 
			
		||||
    ) -> None:
 | 
			
		||||
        record_ld = Record.query.filter_by(
 | 
			
		||||
            user_id=activity_cycling_user_1.user_id,
 | 
			
		||||
            sport_id=activity_cycling_user_1.sport_id,
 | 
			
		||||
@@ -118,8 +144,12 @@ class TestRecordModel:
 | 
			
		||||
        assert isinstance(record_serialize.get('value'), str)
 | 
			
		||||
 | 
			
		||||
    def test_max_speed_records_no_value(
 | 
			
		||||
        self, app, user_1, sport_1_cycling, activity_cycling_user_1
 | 
			
		||||
    ):
 | 
			
		||||
        self,
 | 
			
		||||
        app: Flask,
 | 
			
		||||
        user_1: User,
 | 
			
		||||
        sport_1_cycling: Sport,
 | 
			
		||||
        activity_cycling_user_1: Activity,
 | 
			
		||||
    ) -> None:
 | 
			
		||||
        record_ms = Record.query.filter_by(
 | 
			
		||||
            user_id=activity_cycling_user_1.user_id,
 | 
			
		||||
            sport_id=activity_cycling_user_1.sport_id,
 | 
			
		||||
 
 | 
			
		||||
@@ -1,5 +1,9 @@
 | 
			
		||||
import json
 | 
			
		||||
 | 
			
		||||
from fittrackee.activities.models import Activity, Sport
 | 
			
		||||
from fittrackee.users.models import User
 | 
			
		||||
from flask import Flask
 | 
			
		||||
 | 
			
		||||
expected_sport_1_cycling_result = {
 | 
			
		||||
    'id': 1,
 | 
			
		||||
    'label': 'Cycling',
 | 
			
		||||
@@ -32,8 +36,12 @@ expected_sport_1_cycling_inactive_admin_result['has_activities'] = False
 | 
			
		||||
 | 
			
		||||
class TestGetSports:
 | 
			
		||||
    def test_it_gets_all_sports(
 | 
			
		||||
        self, app, user_1, sport_1_cycling, sport_2_running
 | 
			
		||||
    ):
 | 
			
		||||
        self,
 | 
			
		||||
        app: Flask,
 | 
			
		||||
        user_1: User,
 | 
			
		||||
        sport_1_cycling: Sport,
 | 
			
		||||
        sport_2_running: Sport,
 | 
			
		||||
    ) -> None:
 | 
			
		||||
        client = app.test_client()
 | 
			
		||||
        resp_login = client.post(
 | 
			
		||||
            '/api/auth/login',
 | 
			
		||||
@@ -57,8 +65,12 @@ class TestGetSports:
 | 
			
		||||
        assert data['data']['sports'][1] == expected_sport_2_running_result
 | 
			
		||||
 | 
			
		||||
    def test_it_gets_all_sports_with_inactive_one(
 | 
			
		||||
        self, app, user_1, sport_1_cycling_inactive, sport_2_running
 | 
			
		||||
    ):
 | 
			
		||||
        self,
 | 
			
		||||
        app: Flask,
 | 
			
		||||
        user_1: User,
 | 
			
		||||
        sport_1_cycling_inactive: Sport,
 | 
			
		||||
        sport_2_running: Sport,
 | 
			
		||||
    ) -> None:
 | 
			
		||||
        client = app.test_client()
 | 
			
		||||
        resp_login = client.post(
 | 
			
		||||
            '/api/auth/login',
 | 
			
		||||
@@ -85,8 +97,12 @@ class TestGetSports:
 | 
			
		||||
        assert data['data']['sports'][1] == expected_sport_2_running_result
 | 
			
		||||
 | 
			
		||||
    def test_it_gets_all_sports_with_admin_rights(
 | 
			
		||||
        self, app, user_1_admin, sport_1_cycling_inactive, sport_2_running
 | 
			
		||||
    ):
 | 
			
		||||
        self,
 | 
			
		||||
        app: Flask,
 | 
			
		||||
        user_1_admin: User,
 | 
			
		||||
        sport_1_cycling_inactive: Sport,
 | 
			
		||||
        sport_2_running: Sport,
 | 
			
		||||
    ) -> None:
 | 
			
		||||
        client = app.test_client()
 | 
			
		||||
        resp_login = client.post(
 | 
			
		||||
            '/api/auth/login',
 | 
			
		||||
@@ -118,7 +134,9 @@ class TestGetSports:
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
class TestGetSport:
 | 
			
		||||
    def test_it_gets_a_sport(self, app, user_1, sport_1_cycling):
 | 
			
		||||
    def test_it_gets_a_sport(
 | 
			
		||||
        self, app: Flask, user_1: User, sport_1_cycling: Sport
 | 
			
		||||
    ) -> None:
 | 
			
		||||
        client = app.test_client()
 | 
			
		||||
        resp_login = client.post(
 | 
			
		||||
            '/api/auth/login',
 | 
			
		||||
@@ -140,7 +158,9 @@ class TestGetSport:
 | 
			
		||||
        assert len(data['data']['sports']) == 1
 | 
			
		||||
        assert data['data']['sports'][0] == expected_sport_1_cycling_result
 | 
			
		||||
 | 
			
		||||
    def test_it_returns_404_if_sport_does_not_exist(self, app, user_1):
 | 
			
		||||
    def test_it_returns_404_if_sport_does_not_exist(
 | 
			
		||||
        self, app: Flask, user_1: User
 | 
			
		||||
    ) -> None:
 | 
			
		||||
        client = app.test_client()
 | 
			
		||||
        resp_login = client.post(
 | 
			
		||||
            '/api/auth/login',
 | 
			
		||||
@@ -162,8 +182,8 @@ class TestGetSport:
 | 
			
		||||
        assert len(data['data']['sports']) == 0
 | 
			
		||||
 | 
			
		||||
    def test_it_gets_a_inactive_sport(
 | 
			
		||||
        self, app, user_1, sport_1_cycling_inactive
 | 
			
		||||
    ):
 | 
			
		||||
        self, app: Flask, user_1: User, sport_1_cycling_inactive: Sport
 | 
			
		||||
    ) -> None:
 | 
			
		||||
        client = app.test_client()
 | 
			
		||||
        resp_login = client.post(
 | 
			
		||||
            '/api/auth/login',
 | 
			
		||||
@@ -189,8 +209,8 @@ class TestGetSport:
 | 
			
		||||
        )
 | 
			
		||||
 | 
			
		||||
    def test_it_get_an_inactive_sport_with_admin_rights(
 | 
			
		||||
        self, app, user_1_admin, sport_1_cycling_inactive
 | 
			
		||||
    ):
 | 
			
		||||
        self, app: Flask, user_1_admin: User, sport_1_cycling_inactive: Sport
 | 
			
		||||
    ) -> None:
 | 
			
		||||
        client = app.test_client()
 | 
			
		||||
        resp_login = client.post(
 | 
			
		||||
            '/api/auth/login',
 | 
			
		||||
@@ -219,7 +239,9 @@ class TestGetSport:
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
class TestUpdateSport:
 | 
			
		||||
    def test_it_disables_a_sport(self, app, user_1_admin, sport_1_cycling):
 | 
			
		||||
    def test_it_disables_a_sport(
 | 
			
		||||
        self, app: Flask, user_1_admin: User, sport_1_cycling: Sport
 | 
			
		||||
    ) -> None:
 | 
			
		||||
        client = app.test_client()
 | 
			
		||||
        resp_login = client.post(
 | 
			
		||||
            '/api/auth/login',
 | 
			
		||||
@@ -246,7 +268,9 @@ class TestUpdateSport:
 | 
			
		||||
        assert data['data']['sports'][0]['is_active'] is False
 | 
			
		||||
        assert data['data']['sports'][0]['has_activities'] is False
 | 
			
		||||
 | 
			
		||||
    def test_it_enables_a_sport(self, app, user_1_admin, sport_1_cycling):
 | 
			
		||||
    def test_it_enables_a_sport(
 | 
			
		||||
        self, app: Flask, user_1_admin: User, sport_1_cycling: Sport
 | 
			
		||||
    ) -> None:
 | 
			
		||||
        sport_1_cycling.is_active = False
 | 
			
		||||
        client = app.test_client()
 | 
			
		||||
        resp_login = client.post(
 | 
			
		||||
@@ -275,8 +299,12 @@ class TestUpdateSport:
 | 
			
		||||
        assert data['data']['sports'][0]['has_activities'] is False
 | 
			
		||||
 | 
			
		||||
    def test_it_disables_a_sport_with_activities(
 | 
			
		||||
        self, app, user_1_admin, sport_1_cycling, activity_cycling_user_1
 | 
			
		||||
    ):
 | 
			
		||||
        self,
 | 
			
		||||
        app: Flask,
 | 
			
		||||
        user_1_admin: User,
 | 
			
		||||
        sport_1_cycling: Sport,
 | 
			
		||||
        activity_cycling_user_1: Activity,
 | 
			
		||||
    ) -> None:
 | 
			
		||||
        client = app.test_client()
 | 
			
		||||
        resp_login = client.post(
 | 
			
		||||
            '/api/auth/login',
 | 
			
		||||
@@ -304,8 +332,12 @@ class TestUpdateSport:
 | 
			
		||||
        assert data['data']['sports'][0]['has_activities'] is True
 | 
			
		||||
 | 
			
		||||
    def test_it_enables_a_sport_with_activities(
 | 
			
		||||
        self, app, user_1_admin, sport_1_cycling, activity_cycling_user_1
 | 
			
		||||
    ):
 | 
			
		||||
        self,
 | 
			
		||||
        app: Flask,
 | 
			
		||||
        user_1_admin: User,
 | 
			
		||||
        sport_1_cycling: Sport,
 | 
			
		||||
        activity_cycling_user_1: Activity,
 | 
			
		||||
    ) -> None:
 | 
			
		||||
        sport_1_cycling.is_active = False
 | 
			
		||||
        client = app.test_client()
 | 
			
		||||
        resp_login = client.post(
 | 
			
		||||
@@ -334,8 +366,8 @@ class TestUpdateSport:
 | 
			
		||||
        assert data['data']['sports'][0]['has_activities'] is True
 | 
			
		||||
 | 
			
		||||
    def test_returns_error_if_user_has_no_admin_rights(
 | 
			
		||||
        self, app, user_1, sport_1_cycling
 | 
			
		||||
    ):
 | 
			
		||||
        self, app: Flask, user_1: User, sport_1_cycling: Sport
 | 
			
		||||
    ) -> None:
 | 
			
		||||
        client = app.test_client()
 | 
			
		||||
        resp_login = client.post(
 | 
			
		||||
            '/api/auth/login',
 | 
			
		||||
@@ -358,7 +390,9 @@ class TestUpdateSport:
 | 
			
		||||
        assert 'error' in data['status']
 | 
			
		||||
        assert 'You do not have permissions.' in data['message']
 | 
			
		||||
 | 
			
		||||
    def test_returns_error_if_payload_is_invalid(self, app, user_1_admin):
 | 
			
		||||
    def test_returns_error_if_payload_is_invalid(
 | 
			
		||||
        self, app: Flask, user_1_admin: User
 | 
			
		||||
    ) -> None:
 | 
			
		||||
        client = app.test_client()
 | 
			
		||||
        resp_login = client.post(
 | 
			
		||||
            '/api/auth/login',
 | 
			
		||||
@@ -383,7 +417,9 @@ class TestUpdateSport:
 | 
			
		||||
        assert 'error' in data['status']
 | 
			
		||||
        assert 'Invalid payload.' in data['message']
 | 
			
		||||
 | 
			
		||||
    def test_it_returns_error_if_sport_does_not_exist(self, app, user_1_admin):
 | 
			
		||||
    def test_it_returns_error_if_sport_does_not_exist(
 | 
			
		||||
        self, app: Flask, user_1_admin: User
 | 
			
		||||
    ) -> None:
 | 
			
		||||
        client = app.test_client()
 | 
			
		||||
        resp_login = client.post(
 | 
			
		||||
            '/api/auth/login',
 | 
			
		||||
 
 | 
			
		||||
@@ -1,6 +1,15 @@
 | 
			
		||||
from typing import Dict, Optional
 | 
			
		||||
 | 
			
		||||
from fittrackee.activities.models import Activity, Sport
 | 
			
		||||
from fittrackee.users.models import User
 | 
			
		||||
from flask import Flask
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
class TestSportModel:
 | 
			
		||||
    @staticmethod
 | 
			
		||||
    def assert_sport_model(sport, is_admin=False):
 | 
			
		||||
    def assert_sport_model(
 | 
			
		||||
        sport: Sport, is_admin: Optional[bool] = False
 | 
			
		||||
    ) -> Dict:
 | 
			
		||||
        assert 1 == sport.id
 | 
			
		||||
        assert 'Cycling' == sport.label
 | 
			
		||||
        assert '<Sport \'Cycling\'>' == str(sport)
 | 
			
		||||
@@ -11,18 +20,26 @@ class TestSportModel:
 | 
			
		||||
        assert serialized_sport['is_active'] is True
 | 
			
		||||
        return serialized_sport
 | 
			
		||||
 | 
			
		||||
    def test_sport_model(self, app, sport_1_cycling):
 | 
			
		||||
    def test_sport_model(self, app: Flask, sport_1_cycling: Sport) -> None:
 | 
			
		||||
        serialized_sport = self.assert_sport_model(sport_1_cycling)
 | 
			
		||||
        assert 'has_activities' not in serialized_sport
 | 
			
		||||
 | 
			
		||||
    def test_sport_model_with_activity(
 | 
			
		||||
        self, app, sport_1_cycling, user_1, activity_cycling_user_1
 | 
			
		||||
    ):
 | 
			
		||||
        self,
 | 
			
		||||
        app: Flask,
 | 
			
		||||
        sport_1_cycling: Sport,
 | 
			
		||||
        user_1: User,
 | 
			
		||||
        activity_cycling_user_1: Activity,
 | 
			
		||||
    ) -> None:
 | 
			
		||||
        serialized_sport = self.assert_sport_model(sport_1_cycling)
 | 
			
		||||
        assert 'has_activities' not in serialized_sport
 | 
			
		||||
 | 
			
		||||
    def test_sport_model_with_activity_as_admin(
 | 
			
		||||
        self, app, sport_1_cycling, user_1, activity_cycling_user_1
 | 
			
		||||
    ):
 | 
			
		||||
        self,
 | 
			
		||||
        app: Flask,
 | 
			
		||||
        sport_1_cycling: Sport,
 | 
			
		||||
        user_1: User,
 | 
			
		||||
        activity_cycling_user_1: Activity,
 | 
			
		||||
    ) -> None:
 | 
			
		||||
        serialized_sport = self.assert_sport_model(sport_1_cycling, True)
 | 
			
		||||
        assert serialized_sport['has_activities'] is True
 | 
			
		||||
 
 | 
			
		||||
@@ -1,8 +1,14 @@
 | 
			
		||||
import json
 | 
			
		||||
 | 
			
		||||
from fittrackee.activities.models import Activity, Sport
 | 
			
		||||
from fittrackee.users.models import User
 | 
			
		||||
from flask import Flask
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
class TestGetStatsByTime:
 | 
			
		||||
    def test_it_gets_no_stats_when_user_has_no_activities(self, app, user_1):
 | 
			
		||||
    def test_it_gets_no_stats_when_user_has_no_activities(
 | 
			
		||||
        self, app: Flask, user_1: User
 | 
			
		||||
    ) -> None:
 | 
			
		||||
        client = app.test_client()
 | 
			
		||||
        resp_login = client.post(
 | 
			
		||||
            '/api/auth/login',
 | 
			
		||||
@@ -23,7 +29,9 @@ class TestGetStatsByTime:
 | 
			
		||||
        assert 'success' in data['status']
 | 
			
		||||
        assert data['data']['statistics'] == {}
 | 
			
		||||
 | 
			
		||||
    def test_it_returns_error_when_user_does_not_exists(self, app, user_1):
 | 
			
		||||
    def test_it_returns_error_when_user_does_not_exists(
 | 
			
		||||
        self, app: Flask, user_1: User
 | 
			
		||||
    ) -> None:
 | 
			
		||||
        client = app.test_client()
 | 
			
		||||
        resp_login = client.post(
 | 
			
		||||
            '/api/auth/login',
 | 
			
		||||
@@ -46,13 +54,13 @@ class TestGetStatsByTime:
 | 
			
		||||
 | 
			
		||||
    def test_it_returns_error_if_date_format_is_invalid(
 | 
			
		||||
        self,
 | 
			
		||||
        app,
 | 
			
		||||
        user_1,
 | 
			
		||||
        sport_1_cycling,
 | 
			
		||||
        sport_2_running,
 | 
			
		||||
        seven_activities_user_1,
 | 
			
		||||
        activity_running_user_1,
 | 
			
		||||
    ):
 | 
			
		||||
        app: Flask,
 | 
			
		||||
        user_1: User,
 | 
			
		||||
        sport_1_cycling: Sport,
 | 
			
		||||
        sport_2_running: Sport,
 | 
			
		||||
        seven_activities_user_1: Activity,
 | 
			
		||||
        activity_running_user_1: Activity,
 | 
			
		||||
    ) -> None:
 | 
			
		||||
        client = app.test_client()
 | 
			
		||||
        resp_login = client.post(
 | 
			
		||||
            '/api/auth/login',
 | 
			
		||||
@@ -78,13 +86,13 @@ class TestGetStatsByTime:
 | 
			
		||||
 | 
			
		||||
    def test_it_returns_error_if_period_is_invalid(
 | 
			
		||||
        self,
 | 
			
		||||
        app,
 | 
			
		||||
        user_1,
 | 
			
		||||
        sport_1_cycling,
 | 
			
		||||
        sport_2_running,
 | 
			
		||||
        seven_activities_user_1,
 | 
			
		||||
        activity_running_user_1,
 | 
			
		||||
    ):
 | 
			
		||||
        app: Flask,
 | 
			
		||||
        user_1: User,
 | 
			
		||||
        sport_1_cycling: Sport,
 | 
			
		||||
        sport_2_running: Sport,
 | 
			
		||||
        seven_activities_user_1: Activity,
 | 
			
		||||
        activity_running_user_1: Activity,
 | 
			
		||||
    ) -> None:
 | 
			
		||||
        client = app.test_client()
 | 
			
		||||
        resp_login = client.post(
 | 
			
		||||
            '/api/auth/login',
 | 
			
		||||
@@ -107,13 +115,13 @@ class TestGetStatsByTime:
 | 
			
		||||
 | 
			
		||||
    def test_it_gets_stats_by_time_all_activities(
 | 
			
		||||
        self,
 | 
			
		||||
        app,
 | 
			
		||||
        user_1,
 | 
			
		||||
        sport_1_cycling,
 | 
			
		||||
        sport_2_running,
 | 
			
		||||
        seven_activities_user_1,
 | 
			
		||||
        activity_running_user_1,
 | 
			
		||||
    ):
 | 
			
		||||
        app: Flask,
 | 
			
		||||
        user_1: User,
 | 
			
		||||
        sport_1_cycling: Sport,
 | 
			
		||||
        sport_2_running: Sport,
 | 
			
		||||
        seven_activities_user_1: Activity,
 | 
			
		||||
        activity_running_user_1: Activity,
 | 
			
		||||
    ) -> None:
 | 
			
		||||
        client = app.test_client()
 | 
			
		||||
        resp_login = client.post(
 | 
			
		||||
            '/api/auth/login',
 | 
			
		||||
@@ -156,13 +164,13 @@ class TestGetStatsByTime:
 | 
			
		||||
 | 
			
		||||
    def test_it_gets_stats_for_april_2018(
 | 
			
		||||
        self,
 | 
			
		||||
        app,
 | 
			
		||||
        user_1,
 | 
			
		||||
        sport_1_cycling,
 | 
			
		||||
        sport_2_running,
 | 
			
		||||
        seven_activities_user_1,
 | 
			
		||||
        activity_running_user_1,
 | 
			
		||||
    ):
 | 
			
		||||
        app: Flask,
 | 
			
		||||
        user_1: User,
 | 
			
		||||
        sport_1_cycling: Sport,
 | 
			
		||||
        sport_2_running: Sport,
 | 
			
		||||
        seven_activities_user_1: Activity,
 | 
			
		||||
        activity_running_user_1: Activity,
 | 
			
		||||
    ) -> None:
 | 
			
		||||
        client = app.test_client()
 | 
			
		||||
        resp_login = client.post(
 | 
			
		||||
            '/api/auth/login',
 | 
			
		||||
@@ -198,13 +206,13 @@ class TestGetStatsByTime:
 | 
			
		||||
 | 
			
		||||
    def test_it_gets_stats_for_april_2018_with_paris_timezone(
 | 
			
		||||
        self,
 | 
			
		||||
        app,
 | 
			
		||||
        user_1_paris,
 | 
			
		||||
        sport_1_cycling,
 | 
			
		||||
        sport_2_running,
 | 
			
		||||
        seven_activities_user_1,
 | 
			
		||||
        activity_running_user_1,
 | 
			
		||||
    ):
 | 
			
		||||
        app: Flask,
 | 
			
		||||
        user_1_paris: User,
 | 
			
		||||
        sport_1_cycling: Sport,
 | 
			
		||||
        sport_2_running: Sport,
 | 
			
		||||
        seven_activities_user_1: Activity,
 | 
			
		||||
        activity_running_user_1: Activity,
 | 
			
		||||
    ) -> None:
 | 
			
		||||
        client = app.test_client()
 | 
			
		||||
        resp_login = client.post(
 | 
			
		||||
            '/api/auth/login',
 | 
			
		||||
@@ -241,13 +249,13 @@ class TestGetStatsByTime:
 | 
			
		||||
 | 
			
		||||
    def test_it_gets_stats_by_year(
 | 
			
		||||
        self,
 | 
			
		||||
        app,
 | 
			
		||||
        user_1,
 | 
			
		||||
        sport_1_cycling,
 | 
			
		||||
        sport_2_running,
 | 
			
		||||
        seven_activities_user_1,
 | 
			
		||||
        activity_running_user_1,
 | 
			
		||||
    ):
 | 
			
		||||
        app: Flask,
 | 
			
		||||
        user_1: User,
 | 
			
		||||
        sport_1_cycling: Sport,
 | 
			
		||||
        sport_2_running: Sport,
 | 
			
		||||
        seven_activities_user_1: Activity,
 | 
			
		||||
        activity_running_user_1: Activity,
 | 
			
		||||
    ) -> None:
 | 
			
		||||
        client = app.test_client()
 | 
			
		||||
        resp_login = client.post(
 | 
			
		||||
            '/api/auth/login',
 | 
			
		||||
@@ -290,13 +298,13 @@ class TestGetStatsByTime:
 | 
			
		||||
 | 
			
		||||
    def test_it_gets_stats_by_year_for_april_2018(
 | 
			
		||||
        self,
 | 
			
		||||
        app,
 | 
			
		||||
        user_1,
 | 
			
		||||
        sport_1_cycling,
 | 
			
		||||
        sport_2_running,
 | 
			
		||||
        seven_activities_user_1,
 | 
			
		||||
        activity_running_user_1,
 | 
			
		||||
    ):
 | 
			
		||||
        app: Flask,
 | 
			
		||||
        user_1: User,
 | 
			
		||||
        sport_1_cycling: Sport,
 | 
			
		||||
        sport_2_running: Sport,
 | 
			
		||||
        seven_activities_user_1: Activity,
 | 
			
		||||
        activity_running_user_1: Activity,
 | 
			
		||||
    ) -> None:
 | 
			
		||||
        client = app.test_client()
 | 
			
		||||
        resp_login = client.post(
 | 
			
		||||
            '/api/auth/login',
 | 
			
		||||
@@ -332,13 +340,13 @@ class TestGetStatsByTime:
 | 
			
		||||
 | 
			
		||||
    def test_it_gets_stats_by_year_for_april_2018_with_paris_timezone(
 | 
			
		||||
        self,
 | 
			
		||||
        app,
 | 
			
		||||
        user_1_paris,
 | 
			
		||||
        sport_1_cycling,
 | 
			
		||||
        sport_2_running,
 | 
			
		||||
        seven_activities_user_1,
 | 
			
		||||
        activity_running_user_1,
 | 
			
		||||
    ):
 | 
			
		||||
        app: Flask,
 | 
			
		||||
        user_1_paris: User,
 | 
			
		||||
        sport_1_cycling: Sport,
 | 
			
		||||
        sport_2_running: Sport,
 | 
			
		||||
        seven_activities_user_1: Activity,
 | 
			
		||||
        activity_running_user_1: Activity,
 | 
			
		||||
    ) -> None:
 | 
			
		||||
        client = app.test_client()
 | 
			
		||||
        resp_login = client.post(
 | 
			
		||||
            '/api/auth/login',
 | 
			
		||||
@@ -374,13 +382,13 @@ class TestGetStatsByTime:
 | 
			
		||||
 | 
			
		||||
    def test_it_gets_stats_by_month(
 | 
			
		||||
        self,
 | 
			
		||||
        app,
 | 
			
		||||
        user_1,
 | 
			
		||||
        sport_1_cycling,
 | 
			
		||||
        sport_2_running,
 | 
			
		||||
        seven_activities_user_1,
 | 
			
		||||
        activity_running_user_1,
 | 
			
		||||
    ):
 | 
			
		||||
        app: Flask,
 | 
			
		||||
        user_1: User,
 | 
			
		||||
        sport_1_cycling: Sport,
 | 
			
		||||
        sport_2_running: Sport,
 | 
			
		||||
        seven_activities_user_1: Activity,
 | 
			
		||||
        activity_running_user_1: Activity,
 | 
			
		||||
    ) -> None:
 | 
			
		||||
        client = app.test_client()
 | 
			
		||||
        resp_login = client.post(
 | 
			
		||||
            '/api/auth/login',
 | 
			
		||||
@@ -451,13 +459,13 @@ class TestGetStatsByTime:
 | 
			
		||||
 | 
			
		||||
    def test_it_gets_stats_by_month_with_new_york_timezone(
 | 
			
		||||
        self,
 | 
			
		||||
        app,
 | 
			
		||||
        user_1_full,
 | 
			
		||||
        sport_1_cycling,
 | 
			
		||||
        sport_2_running,
 | 
			
		||||
        seven_activities_user_1,
 | 
			
		||||
        activity_running_user_1,
 | 
			
		||||
    ):
 | 
			
		||||
        app: Flask,
 | 
			
		||||
        user_1_full: User,
 | 
			
		||||
        sport_1_cycling: Sport,
 | 
			
		||||
        sport_2_running: Sport,
 | 
			
		||||
        seven_activities_user_1: Activity,
 | 
			
		||||
        activity_running_user_1: Activity,
 | 
			
		||||
    ) -> None:
 | 
			
		||||
        client = app.test_client()
 | 
			
		||||
        resp_login = client.post(
 | 
			
		||||
            '/api/auth/login',
 | 
			
		||||
@@ -528,13 +536,13 @@ class TestGetStatsByTime:
 | 
			
		||||
 | 
			
		||||
    def test_it_gets_stats_by_month_for_april_2018(
 | 
			
		||||
        self,
 | 
			
		||||
        app,
 | 
			
		||||
        user_1,
 | 
			
		||||
        sport_1_cycling,
 | 
			
		||||
        sport_2_running,
 | 
			
		||||
        seven_activities_user_1,
 | 
			
		||||
        activity_running_user_1,
 | 
			
		||||
    ):
 | 
			
		||||
        app: Flask,
 | 
			
		||||
        user_1: User,
 | 
			
		||||
        sport_1_cycling: Sport,
 | 
			
		||||
        sport_2_running: Sport,
 | 
			
		||||
        seven_activities_user_1: Activity,
 | 
			
		||||
        activity_running_user_1: Activity,
 | 
			
		||||
    ) -> None:
 | 
			
		||||
        client = app.test_client()
 | 
			
		||||
        resp_login = client.post(
 | 
			
		||||
            '/api/auth/login',
 | 
			
		||||
@@ -570,13 +578,13 @@ class TestGetStatsByTime:
 | 
			
		||||
 | 
			
		||||
    def test_it_gets_stats_by_week(
 | 
			
		||||
        self,
 | 
			
		||||
        app,
 | 
			
		||||
        user_1_full,
 | 
			
		||||
        sport_1_cycling,
 | 
			
		||||
        sport_2_running,
 | 
			
		||||
        seven_activities_user_1,
 | 
			
		||||
        activity_running_user_1,
 | 
			
		||||
    ):
 | 
			
		||||
        app: Flask,
 | 
			
		||||
        user_1_full: User,
 | 
			
		||||
        sport_1_cycling: Sport,
 | 
			
		||||
        sport_2_running: Sport,
 | 
			
		||||
        seven_activities_user_1: Activity,
 | 
			
		||||
        activity_running_user_1: Activity,
 | 
			
		||||
    ) -> None:
 | 
			
		||||
        client = app.test_client()
 | 
			
		||||
        resp_login = client.post(
 | 
			
		||||
            '/api/auth/login',
 | 
			
		||||
@@ -647,13 +655,13 @@ class TestGetStatsByTime:
 | 
			
		||||
 | 
			
		||||
    def test_it_gets_stats_by_week_for_week_13(
 | 
			
		||||
        self,
 | 
			
		||||
        app,
 | 
			
		||||
        user_1,
 | 
			
		||||
        sport_1_cycling,
 | 
			
		||||
        sport_2_running,
 | 
			
		||||
        seven_activities_user_1,
 | 
			
		||||
        activity_running_user_1,
 | 
			
		||||
    ):
 | 
			
		||||
        app: Flask,
 | 
			
		||||
        user_1: User,
 | 
			
		||||
        sport_1_cycling: Sport,
 | 
			
		||||
        sport_2_running: Sport,
 | 
			
		||||
        seven_activities_user_1: Activity,
 | 
			
		||||
        activity_running_user_1: Activity,
 | 
			
		||||
    ) -> None:
 | 
			
		||||
        client = app.test_client()
 | 
			
		||||
        resp_login = client.post(
 | 
			
		||||
            '/api/auth/login',
 | 
			
		||||
@@ -689,13 +697,13 @@ class TestGetStatsByTime:
 | 
			
		||||
 | 
			
		||||
    def test_if_get_stats_by_week_starting_with_monday(
 | 
			
		||||
        self,
 | 
			
		||||
        app,
 | 
			
		||||
        user_1,
 | 
			
		||||
        sport_1_cycling,
 | 
			
		||||
        sport_2_running,
 | 
			
		||||
        seven_activities_user_1,
 | 
			
		||||
        activity_running_user_1,
 | 
			
		||||
    ):
 | 
			
		||||
        app: Flask,
 | 
			
		||||
        user_1: User,
 | 
			
		||||
        sport_1_cycling: Sport,
 | 
			
		||||
        sport_2_running: Sport,
 | 
			
		||||
        seven_activities_user_1: Activity,
 | 
			
		||||
        activity_running_user_1: Activity,
 | 
			
		||||
    ) -> None:
 | 
			
		||||
        client = app.test_client()
 | 
			
		||||
        resp_login = client.post(
 | 
			
		||||
            '/api/auth/login',
 | 
			
		||||
@@ -766,13 +774,13 @@ class TestGetStatsByTime:
 | 
			
		||||
 | 
			
		||||
    def test_it_gets_stats_by_week_starting_with_monday_for_week_13(
 | 
			
		||||
        self,
 | 
			
		||||
        app,
 | 
			
		||||
        user_1,
 | 
			
		||||
        sport_1_cycling,
 | 
			
		||||
        sport_2_running,
 | 
			
		||||
        seven_activities_user_1,
 | 
			
		||||
        activity_running_user_1,
 | 
			
		||||
    ):
 | 
			
		||||
        app: Flask,
 | 
			
		||||
        user_1: User,
 | 
			
		||||
        sport_1_cycling: Sport,
 | 
			
		||||
        sport_2_running: Sport,
 | 
			
		||||
        seven_activities_user_1: Activity,
 | 
			
		||||
        activity_running_user_1: Activity,
 | 
			
		||||
    ) -> None:
 | 
			
		||||
        client = app.test_client()
 | 
			
		||||
        resp_login = client.post(
 | 
			
		||||
            '/api/auth/login',
 | 
			
		||||
@@ -810,13 +818,13 @@ class TestGetStatsByTime:
 | 
			
		||||
class TestGetStatsBySport:
 | 
			
		||||
    def test_it_gets_stats_by_sport(
 | 
			
		||||
        self,
 | 
			
		||||
        app,
 | 
			
		||||
        user_1,
 | 
			
		||||
        sport_1_cycling,
 | 
			
		||||
        sport_2_running,
 | 
			
		||||
        seven_activities_user_1,
 | 
			
		||||
        activity_running_user_1,
 | 
			
		||||
    ):
 | 
			
		||||
        app: Flask,
 | 
			
		||||
        user_1: User,
 | 
			
		||||
        sport_1_cycling: Sport,
 | 
			
		||||
        sport_2_running: Sport,
 | 
			
		||||
        seven_activities_user_1: Activity,
 | 
			
		||||
        activity_running_user_1: Activity,
 | 
			
		||||
    ) -> None:
 | 
			
		||||
        client = app.test_client()
 | 
			
		||||
        resp_login = client.post(
 | 
			
		||||
            '/api/auth/login',
 | 
			
		||||
@@ -850,13 +858,13 @@ class TestGetStatsBySport:
 | 
			
		||||
 | 
			
		||||
    def test_it_get_stats_for_sport_1(
 | 
			
		||||
        self,
 | 
			
		||||
        app,
 | 
			
		||||
        user_1,
 | 
			
		||||
        sport_1_cycling,
 | 
			
		||||
        sport_2_running,
 | 
			
		||||
        seven_activities_user_1,
 | 
			
		||||
        activity_running_user_1,
 | 
			
		||||
    ):
 | 
			
		||||
        app: Flask,
 | 
			
		||||
        user_1: User,
 | 
			
		||||
        sport_1_cycling: Sport,
 | 
			
		||||
        sport_2_running: Sport,
 | 
			
		||||
        seven_activities_user_1: Activity,
 | 
			
		||||
        activity_running_user_1: Activity,
 | 
			
		||||
    ) -> None:
 | 
			
		||||
        client = app.test_client()
 | 
			
		||||
        resp_login = client.post(
 | 
			
		||||
            '/api/auth/login',
 | 
			
		||||
@@ -885,13 +893,13 @@ class TestGetStatsBySport:
 | 
			
		||||
 | 
			
		||||
    def test_it_returns_errors_if_user_does_not_exist(
 | 
			
		||||
        self,
 | 
			
		||||
        app,
 | 
			
		||||
        user_1,
 | 
			
		||||
        sport_1_cycling,
 | 
			
		||||
        sport_2_running,
 | 
			
		||||
        seven_activities_user_1,
 | 
			
		||||
        activity_running_user_1,
 | 
			
		||||
    ):
 | 
			
		||||
        app: Flask,
 | 
			
		||||
        user_1: User,
 | 
			
		||||
        sport_1_cycling: Sport,
 | 
			
		||||
        sport_2_running: Sport,
 | 
			
		||||
        seven_activities_user_1: Activity,
 | 
			
		||||
        activity_running_user_1: Activity,
 | 
			
		||||
    ) -> None:
 | 
			
		||||
        client = app.test_client()
 | 
			
		||||
        resp_login = client.post(
 | 
			
		||||
            '/api/auth/login',
 | 
			
		||||
@@ -914,13 +922,13 @@ class TestGetStatsBySport:
 | 
			
		||||
 | 
			
		||||
    def test_it_returns_error_if_sport_does_not_exist(
 | 
			
		||||
        self,
 | 
			
		||||
        app,
 | 
			
		||||
        user_1,
 | 
			
		||||
        sport_1_cycling,
 | 
			
		||||
        sport_2_running,
 | 
			
		||||
        seven_activities_user_1,
 | 
			
		||||
        activity_running_user_1,
 | 
			
		||||
    ):
 | 
			
		||||
        app: Flask,
 | 
			
		||||
        user_1: User,
 | 
			
		||||
        sport_1_cycling: Sport,
 | 
			
		||||
        sport_2_running: Sport,
 | 
			
		||||
        seven_activities_user_1: Activity,
 | 
			
		||||
        activity_running_user_1: Activity,
 | 
			
		||||
    ) -> None:
 | 
			
		||||
        client = app.test_client()
 | 
			
		||||
        resp_login = client.post(
 | 
			
		||||
            '/api/auth/login',
 | 
			
		||||
@@ -943,13 +951,13 @@ class TestGetStatsBySport:
 | 
			
		||||
 | 
			
		||||
    def test_it_returns_error_if_sport_id_is_invalid(
 | 
			
		||||
        self,
 | 
			
		||||
        app,
 | 
			
		||||
        user_1,
 | 
			
		||||
        sport_1_cycling,
 | 
			
		||||
        sport_2_running,
 | 
			
		||||
        seven_activities_user_1,
 | 
			
		||||
        activity_running_user_1,
 | 
			
		||||
    ):
 | 
			
		||||
        app: Flask,
 | 
			
		||||
        user_1: User,
 | 
			
		||||
        sport_1_cycling: Sport,
 | 
			
		||||
        sport_2_running: Sport,
 | 
			
		||||
        seven_activities_user_1: Activity,
 | 
			
		||||
        activity_running_user_1: Activity,
 | 
			
		||||
    ) -> None:
 | 
			
		||||
        client = app.test_client()
 | 
			
		||||
        resp_login = client.post(
 | 
			
		||||
            '/api/auth/login',
 | 
			
		||||
@@ -976,8 +984,8 @@ class TestGetStatsBySport:
 | 
			
		||||
 | 
			
		||||
class TestGetAllStats:
 | 
			
		||||
    def test_it_returns_all_stats_when_users_have_no_activities(
 | 
			
		||||
        self, app, user_1_admin, user_2
 | 
			
		||||
    ):
 | 
			
		||||
        self, app: Flask, user_1_admin: User, user_2: User
 | 
			
		||||
    ) -> None:
 | 
			
		||||
        client = app.test_client()
 | 
			
		||||
        resp_login = client.post(
 | 
			
		||||
            '/api/auth/login',
 | 
			
		||||
@@ -1005,16 +1013,16 @@ class TestGetAllStats:
 | 
			
		||||
 | 
			
		||||
    def test_it_gets_app_all_stats_with_activities(
 | 
			
		||||
        self,
 | 
			
		||||
        app,
 | 
			
		||||
        user_1_admin,
 | 
			
		||||
        user_2,
 | 
			
		||||
        user_3,
 | 
			
		||||
        sport_1_cycling,
 | 
			
		||||
        sport_2_running,
 | 
			
		||||
        activity_cycling_user_1,
 | 
			
		||||
        activity_cycling_user_2,
 | 
			
		||||
        activity_running_user_1,
 | 
			
		||||
    ):
 | 
			
		||||
        app: Flask,
 | 
			
		||||
        user_1_admin: User,
 | 
			
		||||
        user_2: User,
 | 
			
		||||
        user_3: User,
 | 
			
		||||
        sport_1_cycling: Sport,
 | 
			
		||||
        sport_2_running: Sport,
 | 
			
		||||
        activity_cycling_user_1: Activity,
 | 
			
		||||
        activity_cycling_user_2: Activity,
 | 
			
		||||
        activity_running_user_1: Activity,
 | 
			
		||||
    ) -> None:
 | 
			
		||||
        client = app.test_client()
 | 
			
		||||
        resp_login = client.post(
 | 
			
		||||
            '/api/auth/login',
 | 
			
		||||
@@ -1042,16 +1050,16 @@ class TestGetAllStats:
 | 
			
		||||
 | 
			
		||||
    def test_it_returns_error_if_user_has_no_admin_rights(
 | 
			
		||||
        self,
 | 
			
		||||
        app,
 | 
			
		||||
        user_1,
 | 
			
		||||
        user_2,
 | 
			
		||||
        user_3,
 | 
			
		||||
        sport_1_cycling,
 | 
			
		||||
        sport_2_running,
 | 
			
		||||
        activity_cycling_user_1,
 | 
			
		||||
        activity_cycling_user_2,
 | 
			
		||||
        activity_running_user_1,
 | 
			
		||||
    ):
 | 
			
		||||
        app: Flask,
 | 
			
		||||
        user_1: User,
 | 
			
		||||
        user_2: User,
 | 
			
		||||
        user_3: User,
 | 
			
		||||
        sport_1_cycling: Sport,
 | 
			
		||||
        sport_2_running: Sport,
 | 
			
		||||
        activity_cycling_user_1: Activity,
 | 
			
		||||
        activity_cycling_user_2: Activity,
 | 
			
		||||
        activity_running_user_1: Activity,
 | 
			
		||||
    ) -> None:
 | 
			
		||||
        client = app.test_client()
 | 
			
		||||
        resp_login = client.post(
 | 
			
		||||
            '/api/auth/login',
 | 
			
		||||
 
 | 
			
		||||
@@ -1,15 +1,17 @@
 | 
			
		||||
import json
 | 
			
		||||
from io import BytesIO
 | 
			
		||||
from typing import Tuple
 | 
			
		||||
from uuid import uuid4
 | 
			
		||||
 | 
			
		||||
from fittrackee.activities.utils_id import encode_uuid
 | 
			
		||||
from flask import Flask
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
def get_random_short_id():
 | 
			
		||||
def get_random_short_id() -> str:
 | 
			
		||||
    return encode_uuid(uuid4())
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
def post_an_activity(app, gpx_file):
 | 
			
		||||
def post_an_activity(app: Flask, gpx_file: str) -> Tuple[str, str]:
 | 
			
		||||
    client = app.test_client()
 | 
			
		||||
    resp_login = client.post(
 | 
			
		||||
        '/api/auth/login',
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user