Skip to content

Commit

Permalink
add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
dchhabda committed Oct 17, 2022
1 parent 2a09edb commit b458102
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
4 changes: 2 additions & 2 deletions pybossa/jobs.py
Original file line number Diff line number Diff line change
Expand Up @@ -1575,8 +1575,8 @@ def perform_completed_tasks_cleanup():
cleanup_days = -1
if cleanup_days not in valid_days:
current_app.logger.info(
f"Skipping project cleanup days due to invalid configuration,"
f"project id {project_id}, completed_tasks_cleanup_days {cleanup_days}, valid days {valid_days}"
f"Skipping project cleanup days due to invalid cleanup days,"
f"project id {project_id}, completed_tasks_cleanup_days {row.cleanup_days}, valid days {valid_days}"
)
else:
projects.append((project_id, cleanup_days))
Expand Down
22 changes: 22 additions & 0 deletions test/test_jobs/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -354,3 +354,25 @@ def test_saturday_4pm_date(self):
date2 = datetime.strptime("2026-01-31 10:00AM", "%Y-%m-%d %I:%M%p")
saturday = get_saturday_4pm_date(date2)
assert saturday.strftime("%Y-%m-%d %H:%M:%S") == "2026-01-31 16:00:00"

@with_context
@patch('pybossa.jobs.purge_task_data')
def test_completed_tasks_cleanup_bad_config(self, mock_purge_tasks):
"""Test completed_tasks_cleanup deletes tasks qualify for deletion."""

from flask import current_app
current_app.config['COMPLETED_TASK_CLEANUP_DAYS'] = [(None, None)]
perform_completed_tasks_cleanup()
assert not mock_purge_tasks.called

@with_context
@patch('pybossa.jobs.purge_task_data')
def test_completed_tasks_cleanup_bad_project_config(self, mock_purge_tasks):
"""Test completed_tasks_cleanup deletes tasks qualify for deletion."""

from flask import current_app
current_app.config['COMPLETED_TASK_CLEANUP_DAYS'] = [(30, "30 days"), (60, "60 days")]
ProjectFactory.create(info=dict(completed_tasks_cleanup_days=240))
ProjectFactory.create(info=dict(completed_tasks_cleanup_days="xyz"))
perform_completed_tasks_cleanup()
assert not mock_purge_tasks.called

0 comments on commit b458102

Please sign in to comment.