From edb248a9d73c82e273b91a77ae8f8a9859c7942f Mon Sep 17 00:00:00 2001 From: Michael Genson <71845777+michael-genson@users.noreply.github.com> Date: Mon, 9 Sep 2024 20:48:08 +0000 Subject: [PATCH] tests --- .../test_cookbook_repository.py | 49 ++++++++++++++++++- 1 file changed, 47 insertions(+), 2 deletions(-) diff --git a/tests/unit_tests/repository_tests/test_cookbook_repository.py b/tests/unit_tests/repository_tests/test_cookbook_repository.py index f465a6940e7..abec4d12aaf 100644 --- a/tests/unit_tests/repository_tests/test_cookbook_repository.py +++ b/tests/unit_tests/repository_tests/test_cookbook_repository.py @@ -47,7 +47,52 @@ def test_create_cookbook_duplicate_name(unique_user: TestUser, use_create_many: cb_2 = unique_user.repos.cookbooks.create(cb_2_data) assert cb_1.id != cb_2.id - assert cb_1.group_id == cb_2.group_id - assert cb_1.household_id != cb_2.household_id + assert cb_1.name == cb_2.name + assert cb_1.slug != cb_2.slug + + +@pytest.mark.parametrize("method", ["update", "update_many", "patch"]) +def test_update_cookbook_updates_slug(unique_user: TestUser, method: str): + cb_data = cookbook_data(unique_user) + cb = unique_user.repos.cookbooks.create(cb_data) + unique_user.repos.session.commit() + + new_name = random_string() + cb.name = new_name + + if method == "update": + cb = unique_user.repos.cookbooks.update(cb.id, cb) + if method == "update_many": + result = unique_user.repos.cookbooks.update_many([cb]) + assert len(result) == 1 + cb = result[0] + else: + cb = unique_user.repos.cookbooks.patch(cb.id, cb) + + assert cb.name == new_name + assert cb.slug == slugify(new_name) + + +@pytest.mark.parametrize("method", ["update", "update_many", "patch"]) +def test_update_cookbook_duplicate_name(unique_user: TestUser, method: str): + cb_1_data = cookbook_data(unique_user) + cb_2_data = cookbook_data(unique_user) + + cb_1 = unique_user.repos.cookbooks.create(cb_1_data) + unique_user.repos.session.commit() + cb_2 = unique_user.repos.cookbooks.create(cb_2_data) + unique_user.repos.session.commit() + + cb_2.name = cb_1.name + if method == "update": + cb_2 = unique_user.repos.cookbooks.update(cb_2.id, cb_2) + if method == "update_many": + result = unique_user.repos.cookbooks.update_many([cb_2]) + assert len(result) == 1 + cb_2 = result[0] + else: + cb_2 = unique_user.repos.cookbooks.patch(cb_2.id, cb_2) + + assert cb_1.id != cb_2.id assert cb_1.name == cb_2.name assert cb_1.slug != cb_2.slug