You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
50 lines
1.6 KiB
50 lines
1.6 KiB
import pytest
|
|
from scripttease.exceptions import InvalidInput
|
|
from scripttease.lib.commands.base import Command
|
|
from scripttease.lib.loaders import INILoader
|
|
from scripttease.lib.factories import *
|
|
|
|
|
|
def bad_custom_command(path):
|
|
# this will fail because the function doesn't except kwargs.
|
|
pass
|
|
|
|
|
|
def custom_command(path, **kwargs):
|
|
return Command("ls -ls %s" % path, name="custom", **kwargs)
|
|
|
|
|
|
def test_command_factory():
|
|
ini = INILoader("tests/examples/kitchen_sink.ini")
|
|
assert command_factory(ini, profile="nonexistent") is None
|
|
|
|
ini = INILoader("tests/examples/kitchen_sink.ini")
|
|
ini.load()
|
|
commands = command_factory(ini)
|
|
assert len(commands) == 49
|
|
|
|
ini = INILoader("tests/examples/bad_command.ini")
|
|
ini.load()
|
|
commands = command_factory(ini)
|
|
assert len(commands) == 0
|
|
|
|
ini = INILoader("tests/examples/apache_examples.ini")
|
|
ini.load()
|
|
commands = command_factory(ini)
|
|
assert len(commands) == 2
|
|
|
|
# This should result in no commands because CentOS doesn't have enable/disable site or module.
|
|
ini = INILoader("tests/examples/apache_examples.ini")
|
|
ini.load()
|
|
commands = command_factory(ini, profile="centos")
|
|
assert len(commands) == 0
|
|
|
|
ini = INILoader("tests/examples/custom_example.ini")
|
|
ini.load()
|
|
commands = command_factory(ini, mappings={'custom': custom_command})
|
|
assert len(commands) == 3
|
|
|
|
ini = INILoader("tests/examples/bad_custom_example.ini")
|
|
ini.load()
|
|
with pytest.raises(InvalidInput):
|
|
command_factory(ini, mappings={'bad_custom': bad_custom_command})
|
|
|