FitTrackee/fittrackee/tests/application/test_app_config_model.py

118 lines
4.0 KiB
Python
Raw Permalink Normal View History

2023-02-25 14:06:49 +01:00
from datetime import datetime
import pytest
2021-01-02 19:28:03 +01:00
from flask import Flask
from fittrackee import VERSION
2021-01-20 16:47:00 +01:00
from fittrackee.application.models import AppConfig
from fittrackee.users.models import User
2021-01-20 16:47:00 +01:00
2023-02-25 14:06:49 +01:00
from ..utils import random_string
2020-05-10 15:55:56 +02:00
class TestConfigModel:
def test_application_config(
self, app: Flask, monkeypatch: pytest.MonkeyPatch
) -> None:
monkeypatch.setenv('WEATHER_API_PROVIDER', 'darksky')
2020-05-10 15:55:56 +02:00
app_config = AppConfig.query.first()
app_config.admin_contact = 'admin@example.com'
assert app_config.is_registration_enabled is True
assert (
app_config.map_attribution
== app.config['TILE_SERVER']['ATTRIBUTION']
)
2020-05-10 15:55:56 +02:00
serialized_app_config = app_config.serialize()
assert (
serialized_app_config['admin_contact'] == app_config.admin_contact
)
assert (
serialized_app_config['gpx_limit_import']
== app_config.gpx_limit_import
)
assert serialized_app_config['is_email_sending_enabled'] is True
2020-05-10 15:55:56 +02:00
assert serialized_app_config['is_registration_enabled'] is True
assert (
serialized_app_config['max_single_file_size']
== app_config.max_single_file_size
)
assert (
serialized_app_config['max_zip_file_size']
== app_config.max_zip_file_size
)
assert serialized_app_config['max_users'] == app_config.max_users
assert (
serialized_app_config['map_attribution']
== app_config.map_attribution
)
assert serialized_app_config['version'] == VERSION
assert serialized_app_config['weather_provider'] == 'darksky'
def test_it_returns_registration_disabled_when_users_count_exceeds_limit(
self, app: Flask, user_1: User, user_2: User
) -> None:
app_config = AppConfig.query.first()
app_config.max_users = 2
serialized_app_config = app_config.serialize()
assert app_config.is_registration_enabled is False
assert serialized_app_config['is_registration_enabled'] is False
def test_it_returns_email_sending_disabled_when_no_email_url_provided(
self, app_wo_email_activation: Flask, user_1: User, user_2: User
) -> None:
app_config = AppConfig.query.first()
serialized_app_config = app_config.serialize()
assert serialized_app_config['is_email_sending_enabled'] is False
@pytest.mark.parametrize(
'input_weather_api_provider, expected_weather_provider',
[
('darksky', 'darksky'),
('Visualcrossing', 'visualcrossing'),
('invalid_provider', None),
('', None),
],
)
def test_it_returns_weather_provider(
self,
app: Flask,
input_weather_api_provider: str,
expected_weather_provider: str,
monkeypatch: pytest.MonkeyPatch,
) -> None:
monkeypatch.setenv('WEATHER_API_PROVIDER', input_weather_api_provider)
app_config = AppConfig.query.first()
serialized_app_config = app_config.serialize()
assert (
serialized_app_config['weather_provider']
== expected_weather_provider
)
2023-02-25 14:06:49 +01:00
def test_it_returns_privacy_policy(self, app: Flask) -> None:
app_config = AppConfig.query.first()
privacy_policy = random_string()
privacy_policy_date = datetime.now()
app_config.privacy_policy = privacy_policy
app_config.privacy_policy_date = privacy_policy_date
serialized_app_config = app_config.serialize()
assert serialized_app_config["privacy_policy"] == privacy_policy
assert (
serialized_app_config["privacy_policy_date"] == privacy_policy_date
)
def test_it_returns_about(self, app: Flask) -> None:
app_config = AppConfig.query.first()
about = random_string()
app_config.about = about
serialized_app_config = app_config.serialize()
assert serialized_app_config["about"] == about