Rename 'expiration.on-sync' to 'purge.on-sync' (#3556)
Taskwarrior uses "expire" to refer to deletion of tasks past their "until" date, so let's use `purge` to link this semantically to the `task purge` command.
This commit is contained in:
committed by
GitHub
parent
1304d6361c
commit
7d79b9e516
@@ -2,7 +2,7 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
###############################################################################
|
||||
#
|
||||
# Copyright 2006 - 2021, Tomas Babej, Paul Beckingham, Federico Hernandez.
|
||||
# Copyright 2006 - 2024, Tomas Babej, Paul Beckingham, Federico Hernandez.
|
||||
#
|
||||
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
# of this software and associated documentation files (the "Software"), to deal
|
||||
@@ -29,10 +29,58 @@
|
||||
import sys
|
||||
import os
|
||||
import unittest
|
||||
import time
|
||||
# Ensure python finds the local simpletap module
|
||||
sys.path.append(os.path.dirname(os.path.abspath(__file__)))
|
||||
|
||||
from basetest import Task, TestCase
|
||||
from basetest.utils import mkstemp
|
||||
|
||||
|
||||
class TestAutoPurge(TestCase):
|
||||
def setUp(self):
|
||||
self.t = Task()
|
||||
# Set up local sync within the TASKDATA directory, so that it will be
|
||||
# deleted properly.
|
||||
self.t.config("sync.local.server_dir", self.t.datadir)
|
||||
|
||||
def exists(self, uuid):
|
||||
code, out, err = self.t(f"_get {uuid}.status")
|
||||
return out.strip() != ""
|
||||
|
||||
def test_auto_purge(self):
|
||||
"""Only tasks that are deleted and have a modification in the past are purged."""
|
||||
yesterday = int(time.time()) - 3600 * 24
|
||||
last_year = int(time.time()) - 265 * 3600 * 24
|
||||
old_pending = "a1111111-a111-a111-a111-a11111111111"
|
||||
old_completed = "a2222222-a222-a222-a222-a22222222222"
|
||||
new_deleted = "a3333333-a333-a333-a333-a33333333333"
|
||||
old_deleted = "a4444444-a444-a444-a444-a44444444444"
|
||||
task_data = f"""[
|
||||
{{"uuid":"{old_pending}","status":"pending","modified":"{last_year}","description":"x"}},
|
||||
{{"uuid":"{old_completed}","status":"completed","modified":"{last_year}","description":"x"}},
|
||||
{{"uuid":"{new_deleted}","status":"deleted","modified":"{yesterday}","description":"x"}},
|
||||
{{"uuid":"{old_deleted}","status":"deleted","modified":"{last_year}","description":"x"}}
|
||||
]
|
||||
"""
|
||||
code, out, err = self.t("import -", input=task_data)
|
||||
self.assertIn("Imported 4 tasks", err)
|
||||
|
||||
# By default, purge does not occur.
|
||||
code, out, err = self.t("sync")
|
||||
self.assertTrue(self.exists(old_pending))
|
||||
self.assertTrue(self.exists(old_completed))
|
||||
self.assertTrue(self.exists(new_deleted))
|
||||
self.assertTrue(self.exists(old_deleted))
|
||||
|
||||
# Configure purge on sync. The old_deleted task
|
||||
# should be removed.
|
||||
self.t.config("purge.on-sync", "1")
|
||||
code, out, err = self.t("sync")
|
||||
self.assertTrue(self.exists(old_pending))
|
||||
self.assertTrue(self.exists(old_completed))
|
||||
self.assertTrue(self.exists(new_deleted))
|
||||
self.assertFalse(self.exists(old_deleted))
|
||||
|
||||
|
||||
class TestDelete(TestCase):
|
||||
|
||||
Reference in New Issue
Block a user