mirror of
https://github.com/mealie-recipes/mealie.git
synced 2025-06-05 06:35:28 -04:00
* Translate missing items on About page * Localize import summary dialog * Make site menu translation reactive * Localize import options * Include semi colon in string * Move API texts to frontend + better status codes * Provide feedback to user when no meal is planned * Fix API tests after latest rework * Add warning for API changes in changelog * Refactor API texts handling * Refactor API texts handling #2 * Better API feedback * Rearrange strings hierarchy * Add messages upon recipe updated * Fix 'recipe effected' typo * Remove snackbar usage in backend * Translate toolbox * Provide feedback for tags CRUD * Fix messed up merge * Translate sign-up form * Better feedback for sign-up CRUD * Refactor log-in API texts handling * No error message when user is not authenticated * Remove unimportant console log
108 lines
3.6 KiB
Python
108 lines
3.6 KiB
Python
import json
|
|
|
|
import pytest
|
|
from fastapi.testclient import TestClient
|
|
from mealie.schema.settings import SiteSettings
|
|
from mealie.schema.theme import SiteTheme
|
|
from tests.app_routes import AppRoutes
|
|
|
|
|
|
@pytest.fixture(scope="function")
|
|
def default_settings():
|
|
return SiteSettings().dict(by_alias=True)
|
|
|
|
|
|
@pytest.fixture(scope="session")
|
|
def default_theme():
|
|
return SiteTheme().dict()
|
|
|
|
|
|
@pytest.fixture(scope="session")
|
|
def new_theme():
|
|
return {
|
|
"name": "myTestTheme",
|
|
"colors": {
|
|
"primary": "#E58325",
|
|
"accent": "#00457A",
|
|
"secondary": "#973542",
|
|
"success": "#5AB1BB",
|
|
"info": "#4990BA",
|
|
"warning": "#FF4081",
|
|
"error": "#EF5350",
|
|
},
|
|
}
|
|
|
|
|
|
def test_default_settings(api_client: TestClient, api_routes: AppRoutes, default_settings):
|
|
response = api_client.get(api_routes.site_settings)
|
|
|
|
assert response.status_code == 200
|
|
|
|
assert json.loads(response.content) == default_settings
|
|
|
|
|
|
def test_update_settings(api_client: TestClient, api_routes: AppRoutes, default_settings, token):
|
|
default_settings["language"] = "fr"
|
|
default_settings["showRecent"] = False
|
|
|
|
response = api_client.put(api_routes.site_settings, json=default_settings, headers=token)
|
|
|
|
assert response.status_code == 200
|
|
|
|
response = api_client.get(api_routes.site_settings)
|
|
assert json.loads(response.content) == default_settings
|
|
|
|
|
|
def test_default_theme(api_client: TestClient, api_routes: AppRoutes, default_theme):
|
|
response = api_client.get(api_routes.themes_theme_name("default"))
|
|
assert response.status_code == 200
|
|
assert json.loads(response.content) == default_theme
|
|
|
|
|
|
def test_create_theme(api_client: TestClient, api_routes: AppRoutes, new_theme, token):
|
|
|
|
response = api_client.post(api_routes.themes_create, json=new_theme, headers=token)
|
|
assert response.status_code == 201
|
|
|
|
response = api_client.get(api_routes.themes_theme_name(new_theme.get("name")), headers=token)
|
|
assert response.status_code == 200
|
|
assert json.loads(response.content) == new_theme
|
|
|
|
|
|
def test_read_all_themes(api_client: TestClient, api_routes: AppRoutes, default_theme, new_theme):
|
|
response = api_client.get(api_routes.themes)
|
|
assert response.status_code == 200
|
|
assert json.loads(response.content) == [default_theme, new_theme]
|
|
|
|
|
|
def test_read_theme(api_client: TestClient, api_routes: AppRoutes, default_theme, new_theme):
|
|
for theme in [default_theme, new_theme]:
|
|
response = api_client.get(api_routes.themes_theme_name(theme.get("name")))
|
|
assert response.status_code == 200
|
|
assert json.loads(response.content) == theme
|
|
|
|
|
|
def test_update_theme(api_client: TestClient, api_routes: AppRoutes, token, default_theme, new_theme):
|
|
theme_colors = {
|
|
"primary": "#E12345",
|
|
"accent": "#012345",
|
|
"secondary": "#973542",
|
|
"success": "#5AB1BB",
|
|
"info": "#4990BA",
|
|
"warning": "#FF4081",
|
|
"error": "#EF4432",
|
|
}
|
|
|
|
new_theme["colors"] = theme_colors
|
|
response = api_client.put(api_routes.themes_theme_name(new_theme.get("name")), json=new_theme, headers=token)
|
|
assert response.status_code == 200
|
|
response = api_client.get(api_routes.themes_theme_name(new_theme.get("name")))
|
|
assert json.loads(response.content) == new_theme
|
|
|
|
|
|
def test_delete_theme(api_client: TestClient, api_routes: AppRoutes, default_theme, new_theme, token):
|
|
for theme in [default_theme, new_theme]:
|
|
response = api_client.delete(api_routes.themes_theme_name(theme.get("name")), headers=token)
|
|
|
|
assert response.status_code == 200
|