API - refactor imports
This commit is contained in:
parent
fdeaf54aa9
commit
d3ce0ad1e5
@ -9,7 +9,7 @@ from flask_dramatiq import Dramatiq
|
||||
from flask_migrate import Migrate
|
||||
from flask_sqlalchemy import SQLAlchemy
|
||||
|
||||
from .email.email import Email
|
||||
from fittrackee.emails.email import Email
|
||||
|
||||
db = SQLAlchemy()
|
||||
bcrypt = Bcrypt()
|
||||
|
@ -5,15 +5,16 @@ import shutil
|
||||
from typing import Dict, Optional
|
||||
|
||||
import gunicorn.app.base
|
||||
from flask import Flask
|
||||
from flask_dramatiq import worker
|
||||
from flask_migrate import upgrade
|
||||
from tqdm import tqdm
|
||||
|
||||
from fittrackee import create_app, db
|
||||
from fittrackee.application.utils import init_config
|
||||
from fittrackee.database_utils import init_database
|
||||
from fittrackee.workouts.models import Workout
|
||||
from fittrackee.workouts.utils import update_workout
|
||||
from flask import Flask
|
||||
from flask_dramatiq import worker
|
||||
from flask_migrate import upgrade
|
||||
from tqdm import tqdm
|
||||
|
||||
HOST = os.getenv('HOST', '0.0.0.0')
|
||||
PORT = os.getenv('PORT', '5000')
|
||||
|
@ -1,15 +1,16 @@
|
||||
from typing import Dict, Union
|
||||
|
||||
from flask import Blueprint, current_app, request
|
||||
from sqlalchemy.orm.exc import MultipleResultsFound, NoResultFound
|
||||
|
||||
from fittrackee import db
|
||||
from fittrackee.responses import (
|
||||
HttpResponse,
|
||||
InvalidPayloadErrorResponse,
|
||||
handle_error_and_return_response,
|
||||
)
|
||||
from flask import Blueprint, current_app, request
|
||||
from sqlalchemy.orm.exc import MultipleResultsFound, NoResultFound
|
||||
from fittrackee.users.decorators import authenticate_as_admin
|
||||
|
||||
from ..users.decorators import authenticate_as_admin
|
||||
from .models import AppConfig
|
||||
from .utils import update_app_config_from_database
|
||||
|
||||
|
@ -1,6 +1,5 @@
|
||||
from typing import Dict
|
||||
|
||||
from fittrackee import db
|
||||
from flask import current_app
|
||||
from sqlalchemy.engine.base import Connection
|
||||
from sqlalchemy.event import listens_for
|
||||
@ -8,7 +7,8 @@ from sqlalchemy.ext.declarative import DeclarativeMeta
|
||||
from sqlalchemy.orm.mapper import Mapper
|
||||
from sqlalchemy.orm.session import Session
|
||||
|
||||
from ..users.models import User
|
||||
from fittrackee import db
|
||||
from fittrackee.users.models import User
|
||||
|
||||
BaseModel: DeclarativeMeta = db.Model
|
||||
|
||||
|
@ -1,9 +1,10 @@
|
||||
import os
|
||||
from typing import Tuple
|
||||
|
||||
from flask import Flask
|
||||
|
||||
from fittrackee import db
|
||||
from fittrackee.users.models import User
|
||||
from flask import Flask
|
||||
|
||||
from .models import AppConfig
|
||||
|
||||
|
@ -26,7 +26,7 @@ class BaseConfig:
|
||||
)
|
||||
PICTURE_ALLOWED_EXTENSIONS = {'jpg', 'png', 'gif'}
|
||||
WORKOUT_ALLOWED_EXTENSIONS = {'gpx', 'zip'}
|
||||
TEMPLATES_FOLDER = os.path.join(current_app.root_path, 'email/templates')
|
||||
TEMPLATES_FOLDER = os.path.join(current_app.root_path, 'emails/templates')
|
||||
UI_URL = os.environ.get('UI_URL')
|
||||
EMAIL_URL = os.environ.get('EMAIL_URL')
|
||||
SENDER_EMAIL = os.environ.get('SENDER_EMAIL')
|
||||
|
@ -1,3 +1,5 @@
|
||||
from flask import Flask
|
||||
|
||||
from fittrackee import db
|
||||
from fittrackee.application.utils import (
|
||||
init_config,
|
||||
@ -5,7 +7,6 @@ from fittrackee.application.utils import (
|
||||
)
|
||||
from fittrackee.users.models import User
|
||||
from fittrackee.workouts.models import Sport
|
||||
from flask import Flask
|
||||
|
||||
|
||||
def init_database(app: Flask) -> None:
|
||||
|
@ -1,10 +1,11 @@
|
||||
from json import dumps
|
||||
from typing import Dict, List, Optional, Union
|
||||
|
||||
from fittrackee import appLog
|
||||
from flask import Response
|
||||
from flask_sqlalchemy import SQLAlchemy
|
||||
|
||||
from fittrackee import appLog
|
||||
|
||||
|
||||
def get_empty_data_for_datatype(data_type: str) -> Union[str, List]:
|
||||
return '' if data_type in ['gpx', 'chart_data'] else []
|
||||
|
@ -1,8 +1,9 @@
|
||||
import json
|
||||
|
||||
from fittrackee.users.models import User
|
||||
from flask import Flask
|
||||
|
||||
from fittrackee.users.models import User
|
||||
|
||||
|
||||
class TestGetConfig:
|
||||
def test_it_gets_application_config(
|
||||
|
@ -1,6 +1,7 @@
|
||||
from fittrackee.application.models import AppConfig
|
||||
from flask import Flask
|
||||
|
||||
from fittrackee.application.models import AppConfig
|
||||
|
||||
|
||||
class TestConfigModel:
|
||||
def test_application_config(self, app: Flask) -> None:
|
||||
|
@ -3,6 +3,7 @@ import os
|
||||
from typing import Generator, Optional
|
||||
|
||||
import pytest
|
||||
|
||||
from fittrackee import create_app, db
|
||||
from fittrackee.application.models import AppConfig
|
||||
from fittrackee.application.utils import update_app_config_from_database
|
||||
|
@ -1,11 +1,12 @@
|
||||
from typing import Any
|
||||
from unittest.mock import Mock, patch
|
||||
|
||||
from fittrackee import email_service
|
||||
from fittrackee.email.email import EmailMessage
|
||||
from flask import Flask
|
||||
|
||||
from ..template_results.password_reset_request import expected_en_text_body
|
||||
from fittrackee import email_service
|
||||
from fittrackee.emails.email import EmailMessage
|
||||
|
||||
from .template_results.password_reset_request import expected_en_text_body
|
||||
|
||||
|
||||
class TestEmailMessage:
|
@ -1,8 +1,9 @@
|
||||
import pytest
|
||||
from fittrackee.email.email import EmailTemplate
|
||||
from flask import Flask
|
||||
|
||||
from ..template_results.password_reset_request import (
|
||||
from fittrackee.emails.email import EmailTemplate
|
||||
|
||||
from .template_results.password_reset_request import (
|
||||
expected_en_html_body,
|
||||
expected_en_text_body,
|
||||
expected_fr_html_body,
|
@ -1,5 +1,9 @@
|
||||
import pytest
|
||||
from fittrackee.email.utils_email import InvalidEmailUrlScheme, parse_email_url
|
||||
|
||||
from fittrackee.emails.utils_email import (
|
||||
InvalidEmailUrlScheme,
|
||||
parse_email_url,
|
||||
)
|
||||
|
||||
|
||||
class TestEmailUrlParser:
|
@ -3,11 +3,12 @@ from datetime import datetime, timedelta
|
||||
from io import BytesIO
|
||||
from unittest.mock import Mock, patch
|
||||
|
||||
from flask import Flask
|
||||
from freezegun import freeze_time
|
||||
|
||||
from fittrackee.users.models import User
|
||||
from fittrackee.users.utils_token import get_user_token
|
||||
from fittrackee.workouts.models import Sport, Workout
|
||||
from flask import Flask
|
||||
from freezegun import freeze_time
|
||||
|
||||
|
||||
class TestUserRegistration:
|
||||
|
@ -3,9 +3,10 @@ from datetime import datetime, timedelta
|
||||
from io import BytesIO
|
||||
from unittest.mock import patch
|
||||
|
||||
from flask import Flask
|
||||
|
||||
from fittrackee.users.models import User
|
||||
from fittrackee.workouts.models import Sport, Workout
|
||||
from flask import Flask
|
||||
|
||||
|
||||
class TestGetUser:
|
||||
|
@ -1,6 +1,7 @@
|
||||
from fittrackee.users.models import User
|
||||
from flask import Flask
|
||||
|
||||
from fittrackee.users.models import User
|
||||
|
||||
|
||||
class TestUserModel:
|
||||
def test_user_model(self, app: Flask, user_1: User) -> None:
|
||||
|
@ -1,8 +1,9 @@
|
||||
import json
|
||||
|
||||
from flask import Flask
|
||||
|
||||
from fittrackee.users.models import User
|
||||
from fittrackee.workouts.models import Sport, Workout
|
||||
from flask import Flask
|
||||
|
||||
|
||||
class TestGetRecords:
|
||||
|
@ -1,8 +1,9 @@
|
||||
import datetime
|
||||
|
||||
from flask import Flask
|
||||
|
||||
from fittrackee.users.models import User
|
||||
from fittrackee.workouts.models import Record, Sport, Workout
|
||||
from flask import Flask
|
||||
|
||||
|
||||
class TestRecordModel:
|
||||
|
@ -1,8 +1,9 @@
|
||||
import json
|
||||
|
||||
from flask import Flask
|
||||
|
||||
from fittrackee.users.models import User
|
||||
from fittrackee.workouts.models import Sport, Workout
|
||||
from flask import Flask
|
||||
|
||||
expected_sport_1_cycling_result = {
|
||||
'id': 1,
|
||||
|
@ -1,8 +1,9 @@
|
||||
from typing import Dict, Optional
|
||||
|
||||
from flask import Flask
|
||||
|
||||
from fittrackee.users.models import User
|
||||
from fittrackee.workouts.models import Sport, Workout
|
||||
from flask import Flask
|
||||
|
||||
|
||||
class TestSportModel:
|
||||
|
@ -1,8 +1,9 @@
|
||||
import json
|
||||
|
||||
from flask import Flask
|
||||
|
||||
from fittrackee.users.models import User
|
||||
from fittrackee.workouts.models import Sport, Workout
|
||||
from flask import Flask
|
||||
|
||||
|
||||
class TestGetStatsByTime:
|
||||
|
@ -1,9 +1,10 @@
|
||||
import json
|
||||
from uuid import uuid4
|
||||
|
||||
from flask import Flask
|
||||
|
||||
from fittrackee.users.models import User
|
||||
from fittrackee.workouts.models import Sport, Workout
|
||||
from flask import Flask
|
||||
|
||||
from .utils import get_random_short_id
|
||||
|
||||
|
@ -4,10 +4,11 @@ from datetime import datetime
|
||||
from io import BytesIO
|
||||
from typing import Dict
|
||||
|
||||
from flask import Flask
|
||||
|
||||
from fittrackee.users.models import User
|
||||
from fittrackee.workouts.models import Sport, Workout
|
||||
from fittrackee.workouts.utils_id import decode_short_id
|
||||
from flask import Flask
|
||||
|
||||
|
||||
def assert_workout_data_with_gpx(data: Dict) -> None:
|
||||
|
@ -1,10 +1,11 @@
|
||||
import json
|
||||
from typing import Dict
|
||||
|
||||
from flask import Flask
|
||||
|
||||
from fittrackee.users.models import User
|
||||
from fittrackee.workouts.models import Sport, Workout
|
||||
from fittrackee.workouts.utils_id import decode_short_id
|
||||
from flask import Flask
|
||||
|
||||
from .utils import get_random_short_id, post_an_workout
|
||||
|
||||
|
@ -1,10 +1,11 @@
|
||||
import json
|
||||
import os
|
||||
|
||||
from flask import Flask
|
||||
|
||||
from fittrackee.users.models import User
|
||||
from fittrackee.workouts.models import Sport, Workout
|
||||
from fittrackee.workouts.utils import get_absolute_file_path
|
||||
from flask import Flask
|
||||
|
||||
from .utils import get_random_short_id, post_an_workout
|
||||
|
||||
|
@ -1,9 +1,10 @@
|
||||
from uuid import UUID
|
||||
|
||||
from flask import Flask
|
||||
|
||||
from fittrackee.users.models import User
|
||||
from fittrackee.workouts.models import Sport, Workout
|
||||
from fittrackee.workouts.utils_id import decode_short_id
|
||||
from flask import Flask
|
||||
|
||||
|
||||
class TestWorkoutModel:
|
||||
|
@ -3,9 +3,10 @@ from io import BytesIO
|
||||
from typing import Tuple
|
||||
from uuid import uuid4
|
||||
|
||||
from fittrackee.workouts.utils_id import encode_uuid
|
||||
from flask import Flask
|
||||
|
||||
from fittrackee.workouts.utils_id import encode_uuid
|
||||
|
||||
|
||||
def get_random_short_id() -> str:
|
||||
return encode_uuid(uuid4())
|
||||
|
@ -3,6 +3,11 @@ import os
|
||||
from typing import Dict, Tuple, Union
|
||||
|
||||
import jwt
|
||||
from flask import Blueprint, current_app, request
|
||||
from sqlalchemy import exc, or_
|
||||
from werkzeug.exceptions import RequestEntityTooLarge
|
||||
from werkzeug.utils import secure_filename
|
||||
|
||||
from fittrackee import appLog, bcrypt, db
|
||||
from fittrackee.responses import (
|
||||
ForbiddenErrorResponse,
|
||||
@ -13,12 +18,8 @@ from fittrackee.responses import (
|
||||
handle_error_and_return_response,
|
||||
)
|
||||
from fittrackee.tasks import reset_password_email
|
||||
from flask import Blueprint, current_app, request
|
||||
from sqlalchemy import exc, or_
|
||||
from werkzeug.exceptions import RequestEntityTooLarge
|
||||
from werkzeug.utils import secure_filename
|
||||
from fittrackee.workouts.utils_files import get_absolute_file_path
|
||||
|
||||
from ..workouts.utils_files import get_absolute_file_path
|
||||
from .decorators import authenticate
|
||||
from .models import User
|
||||
from .utils import (
|
||||
|
@ -1,9 +1,10 @@
|
||||
from functools import wraps
|
||||
from typing import Any, Callable, Union
|
||||
|
||||
from fittrackee.responses import HttpResponse
|
||||
from flask import request
|
||||
|
||||
from fittrackee.responses import HttpResponse
|
||||
|
||||
from .utils import verify_user
|
||||
|
||||
|
||||
|
@ -2,14 +2,15 @@ from datetime import datetime
|
||||
from typing import Dict, Optional, Union
|
||||
|
||||
import jwt
|
||||
from fittrackee import bcrypt, db
|
||||
from flask import current_app
|
||||
from sqlalchemy import func
|
||||
from sqlalchemy.ext.declarative import DeclarativeMeta
|
||||
from sqlalchemy.ext.hybrid import hybrid_property
|
||||
from sqlalchemy.sql.expression import select
|
||||
|
||||
from ..workouts.models import Workout
|
||||
from fittrackee import bcrypt, db
|
||||
from fittrackee.workouts.models import Workout
|
||||
|
||||
from .utils_token import decode_user_token, get_user_token
|
||||
|
||||
BaseModel: DeclarativeMeta = db.Model
|
||||
|
@ -2,6 +2,9 @@ import os
|
||||
import shutil
|
||||
from typing import Any, Dict, Tuple, Union
|
||||
|
||||
from flask import Blueprint, request, send_file
|
||||
from sqlalchemy import exc
|
||||
|
||||
from fittrackee import db
|
||||
from fittrackee.responses import (
|
||||
ForbiddenErrorResponse,
|
||||
@ -11,10 +14,8 @@ from fittrackee.responses import (
|
||||
UserNotFoundErrorResponse,
|
||||
handle_error_and_return_response,
|
||||
)
|
||||
from flask import Blueprint, request, send_file
|
||||
from sqlalchemy import exc
|
||||
from fittrackee.workouts.utils_files import get_absolute_file_path
|
||||
|
||||
from ..workouts.utils_files import get_absolute_file_path
|
||||
from .decorators import authenticate, authenticate_as_admin
|
||||
from .models import User, Workout
|
||||
|
||||
|
@ -3,6 +3,8 @@ from datetime import timedelta
|
||||
from typing import Optional, Tuple, Union
|
||||
|
||||
import humanize
|
||||
from flask import Request, current_app
|
||||
|
||||
from fittrackee.responses import (
|
||||
ForbiddenErrorResponse,
|
||||
HttpResponse,
|
||||
@ -10,7 +12,6 @@ from fittrackee.responses import (
|
||||
PayloadTooLargeErrorResponse,
|
||||
UnauthorizedErrorResponse,
|
||||
)
|
||||
from flask import Request, current_app
|
||||
|
||||
from .models import User
|
||||
|
||||
|
@ -3,7 +3,6 @@ import os
|
||||
from typing import Any, Dict, Optional, Union
|
||||
from uuid import UUID, uuid4
|
||||
|
||||
from fittrackee import db
|
||||
from sqlalchemy.dialects import postgresql
|
||||
from sqlalchemy.engine.base import Connection
|
||||
from sqlalchemy.event import listens_for
|
||||
@ -13,6 +12,8 @@ from sqlalchemy.orm.mapper import Mapper
|
||||
from sqlalchemy.orm.session import Session, object_session
|
||||
from sqlalchemy.types import JSON, Enum
|
||||
|
||||
from fittrackee import db
|
||||
|
||||
from .utils_files import get_absolute_file_path
|
||||
from .utils_format import convert_in_duration, convert_value_to_integer
|
||||
from .utils_id import encode_uuid
|
||||
|
@ -2,7 +2,8 @@ from typing import Dict
|
||||
|
||||
from flask import Blueprint
|
||||
|
||||
from ..users.decorators import authenticate
|
||||
from fittrackee.users.decorators import authenticate
|
||||
|
||||
from .models import Record
|
||||
|
||||
records_blueprint = Blueprint('records', __name__)
|
||||
|
@ -1,5 +1,8 @@
|
||||
from typing import Dict, Union
|
||||
|
||||
from flask import Blueprint, request
|
||||
from sqlalchemy import exc
|
||||
|
||||
from fittrackee import db
|
||||
from fittrackee.responses import (
|
||||
DataNotFoundErrorResponse,
|
||||
@ -7,11 +10,9 @@ from fittrackee.responses import (
|
||||
InvalidPayloadErrorResponse,
|
||||
handle_error_and_return_response,
|
||||
)
|
||||
from flask import Blueprint, request
|
||||
from sqlalchemy import exc
|
||||
from fittrackee.users.decorators import authenticate, authenticate_as_admin
|
||||
from fittrackee.users.models import User
|
||||
|
||||
from ..users.decorators import authenticate, authenticate_as_admin
|
||||
from ..users.models import User
|
||||
from .models import Sport
|
||||
|
||||
sports_blueprint = Blueprint('sports', __name__)
|
||||
|
@ -1,6 +1,9 @@
|
||||
from datetime import datetime, timedelta
|
||||
from typing import Dict, Union
|
||||
|
||||
from flask import Blueprint, request
|
||||
from sqlalchemy import func
|
||||
|
||||
from fittrackee import db
|
||||
from fittrackee.responses import (
|
||||
HttpResponse,
|
||||
@ -9,11 +12,9 @@ from fittrackee.responses import (
|
||||
UserNotFoundErrorResponse,
|
||||
handle_error_and_return_response,
|
||||
)
|
||||
from flask import Blueprint, request
|
||||
from sqlalchemy import func
|
||||
from fittrackee.users.decorators import authenticate, authenticate_as_admin
|
||||
from fittrackee.users.models import User
|
||||
|
||||
from ..users.decorators import authenticate, authenticate_as_admin
|
||||
from ..users.models import User
|
||||
from .models import Sport, Workout
|
||||
from .utils import get_datetime_with_tz, get_upload_dir_size
|
||||
from .utils_format import convert_timedelta_to_integer
|
||||
|
@ -8,14 +8,15 @@ from uuid import UUID
|
||||
|
||||
import gpxpy.gpx
|
||||
import pytz
|
||||
from fittrackee import appLog, db
|
||||
from flask import current_app
|
||||
from sqlalchemy import exc
|
||||
from staticmap import Line, StaticMap
|
||||
from werkzeug.datastructures import FileStorage
|
||||
from werkzeug.utils import secure_filename
|
||||
|
||||
from ..users.models import User
|
||||
from fittrackee import appLog, db
|
||||
from fittrackee.users.models import User
|
||||
|
||||
from .exceptions import WorkoutException
|
||||
from .models import Sport, Workout, WorkoutSegment
|
||||
from .utils_files import get_absolute_file_path
|
||||
|
@ -3,9 +3,10 @@ from typing import Dict, Optional
|
||||
|
||||
import forecastio
|
||||
import pytz
|
||||
from fittrackee import appLog
|
||||
from gpxpy.gpx import GPXRoutePoint
|
||||
|
||||
from fittrackee import appLog
|
||||
|
||||
API_KEY = os.getenv('WEATHER_API_KEY')
|
||||
|
||||
|
||||
|
@ -5,6 +5,9 @@ from datetime import datetime, timedelta
|
||||
from typing import Any, Dict, List, Optional, Tuple, Union
|
||||
|
||||
import requests
|
||||
from flask import Blueprint, Response, current_app, request, send_file
|
||||
from sqlalchemy import exc
|
||||
|
||||
from fittrackee import appLog, db
|
||||
from fittrackee.responses import (
|
||||
DataInvalidPayloadErrorResponse,
|
||||
@ -15,11 +18,13 @@ from fittrackee.responses import (
|
||||
NotFoundErrorResponse,
|
||||
handle_error_and_return_response,
|
||||
)
|
||||
from flask import Blueprint, Response, current_app, request, send_file
|
||||
from sqlalchemy import exc
|
||||
from fittrackee.users.decorators import authenticate
|
||||
from fittrackee.users.utils import (
|
||||
User,
|
||||
can_view_workout,
|
||||
verify_extension_and_size,
|
||||
)
|
||||
|
||||
from ..users.decorators import authenticate
|
||||
from ..users.utils import User, can_view_workout, verify_extension_and_size
|
||||
from .models import Workout
|
||||
from .utils import (
|
||||
WorkoutException,
|
||||
|
@ -70,7 +70,6 @@ include = ".py$"
|
||||
exclude = "migrations"
|
||||
|
||||
[tool.isort]
|
||||
known_third_party = "fittrackee"
|
||||
multi_line_output = 3
|
||||
include_trailing_comma = true
|
||||
force_grid_wrap = 0
|
||||
|
Loading…
Reference in New Issue
Block a user