API - refacto tests
move some tests in models tests (to simplify api tests) + doc fix
This commit is contained in:
@ -4,17 +4,18 @@ from typing import Optional
|
||||
import pytest
|
||||
from flask import Flask
|
||||
|
||||
import fittrackee
|
||||
from fittrackee.application.models import AppConfig
|
||||
from fittrackee.users.models import User
|
||||
|
||||
from ..mixins import ApiTestCaseMixin
|
||||
from ..utils import jsonify_dict
|
||||
|
||||
|
||||
class TestGetConfig(ApiTestCaseMixin):
|
||||
def test_it_gets_application_config_for_unauthenticated_user(
|
||||
self, app: Flask
|
||||
) -> None:
|
||||
app_config = AppConfig.query.first()
|
||||
client = app.test_client()
|
||||
|
||||
response = client.get('/api/config')
|
||||
@ -22,18 +23,7 @@ class TestGetConfig(ApiTestCaseMixin):
|
||||
data = json.loads(response.data.decode())
|
||||
assert response.status_code == 200
|
||||
assert 'success' in data['status']
|
||||
assert data['data']['admin_contact'] is None
|
||||
assert data['data']['gpx_limit_import'] == 10
|
||||
assert data['data']['is_registration_enabled'] is True
|
||||
assert data['data']['max_single_file_size'] == 1048576
|
||||
assert data['data']['max_zip_file_size'] == 10485760
|
||||
assert data['data']['max_users'] == 100
|
||||
assert data['data']['map_attribution'] == (
|
||||
'© <a href="http://www.openstreetmap.org/copyright" '
|
||||
'target="_blank" rel="noopener noreferrer">OpenStreetMap</a> '
|
||||
'contributors'
|
||||
)
|
||||
assert data['data']['version'] == fittrackee.__version__
|
||||
assert data['data'] == jsonify_dict(app_config.serialize())
|
||||
|
||||
def test_it_gets_application_config(
|
||||
self, app: Flask, user_1: User
|
||||
|
@ -1,22 +1,51 @@
|
||||
from flask import Flask
|
||||
|
||||
from fittrackee import VERSION
|
||||
from fittrackee.application.models import AppConfig
|
||||
from fittrackee.users.models import User
|
||||
|
||||
|
||||
class TestConfigModel:
|
||||
def test_application_config(self, app: Flask) -> None:
|
||||
app_config = AppConfig.query.first()
|
||||
assert 1 == app_config.id
|
||||
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']
|
||||
)
|
||||
|
||||
serialized_app_config = app_config.serialize()
|
||||
assert serialized_app_config['gpx_limit_import'] == 10
|
||||
assert serialized_app_config['is_registration_enabled'] is True
|
||||
assert serialized_app_config['max_single_file_size'] == 1048576
|
||||
assert serialized_app_config['max_zip_file_size'] == 10485760
|
||||
assert serialized_app_config['max_users'] == 100
|
||||
assert serialized_app_config['map_attribution'] == (
|
||||
'© <a href="http://www.openstreetmap.org/copyright" '
|
||||
'target="_blank" rel="noopener noreferrer">OpenStreetMap</a> '
|
||||
'contributors'
|
||||
assert (
|
||||
serialized_app_config['admin_contact'] == app_config.admin_contact
|
||||
)
|
||||
assert 'admin_contact' in serialized_app_config
|
||||
assert (
|
||||
serialized_app_config['gpx_limit_import']
|
||||
== app_config.gpx_limit_import
|
||||
)
|
||||
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
|
||||
|
||||
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
|
||||
|
Reference in New Issue
Block a user