Skip to content
Snippets Groups Projects
Unverified Commit 667f9341 authored by Nils Behlen's avatar Nils Behlen Committed by GitHub
Browse files

Merge pull request #4173 from privacyidea/fix_cron_commands

Fix command names in cron runner
parents 4fe73d3b 42fde41e
No related branches found
No related tags found
No related merge requests found
......@@ -117,17 +117,10 @@ def cli():
This script is meant to be invoked periodically by the system cron daemon.
It runs periodic tasks that are specified in the database.
"""
click.echo(r"""
_ _______ _______
___ ____(_) _____ _______ __/ _/ _ \/ __/ _ |
/ _ \/ __/ / |/ / _ `/ __/ // // // // / _// __ |
/ .__/_/ /_/|___/\_,_/\__/\_, /___/____/___/_/ |_| Cron
/_/ /___/
{0!s:>51}
""".format('v{0!s}'.format(get_version_number())))
pass
@cli.command()
@cli.command("run_manually")
@click.option("-n", "--node", "node_string",
help="Override the node name (read from privacyIDEA config by default)")
@click.option("-t", "--task", "task_name",
......@@ -168,7 +161,7 @@ def list_tasks():
**ptask))
@cli.command()
@cli.command("run_scheduled")
@click.option("-d", "--dryrun",
is_flag=True,
help="Do not run any tasks, only show what would be done")
......
......@@ -17,17 +17,47 @@
# You should have received a copy of the GNU Affero General Public
# License along with this program. If not, see <http://www.gnu.org/licenses/>.
from .base import CliTestCase
import pytest
from sqlalchemy.orm.session import close_all_sessions
from privacyidea.app import create_app
from privacyidea.models import db
from privacyidea.lib.lifecycle import call_finalizers
from privacyidea.cli.tools.cron import cli as privacyidea_cron
class PICronTestCase(CliTestCase):
def test_01_picron_help(self):
runner = self.app.test_cli_runner()
result = runner.invoke(privacyidea_cron, ["-h"])
self.assertIn("Execute all periodic tasks that are scheduled to run.",
result.output, result)
self.assertIn("Show a list of available tasks that could be run.",
result.output, result)
self.assertIn("Manually run a periodic task",
result.output, result)
@pytest.fixture(scope="class")
def app():
"""Create and configure app instance for testing"""
app = create_app(config_name="testing", config_file="", silent=True)
with app.app_context():
db.create_all()
yield app
with app.app_context():
call_finalizers()
close_all_sessions()
db.drop_all()
db.engine.dispose()
class TestPICronExec:
def test_01_picron_exec(self, app):
runner = app.test_cli_runner()
result = runner.invoke(privacyidea_cron, [])
assert "Usage: cli [OPTIONS] COMMAND [ARGS]..." in result.output, result
assert "Execute all periodic tasks that are scheduled to run." in result.output, result
assert "run_scheduled" in result.output, result
assert "Show a list of available tasks that could be run." in result.output, result
assert "Manually run a periodic task" in result.output, result
assert "run_manually" in result.output, result
result = runner.invoke(privacyidea_cron, ["list"])
assert "Active ID Name" in result.output, result.output
result = runner.invoke(privacyidea_cron, ["run_scheduled"])
assert "There are no tasks scheduled on node Node1." in result.output, result.output
result = runner.invoke(privacyidea_cron, ["run_scheduled", "-c"])
assert not result.output, result.output
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment