API & Client - max sizes and max number of files must be greater than 0 - #71
This commit is contained in:
@ -276,3 +276,105 @@ class TestUpdateConfig:
|
||||
'Max. size of zip archive must be equal or greater than max. size '
|
||||
'of uploaded files'
|
||||
) in data['message']
|
||||
|
||||
def test_it_raises_error_if_archive_max_size_equals_0(
|
||||
self, app_with_max_single_file_size: Flask, user_1_admin: User
|
||||
) -> None:
|
||||
client = app_with_max_single_file_size.test_client()
|
||||
resp_login = client.post(
|
||||
'/api/auth/login',
|
||||
data=json.dumps(
|
||||
dict(email='admin@example.com', password='12345678')
|
||||
),
|
||||
content_type='application/json',
|
||||
)
|
||||
|
||||
response = client.patch(
|
||||
'/api/config',
|
||||
content_type='application/json',
|
||||
data=json.dumps(
|
||||
dict(
|
||||
max_zip_file_size=0,
|
||||
)
|
||||
),
|
||||
headers=dict(
|
||||
Authorization='Bearer '
|
||||
+ json.loads(resp_login.data.decode())['auth_token']
|
||||
),
|
||||
)
|
||||
|
||||
data = json.loads(response.data.decode())
|
||||
assert response.status_code == 400
|
||||
assert 'error' in data['status']
|
||||
assert (
|
||||
'Max. size of zip archive must be greater than 0'
|
||||
in data['message']
|
||||
)
|
||||
|
||||
def test_it_raises_error_if_files_max_size_equals_0(
|
||||
self, app: Flask, user_1_admin: User
|
||||
) -> None:
|
||||
client = app.test_client()
|
||||
resp_login = client.post(
|
||||
'/api/auth/login',
|
||||
data=json.dumps(
|
||||
dict(email='admin@example.com', password='12345678')
|
||||
),
|
||||
content_type='application/json',
|
||||
)
|
||||
|
||||
response = client.patch(
|
||||
'/api/config',
|
||||
content_type='application/json',
|
||||
data=json.dumps(
|
||||
dict(
|
||||
max_single_file_size=0,
|
||||
)
|
||||
),
|
||||
headers=dict(
|
||||
Authorization='Bearer '
|
||||
+ json.loads(resp_login.data.decode())['auth_token']
|
||||
),
|
||||
)
|
||||
|
||||
data = json.loads(response.data.decode())
|
||||
assert response.status_code == 400
|
||||
assert 'error' in data['status']
|
||||
assert (
|
||||
'Max. size of uploaded files must be greater than 0'
|
||||
in data['message']
|
||||
)
|
||||
|
||||
def test_it_raises_error_if_gpx_limit_import_equals_0(
|
||||
self, app: Flask, user_1_admin: User
|
||||
) -> None:
|
||||
client = app.test_client()
|
||||
resp_login = client.post(
|
||||
'/api/auth/login',
|
||||
data=json.dumps(
|
||||
dict(email='admin@example.com', password='12345678')
|
||||
),
|
||||
content_type='application/json',
|
||||
)
|
||||
|
||||
response = client.patch(
|
||||
'/api/config',
|
||||
content_type='application/json',
|
||||
data=json.dumps(
|
||||
dict(
|
||||
gpx_limit_import=0,
|
||||
)
|
||||
),
|
||||
headers=dict(
|
||||
Authorization='Bearer '
|
||||
+ json.loads(resp_login.data.decode())['auth_token']
|
||||
),
|
||||
)
|
||||
|
||||
data = json.loads(response.data.decode())
|
||||
assert response.status_code == 400
|
||||
assert 'error' in data['status']
|
||||
assert (
|
||||
'Max. files in a zip archive must be greater than 0'
|
||||
in data['message']
|
||||
)
|
||||
|
16
fittrackee/tests/fixtures/fixtures_app.py
vendored
16
fittrackee/tests/fixtures/fixtures_app.py
vendored
@ -11,11 +11,16 @@ from fittrackee.application.utils import update_app_config_from_database
|
||||
def get_app_config(
|
||||
with_config: Optional[bool] = False,
|
||||
max_workouts: Optional[int] = None,
|
||||
max_single_file_size: Optional[int] = None,
|
||||
) -> Optional[AppConfig]:
|
||||
if with_config:
|
||||
config = AppConfig()
|
||||
config.gpx_limit_import = 10 if max_workouts is None else max_workouts
|
||||
config.max_single_file_size = 1 * 1024 * 1024
|
||||
config.max_single_file_size = (
|
||||
1 * 1024 * 1024
|
||||
if max_single_file_size is None
|
||||
else max_single_file_size
|
||||
)
|
||||
config.max_zip_file_size = 1 * 1024 * 1024 * 10
|
||||
config.max_users = 100
|
||||
db.session.add(config)
|
||||
@ -27,6 +32,7 @@ def get_app_config(
|
||||
def get_app(
|
||||
with_config: Optional[bool] = False,
|
||||
max_workouts: Optional[int] = None,
|
||||
max_single_file_size: Optional[int] = None,
|
||||
) -> Generator:
|
||||
app = create_app()
|
||||
with app.app_context():
|
||||
@ -64,6 +70,14 @@ def app_with_max_workouts(monkeypatch: pytest.MonkeyPatch) -> Generator:
|
||||
yield from get_app(with_config=True, max_workouts=2)
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def app_with_max_single_file_size(
|
||||
monkeypatch: pytest.MonkeyPatch,
|
||||
) -> Generator:
|
||||
monkeypatch.setenv('EMAIL_URL', 'smtp://none:none@0.0.0.0:1025')
|
||||
yield from get_app(with_config=True, max_single_file_size=0)
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def app_no_config() -> Generator:
|
||||
yield from get_app(with_config=False)
|
||||
|
Reference in New Issue
Block a user