mirror of
https://github.com/mealie-recipes/mealie.git
synced 2025-08-03 04:25:24 +02:00
update foods and units for multitenant support
This commit is contained in:
parent
fbc17b670d
commit
9a82a172cb
11 changed files with 194 additions and 15 deletions
1
tests/fixtures/__init__.py
vendored
1
tests/fixtures/__init__.py
vendored
|
@ -1,5 +1,6 @@
|
|||
from .fixture_admin import *
|
||||
from .fixture_database import *
|
||||
from .fixture_multitenant import *
|
||||
from .fixture_recipe import *
|
||||
from .fixture_routes import *
|
||||
from .fixture_shopping_lists import *
|
||||
|
|
22
tests/fixtures/fixture_multitenant.py
vendored
Normal file
22
tests/fixtures/fixture_multitenant.py
vendored
Normal file
|
@ -0,0 +1,22 @@
|
|||
from dataclasses import dataclass
|
||||
|
||||
import pytest
|
||||
from fastapi.testclient import TestClient
|
||||
|
||||
from tests import utils
|
||||
from tests.fixtures.fixture_users import build_unique_user
|
||||
from tests.utils.factories import random_string
|
||||
|
||||
|
||||
@dataclass
|
||||
class MultiTenant:
|
||||
user_one: utils.TestUser
|
||||
user_two: utils.TestUser
|
||||
|
||||
|
||||
@pytest.fixture(scope="module")
|
||||
def multitenants(api_client: TestClient) -> MultiTenant:
|
||||
yield MultiTenant(
|
||||
user_one=build_unique_user(random_string(12), api_client),
|
||||
user_two=build_unique_user(random_string(12), api_client),
|
||||
)
|
31
tests/fixtures/fixture_users.py
vendored
31
tests/fixtures/fixture_users.py
vendored
|
@ -6,22 +6,47 @@ from pytest import fixture
|
|||
from starlette.testclient import TestClient
|
||||
|
||||
from tests import utils
|
||||
from tests.utils.factories import random_string
|
||||
|
||||
|
||||
def build_unique_user(group: str, api_client: requests) -> utils.TestUser:
|
||||
api_routes = utils.AppRoutes()
|
||||
group = group or random_string(12)
|
||||
|
||||
registration = utils.user_registration_factory()
|
||||
response = api_client.post("/api/users/register", json=registration.dict(by_alias=True))
|
||||
assert response.status_code == 201
|
||||
|
||||
form_data = {"username": registration.username, "password": registration.password}
|
||||
|
||||
token = utils.login(form_data, api_client, api_routes)
|
||||
|
||||
user_data = api_client.get(api_routes.users_self, headers=token).json()
|
||||
assert token is not None
|
||||
|
||||
return utils.TestUser(
|
||||
_group_id=user_data.get("groupId"),
|
||||
user_id=user_data.get("id"),
|
||||
email=user_data.get("email"),
|
||||
token=token,
|
||||
)
|
||||
|
||||
|
||||
@fixture(scope="module")
|
||||
def g2_user(admin_token, api_client: requests, api_routes: utils.AppRoutes):
|
||||
def g2_user(admin_token, api_client: TestClient, api_routes: utils.AppRoutes):
|
||||
group = random_string(12)
|
||||
# Create the user
|
||||
create_data = {
|
||||
"fullName": utils.random_string(),
|
||||
"username": utils.random_string(),
|
||||
"email": utils.random_email(),
|
||||
"password": "useruser",
|
||||
"group": "New Group",
|
||||
"group": group,
|
||||
"admin": False,
|
||||
"tokens": [],
|
||||
}
|
||||
|
||||
response = api_client.post(api_routes.groups, json={"name": "New Group"}, headers=admin_token)
|
||||
response = api_client.post(api_routes.groups, json={"name": group}, headers=admin_token)
|
||||
response = api_client.post(api_routes.users, json=create_data, headers=admin_token)
|
||||
|
||||
assert response.status_code == 201
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue