API - return weather api provider in app config route

This commit is contained in:
Sam 2022-12-28 11:43:36 +01:00
parent 52d31a68db
commit cd66952db9
3 changed files with 44 additions and 5 deletions

View File

@ -47,8 +47,9 @@ def get_application_config() -> Union[Dict, HttpResponse]:
"max_single_file_size": 1048576,
"max_users": 0,
"max_zip_file_size": 10485760,
"map_attribution": "&copy; <a href=http://www.openstreetmap.org/copyright>OpenStreetMap</a> contributors"
"version": "0.7.10"
"map_attribution": "&copy; <a href=http://www.openstreetmap.org/copyright>OpenStreetMap</a> contributors",
"version": "0.7.10",
"weather_provider": "darksky"
},
"status": "success"
}
@ -99,8 +100,9 @@ def update_application_config(auth_user: User) -> Union[Dict, HttpResponse]:
"max_single_file_size": 1048576,
"max_users": 10,
"max_zip_file_size": 10485760,
"map_attribution": "&copy; <a href=http://www.openstreetmap.org/copyright>OpenStreetMap</a> contributors"
"version": "0.7.10"
"map_attribution": "&copy; <a href=http://www.openstreetmap.org/copyright>OpenStreetMap</a> contributors",
"version": "0.7.10",
"weather_provider": "darksky"
},
"status": "success"
}

View File

@ -1,3 +1,4 @@
import os
from typing import Dict
from flask import current_app
@ -43,6 +44,7 @@ class AppConfig(BaseModel):
return current_app.config['TILE_SERVER']['ATTRIBUTION']
def serialize(self) -> Dict:
weather_provider = os.getenv('WEATHER_API_PROVIDER', '').lower()
return {
'admin_contact': self.admin_contact,
'gpx_limit_import': self.gpx_limit_import,
@ -53,6 +55,11 @@ class AppConfig(BaseModel):
'max_users': self.max_users,
'map_attribution': self.map_attribution,
'version': VERSION,
'weather_provider': (
weather_provider
if weather_provider in ['darksky', 'visualcrossing']
else None
),
}

View File

@ -1,3 +1,4 @@
import pytest
from flask import Flask
from fittrackee import VERSION
@ -6,7 +7,10 @@ from fittrackee.users.models import User
class TestConfigModel:
def test_application_config(self, app: Flask) -> None:
def test_application_config(
self, app: Flask, monkeypatch: pytest.MonkeyPatch
) -> None:
monkeypatch.setenv('WEATHER_API_PROVIDER', 'darksky')
app_config = AppConfig.query.first()
app_config.admin_contact = 'admin@example.com'
@ -40,6 +44,7 @@ class TestConfigModel:
== 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
@ -58,3 +63,28 @@ class TestConfigModel:
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
)