-
-
Notifications
You must be signed in to change notification settings - Fork 811
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Purge Group Exports type mismatch (#3314)
* cast string to datetime * added test
- Loading branch information
1 parent
f2735ba
commit d960947
Showing
2 changed files
with
39 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
tests/unit_tests/services_tests/scheduler/tasks/test_purge_group_exports.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import tempfile | ||
from pathlib import Path | ||
|
||
from mealie.repos.repository_factory import AllRepositories | ||
from mealie.schema.recipe.recipe import Recipe | ||
from mealie.services.recipe.recipe_bulk_service import RecipeBulkActionsService | ||
from mealie.services.scheduler.tasks.purge_group_exports import purge_group_data_exports | ||
from tests.utils.factories import random_int, random_string | ||
from tests.utils.fixture_schemas import TestUser | ||
|
||
|
||
def test_purge_group_exports(database: AllRepositories, unique_user: TestUser): | ||
# create the export | ||
group = database.groups.get_one(unique_user.group_id) | ||
assert group | ||
user = database.users.get_one(unique_user.user_id) | ||
assert user | ||
recipe_exporter = RecipeBulkActionsService(database, user, group) | ||
recipes = [ | ||
database.recipes.create(Recipe(name=random_string(), group_id=group.id)) for _ in range(random_int(2, 5)) | ||
] | ||
|
||
with tempfile.NamedTemporaryFile() as tmpfile: | ||
recipe_exporter.export_recipes(Path(tmpfile.name), [recipe.slug for recipe in recipes]) | ||
|
||
exports = recipe_exporter.get_exports() | ||
assert len(exports) == 1 | ||
export = exports[0] | ||
export_path = Path(export.path) | ||
assert export_path.exists() | ||
|
||
# purge the export and confirm all data is removed | ||
purge_group_data_exports(-525600) # 1 year into the future | ||
|
||
assert not export_path.exists() | ||
exports = recipe_exporter.get_exports() | ||
assert not exports |