1
0
Fork 0
mirror of https://github.com/mealie-recipes/mealie.git synced 2025-08-03 12:35:22 +02:00

feature/profile-cards (#391)

* unify format

* pass variables

* remove namespace

* rename

* group-card init

* shuffle + icons

* remove console.logs

* token CRUD

* update changelog

* add profile link

* consolidate mealplan to profile dashboard

* update docs

* add query parameter to search page

* update test routes

* update python depts

* basic token tests

Co-authored-by: hay-kot <hay-kot@pm.me>
This commit is contained in:
Hayden 2021-05-06 21:08:27 -08:00 committed by GitHub
parent f4384167f6
commit 95ec13161f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
41 changed files with 977 additions and 449 deletions

View file

@ -2,25 +2,32 @@ class AppRoutes:
def __init__(self) -> None:
self.prefix = "/api"
self.users_sign_ups = "/api/users/sign-ups"
self.auth_token = "/api/auth/token"
self.auth_token_long = "/api/auth/token/long"
self.auth_refresh = "/api/auth/refresh"
self.users_sign_ups = "/api/users/sign-ups"
self.users = "/api/users"
self.users_self = "/api/users/self"
self.users_api_tokens = "/api/users/api-tokens"
self.groups = "/api/groups"
self.groups_self = "/api/groups/self"
self.recipes = "/api/recipes"
self.recipes_summary = "/api/recipes/summary"
self.recipes_summary_untagged = "/api/recipes/summary/untagged"
self.recipes_summary_uncategorized = "/api/recipes/summary/uncategorized"
self.recipes_category = "/api/recipes/category"
self.recipes_tag = "/api/recipes/tag"
self.categories = "/api/categories"
self.recipes_tags = "/api/recipes/tags/"
self.recipes_create = "/api/recipes/create"
self.recipes_create_url = "/api/recipes/create-url"
self.categories = "/api/categories"
self.categories_empty = "/api/categories/empty"
self.tags = "/api/tags"
self.tags_empty = "/api/tags/empty"
self.about_events = "/api/about/events"
self.meal_plans_all = "/api/meal-plans/all"
self.meal_plans_create = "/api/meal-plans/create"
self.meal_plans_this_week = "/api/meal-plans/this-week"
self.meal_plans_today = "/api/meal-plans/today"
self.meal_plans_today_image = "/api/meal-plans/today/image"
self.site_settings_custom_pages = "/api/site-settings/custom-pages"
self.site_settings = "/api/site-settings"
self.site_settings_webhooks_test = "/api/site-settings/webhooks/test"
@ -30,8 +37,12 @@ class AppRoutes:
self.backups_export_database = "/api/backups/export/database"
self.backups_upload = "/api/backups/upload"
self.migrations = "/api/migrations"
self.debug = "/api/debug"
self.debug_statistics = "/api/debug/statistics"
self.debug_version = "/api/debug/version"
self.debug_last_recipe_json = "/api/debug/last-recipe-json"
self.debug_log = "/api/debug/log"
self.utils_download = "/api/utils/download"
def users_sign_ups_token(self, token):
return f"{self.prefix}/users/sign-ups/{token}"
@ -48,21 +59,36 @@ class AppRoutes:
def users_id_password(self, id):
return f"{self.prefix}/users/{id}/password"
def users_api_tokens_token_id(self, token_id):
return f"{self.prefix}/users/api-tokens/{token_id}"
def groups_id(self, id):
return f"{self.prefix}/groups/{id}"
def categories_category(self, category):
return f"{self.prefix}/categories/{category}"
def recipes_tags_tag(self, tag):
return f"{self.prefix}/recipes/tags/{tag}"
def recipes_recipe_slug(self, recipe_slug):
return f"{self.prefix}/recipes/{recipe_slug}"
def recipes_recipe_slug_image(self, recipe_slug):
return f"{self.prefix}/recipes/{recipe_slug}/image"
def recipes_recipe_slug_assets(self, recipe_slug):
return f"{self.prefix}/recipes/{recipe_slug}/assets"
def categories_category(self, category):
return f"{self.prefix}/categories/{category}"
def tags_tag(self, tag):
return f"{self.prefix}/tags/{tag}"
def media_recipes_recipe_slug_images_file_name(self, recipe_slug, file_name):
return f"{self.prefix}/media/recipes/{recipe_slug}/images/{file_name}"
def media_recipes_recipe_slug_assets_file_name(self, recipe_slug, file_name):
return f"{self.prefix}/media/recipes/{recipe_slug}/assets/{file_name}"
def about_events_id(self, id):
return f"{self.prefix}/about/events/{id}"
def meal_plans_plan_id(self, plan_id):
return f"{self.prefix}/meal-plans/{plan_id}"
@ -72,8 +98,8 @@ class AppRoutes:
def site_settings_custom_pages_id(self, id):
return f"{self.prefix}/site-settings/custom-pages/{id}"
def themes_theme_name(self, theme_name):
return f"{self.prefix}/themes/{theme_name}"
def themes_id(self, id):
return f"{self.prefix}/themes/{id}"
def backups_file_name_download(self, file_name):
return f"{self.prefix}/backups/{file_name}/download"
@ -84,14 +110,14 @@ class AppRoutes:
def backups_file_name_delete(self, file_name):
return f"{self.prefix}/backups/{file_name}/delete"
def migrations_source_file_name_import(self, source, file_name):
return f"{self.prefix}/migrations/{source}/{file_name}/import"
def migrations_import_type_file_name_import(self, import_type, file_name):
return f"{self.prefix}/migrations/{import_type}/{file_name}/import"
def migrations_source_file_name_delete(self, source, file_name):
return f"{self.prefix}/migrations/{source}/{file_name}/delete"
def migrations_import_type_file_name_delete(self, import_type, file_name):
return f"{self.prefix}/migrations/{import_type}/{file_name}/delete"
def migrations_source_upload(self, source):
return f"{self.prefix}/migrations/{source}/upload"
def migrations_import_type_upload(self, import_type):
return f"{self.prefix}/migrations/{import_type}/upload"
def debug_log_num(self, num):
return f"{self.prefix}/debug/log/{num}"

View file

@ -0,0 +1,32 @@
import json
from fastapi.testclient import TestClient
from pytest import fixture
from tests.app_routes import AppRoutes
@fixture
def long_live_token(api_client: TestClient, api_routes: AppRoutes, token):
response = api_client.post(api_routes.users_api_tokens, json={"name": "Test Fixture Token"}, headers=token)
assert response.status_code == 201
return {"Authorization": f"Bearer {json.loads(response.text).get('token')}"}
def test_api_token_creation(api_client: TestClient, api_routes: AppRoutes, token):
response = api_client.post(api_routes.users_api_tokens, json={"name": "Test API Token"}, headers=token)
assert response.status_code == 201
def test_use_token(api_client: TestClient, api_routes: AppRoutes, long_live_token):
response = api_client.get(api_routes.users, headers=long_live_token)
assert response.status_code == 200
def test_delete_token(api_client: TestClient, api_routes: AppRoutes, token):
response = api_client.delete(api_routes.users_api_tokens_token_id(1), headers=token)
assert response.status_code == 200
response = api_client.delete(api_routes.users_api_tokens_token_id(2), headers=token)
assert response.status_code == 200

View file

@ -23,7 +23,7 @@ def chowdown_zip():
def test_upload_chowdown_zip(api_client: TestClient, api_routes: AppRoutes, chowdown_zip: Path, token):
upload_url = api_routes.migrations_source_upload("chowdown")
upload_url = api_routes.migrations_import_type_upload("chowdown")
response = api_client.post(upload_url, files={"archive": chowdown_zip.open("rb")}, headers=token)
assert response.status_code == 200
@ -36,7 +36,7 @@ def test_import_chowdown_directory(api_client: TestClient, api_routes: AppRoutes
api_client.delete(delete_url, headers=token) # TODO: Manage Test Data better
selection = chowdown_zip.name
import_url = api_routes.migrations_source_file_name_import("chowdown", selection)
import_url = api_routes.migrations_import_type_file_name_import("chowdown", selection)
response = api_client.post(import_url, headers=token)
assert response.status_code == 200
@ -49,7 +49,7 @@ def test_import_chowdown_directory(api_client: TestClient, api_routes: AppRoutes
def test_delete_chowdown_migration_data(api_client: TestClient, api_routes: AppRoutes, chowdown_zip: Path, token):
selection = chowdown_zip.name
delete_url = api_routes.migrations_source_file_name_delete("chowdown", selection)
delete_url = api_routes.migrations_import_type_file_name_delete("chowdown", selection)
response = api_client.delete(delete_url, headers=token)
assert response.status_code == 200
@ -71,7 +71,7 @@ def nextcloud_zip():
def test_upload_nextcloud_zip(api_client: TestClient, api_routes: AppRoutes, nextcloud_zip, token):
upload_url = api_routes.migrations_source_upload("nextcloud")
upload_url = api_routes.migrations_import_type_upload("nextcloud")
response = api_client.post(upload_url, files={"archive": nextcloud_zip.open("rb")}, headers=token)
assert response.status_code == 200
@ -81,7 +81,7 @@ def test_upload_nextcloud_zip(api_client: TestClient, api_routes: AppRoutes, nex
def test_import_nextcloud_directory(api_client: TestClient, api_routes: AppRoutes, nextcloud_zip, token):
selection = nextcloud_zip.name
import_url = api_routes.migrations_source_file_name_import("nextcloud", selection)
import_url = api_routes.migrations_import_type_file_name_import("nextcloud", selection)
response = api_client.post(import_url, headers=token)
assert response.status_code == 200
@ -93,7 +93,7 @@ def test_import_nextcloud_directory(api_client: TestClient, api_routes: AppRoute
def test_delete__nextcloud_migration_data(api_client: TestClient, api_routes: AppRoutes, nextcloud_zip: Path, token):
selection = nextcloud_zip.name
delete_url = api_routes.migrations_source_file_name_delete("nextcloud", selection)
delete_url = api_routes.migrations_import_type_file_name_delete("nextcloud", selection)
response = api_client.delete(delete_url, headers=token)
assert response.status_code == 200

View file

@ -55,7 +55,7 @@ def test_update_settings(api_client: TestClient, api_routes: AppRoutes, default_
def test_default_theme(api_client: TestClient, api_routes: AppRoutes, default_theme):
response = api_client.get(api_routes.themes_theme_name(1))
response = api_client.get(api_routes.themes_id(1))
assert response.status_code == 200
assert json.loads(response.content) == default_theme
@ -65,7 +65,7 @@ def test_create_theme(api_client: TestClient, api_routes: AppRoutes, new_theme,
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("id")), headers=token)
response = api_client.get(api_routes.themes_id(new_theme.get("id")), headers=token)
assert response.status_code == 200
assert json.loads(response.content) == new_theme
@ -80,7 +80,7 @@ def test_read_all_themes(api_client: TestClient, api_routes: AppRoutes, default_
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("id")))
response = api_client.get(api_routes.themes_id(theme.get("id")))
assert response.status_code == 200
assert json.loads(response.content) == theme
@ -97,14 +97,14 @@ def test_update_theme(api_client: TestClient, api_routes: AppRoutes, token, defa
}
new_theme["colors"] = theme_colors
response = api_client.put(api_routes.themes_theme_name(new_theme.get("id")), json=new_theme, headers=token)
response = api_client.put(api_routes.themes_id(new_theme.get("id")), json=new_theme, headers=token)
assert response.status_code == 200
response = api_client.get(api_routes.themes_theme_name(new_theme.get("id")))
response = api_client.get(api_routes.themes_id(new_theme.get("id")))
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("id")), headers=token)
response = api_client.delete(api_routes.themes_id(theme.get("id")), headers=token)
assert response.status_code == 200

View file

@ -10,12 +10,12 @@ from tests.app_routes import AppRoutes
@fixture(scope="session")
def default_user():
return UserOut(id=1, fullName="Change Me", email="changeme@email.com", group="Home", admin=True)
return UserOut(id=1, fullName="Change Me", email="changeme@email.com", group="Home", admin=True, tokens=[])
@fixture(scope="session")
def new_user():
return UserOut(id=3, fullName="My New User", email="newuser@email.com", group="Home", admin=False)
return UserOut(id=3, fullName="My New User", email="newuser@email.com", group="Home", admin=False, tokens=[])
def test_superuser_login(api_client: TestClient, api_routes: AppRoutes, token):
@ -45,6 +45,7 @@ def test_create_user(api_client: TestClient, api_routes: AppRoutes, token, new_u
"password": "MyStrongPassword",
"group": "Home",
"admin": False,
"tokens": [],
}
response = api_client.post(api_routes.users, json=create_data, headers=token)