1
0
Fork 0
mirror of https://github.com/mealie-recipes/mealie.git synced 2025-07-24 15:49:42 +02:00

fix: Tools Shouldn't Be Unique Across Groups (#2505)

* fixed type/abc errors in tests

* fixed false positive multitentant tests

* fix tools not allowing unique slugs across groups

* fixed alembic refs

---------

Co-authored-by: Hayden <64056131+hay-kot@users.noreply.github.com>
This commit is contained in:
Michael Genson 2023-08-21 15:39:23 -05:00 committed by GitHub
parent 99e7717fec
commit c9cc7a93c8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 62 additions and 29 deletions

View file

@ -10,17 +10,18 @@ class ABCMultiTenantTestCase(ABC):
def __init__(self, database: AllRepositories, client: TestClient) -> None:
self.database = database
self.client = client
self.items = []
self.items: list = []
@abstractmethod
def seed_action(repos: AllRepositories, group_id: str) -> set[int] | set[str]:
def seed_action(self, group_id: str) -> set[int] | set[str]:
...
def seed_multi(self, group1_id: str, group2_id: str) -> tuple[set[int], set[int]]:
pass
@abstractmethod
def seed_multi(self, group1_id: str, group2_id: str) -> tuple[set[str], set[str]]:
...
@abstractmethod
def get_all(token: str) -> Response:
def get_all(self, token: str) -> Response:
...
@abstractmethod

View file

@ -29,9 +29,9 @@ class CategoryTestCase(ABCMultiTenantTestCase):
g1_item_ids: set[str] = set()
g2_item_ids: set[str] = set()
for group_id, item_ids in [(group1_id, g1_item_ids), (group2_id, g2_item_ids)]:
for _ in range(10):
name = utils.random_string(10)
for _ in range(10):
name = utils.random_string(10)
for group_id, item_ids in [(group1_id, g1_item_ids), (group2_id, g2_item_ids)]:
category = self.database.categories.create(
CategorySave(
group_id=group_id,

View file

@ -28,9 +28,9 @@ class FoodsTestCase(ABCMultiTenantTestCase):
g1_item_ids: set[str] = set()
g2_item_ids: set[str] = set()
for group_id, item_ids in [(group1_id, g1_item_ids), (group2_id, g2_item_ids)]:
for _ in range(10):
name = utils.random_string(10)
for _ in range(10):
name = utils.random_string(10)
for group_id, item_ids in [(group1_id, g1_item_ids), (group2_id, g2_item_ids)]:
food = self.database.ingredient_foods.create(
SaveIngredientFood(
group_id=group_id,

View file

@ -29,9 +29,9 @@ class TagsTestCase(ABCMultiTenantTestCase):
g1_item_ids: set[str] = set()
g2_item_ids: set[str] = set()
for group_id, item_ids in [(group1_id, g1_item_ids), (group2_id, g2_item_ids)]:
for _ in range(10):
name = utils.random_string(10)
for _ in range(10):
name = utils.random_string(10)
for group_id, item_ids in [(group1_id, g1_item_ids), (group2_id, g2_item_ids)]:
category = self.database.tags.create(
TagSave(
group_id=group_id,

View file

@ -29,9 +29,9 @@ class ToolsTestCase(ABCMultiTenantTestCase):
g1_item_ids: set[str] = set()
g2_item_ids: set[str] = set()
for group_id, item_ids in [(group1_id, g1_item_ids), (group2_id, g2_item_ids)]:
for _ in range(10):
name = utils.random_string(10)
for _ in range(10):
name = utils.random_string(10)
for group_id, item_ids in [(group1_id, g1_item_ids), (group2_id, g2_item_ids)]:
tool = self.database.tools.create(
RecipeToolSave(
group_id=group_id,

View file

@ -28,9 +28,9 @@ class UnitsTestCase(ABCMultiTenantTestCase):
g1_item_ids: set[str] = set()
g2_item_ids: set[str] = set()
for group_id, item_ids in [(group1_id, g1_item_ids), (group2_id, g2_item_ids)]:
for _ in range(10):
name = utils.random_string(10)
for _ in range(10):
name = utils.random_string(10)
for group_id, item_ids in [(group1_id, g1_item_ids), (group2_id, g2_item_ids)]:
food = self.database.ingredient_units.create(
SaveIngredientUnit(
group_id=group_id,

View file

@ -19,12 +19,12 @@ all_cases = [
]
@pytest.mark.parametrize("test_case", all_cases)
@pytest.mark.parametrize("test_case_type", all_cases)
def test_multitenant_cases_get_all(
api_client: TestClient,
multitenants: MultiTenant,
database: AllRepositories,
test_case: type[ABCMultiTenantTestCase],
test_case_type: type[ABCMultiTenantTestCase],
):
"""
This test will run all the multitenant test cases and validate that they return only the data for their group.
@ -34,11 +34,11 @@ def test_multitenant_cases_get_all(
user1 = multitenants.user_one
user2 = multitenants.user_two
test_case = test_case(database, api_client)
test_case = test_case_type(database, api_client)
with test_case:
expected_ids = test_case.seed_action(user1.group_id)
expected_results = [
expected_results: list = [
(user1.token, expected_ids),
(user2.token, []),
]
@ -56,12 +56,12 @@ def test_multitenant_cases_get_all(
assert item["id"] in item_ids
@pytest.mark.parametrize("test_case", all_cases)
@pytest.mark.parametrize("test_case_type", all_cases)
def test_multitenant_cases_same_named_resources(
api_client: TestClient,
multitenants: MultiTenant,
database: AllRepositories,
test_case: type[ABCMultiTenantTestCase],
test_case_type: type[ABCMultiTenantTestCase],
):
"""
This test is used to ensure that the same resource can be created with the same values in different tenants.
@ -71,7 +71,7 @@ def test_multitenant_cases_same_named_resources(
user1 = multitenants.user_one
user2 = multitenants.user_two
test_case = test_case(database, api_client)
test_case = test_case_type(database, api_client)
with test_case:
expected_ids, expected_ids2 = test_case.seed_multi(user1.group_id, user2.group_id)