mirror of
https://github.com/mealie-recipes/mealie.git
synced 2025-08-02 20:15:24 +02:00
feat(backend): ✨ migrate site-settings to groups (#673)
* feat(frontend): ✨ add user registration page (WIP) * feat(backend): ✨ add user registration (WIP) * test(backend): ✅ add validator testing for registration schema * feat(backend): ✨ continued work on user sign-up * feat(backend): ✨ add signup flow and user/group settings * test(backend): ✅ user-creation tests and small refactor of existing tests * fix(backend): ✅ fix failing group tests * style: 🎨 fix lint issues Co-authored-by: hay-kot <hay-kot@pm.me>
This commit is contained in:
parent
e179dcdb10
commit
3c504e7048
63 changed files with 1665 additions and 841 deletions
|
@ -0,0 +1,46 @@
|
|||
import pytest
|
||||
from fastapi.testclient import TestClient
|
||||
|
||||
|
||||
class Routes:
|
||||
base = "/api/groups/cookbooks"
|
||||
|
||||
def item(item_id: int) -> str:
|
||||
return f"{Routes.base}/{item_id}"
|
||||
|
||||
|
||||
@pytest.fixture()
|
||||
def page_data():
|
||||
return {"name": "My New Page", "description": "", "position": 0, "categories": [], "groupId": 1}
|
||||
|
||||
|
||||
def test_create_cookbook(api_client: TestClient, admin_token, page_data):
|
||||
response = api_client.post(Routes.base, json=page_data, headers=admin_token)
|
||||
|
||||
assert response.status_code == 200
|
||||
|
||||
|
||||
def test_read_cookbook(api_client: TestClient, page_data, admin_token):
|
||||
response = api_client.get(Routes.item(1), headers=admin_token)
|
||||
|
||||
page_data["id"] = 1
|
||||
page_data["slug"] = "my-new-page"
|
||||
|
||||
assert response.json() == page_data
|
||||
|
||||
|
||||
def test_update_cookbook(api_client: TestClient, page_data, admin_token):
|
||||
page_data["id"] = 1
|
||||
page_data["name"] = "My New Name"
|
||||
response = api_client.put(Routes.item(1), json=page_data, headers=admin_token)
|
||||
|
||||
assert response.status_code == 200
|
||||
|
||||
|
||||
def test_delete_cookbook(api_client: TestClient, admin_token):
|
||||
response = api_client.delete(Routes.item(1), headers=admin_token)
|
||||
|
||||
assert response.status_code == 200
|
||||
|
||||
response = api_client.get(Routes.item(1), headers=admin_token)
|
||||
assert response.status_code == 404
|
|
@ -0,0 +1,32 @@
|
|||
from fastapi.testclient import TestClient
|
||||
|
||||
from mealie.schema.user.registration import CreateUserRegistration
|
||||
|
||||
|
||||
class Routes:
|
||||
base = "/api/users/register"
|
||||
auth_token = "/api/auth/token"
|
||||
|
||||
|
||||
def test_user_registration_new_group(api_client: TestClient):
|
||||
registration = CreateUserRegistration(
|
||||
group="New Group Name",
|
||||
email="email@email.com",
|
||||
username="fake-user-name",
|
||||
password="fake-password",
|
||||
password_confirm="fake-password",
|
||||
advanced=False,
|
||||
private=False,
|
||||
)
|
||||
|
||||
response = api_client.post(Routes.base, json=registration.dict(by_alias=True))
|
||||
assert response.status_code == 201
|
||||
|
||||
# Login
|
||||
form_data = {"username": "email@email.com", "password": "fake-password"}
|
||||
|
||||
response = api_client.post(Routes.auth_token, form_data)
|
||||
assert response.status_code == 200
|
||||
token = response.json().get("access_token")
|
||||
|
||||
assert token is not None
|
|
@ -0,0 +1,51 @@
|
|||
from fastapi.testclient import TestClient
|
||||
|
||||
from mealie.schema.group.group_preferences import UpdateGroupPreferences
|
||||
from tests.utils.assertion_helpers import assert_ignore_keys
|
||||
|
||||
|
||||
class Routes:
|
||||
base = "/api/groups/self"
|
||||
preferences = "/api/groups/preferences"
|
||||
|
||||
|
||||
def test_get_preferences(api_client: TestClient, admin_token) -> None:
|
||||
response = api_client.get(Routes.preferences, headers=admin_token)
|
||||
|
||||
assert response.status_code == 200
|
||||
|
||||
preferences = response.json()
|
||||
|
||||
# Spot Check Defaults
|
||||
assert preferences["recipePublic"] is True
|
||||
assert preferences["recipeShowNutrition"] is False
|
||||
|
||||
|
||||
def test_preferences_in_group(api_client: TestClient, admin_token) -> None:
|
||||
response = api_client.get(Routes.base, headers=admin_token)
|
||||
|
||||
assert response.status_code == 200
|
||||
|
||||
group = response.json()
|
||||
|
||||
assert group["preferences"] is not None
|
||||
|
||||
# Spot Check
|
||||
assert group["preferences"]["recipePublic"] is True
|
||||
assert group["preferences"]["recipeShowNutrition"] is False
|
||||
|
||||
|
||||
def test_update_preferences(api_client: TestClient, admin_token) -> None:
|
||||
new_data = UpdateGroupPreferences(recipe_public=False, recipe_show_nutrition=True)
|
||||
|
||||
response = api_client.put(Routes.preferences, json=new_data.dict(), headers=admin_token)
|
||||
|
||||
assert response.status_code == 200
|
||||
|
||||
preferences = response.json()
|
||||
|
||||
assert preferences is not None
|
||||
assert preferences["recipePublic"] is False
|
||||
assert preferences["recipeShowNutrition"] is True
|
||||
|
||||
assert_ignore_keys(new_data.dict(by_alias=True), preferences, ["id", "groupId"])
|
Loading…
Add table
Add a link
Reference in a new issue