2
from tests.baseclass import ParserTest
4
from pykickstart.base import *
5
from pykickstart.version import *
7
class BaseClasses_TestCase(ParserTest):
9
# fail - can't instantiate these directly
10
self.assertRaises(TypeError, KickstartCommand, (100, ))
11
self.assertRaises(TypeError, DeprecatedCommand, (100, ))
12
self.assertRaises(TypeError, BaseHandler, (100, ))
13
self.assertRaises(TypeError, BaseData, (100, ))
15
class HandlerString_TestCase(ParserTest):
17
self.handler.platform = "x86_64"
18
self.assertIn("#platform=x86_64", str(self.handler))
20
class HandlerResetCommand_TestCase(ParserTest):
22
# fail - tried to reset a command that doesn't exist
23
self.assertRaises(KeyError, self.handler.resetCommand, "fakecommand")
25
# might as well test this way of getting the same information, while we're at it
26
self.assertFalse(self.handler.hasCommand("fakecommand"))
28
# Set some attributes on a command, then reset it and verify they're gone.
29
self.handler.autopart.autopart = True
30
self.handler.autopart.cipher = "whatever"
31
self.handler.autopart.encrypted = True
32
self.handler.autopart.passphrase = "something"
33
self.handler.autopart.bogus = True
35
self.handler.resetCommand("autopart")
36
self.assertFalse(self.handler.autopart.autopart)
37
self.assertEqual(self.handler.autopart.cipher, "")
38
self.assertFalse(self.handler.autopart.encrypted)
39
self.assertEqual(self.handler.autopart.passphrase, "")
40
self.assertNotIn("bogus", self.handler.autopart.__dict__)
42
class HandlerDispatch_TestCase(ParserTest):
44
# fail - no such command
45
self.assertRaises(KickstartParseError, self.handler.dispatcher, ["fakecommand"], 1)
47
class HandlerMask_TestCase(ParserTest):
49
# First, verify all commands are set to something other than None. This means
50
# the command can be called.
51
for cmd in self.handler.commands:
52
self.assertIsNotNone(self.handler.commands[cmd])
54
# Now blank out most commands except the one or two we're actually interested
55
# in. This has the effect of making the other commands recognized, but calling
56
# them will have no effect on data.
57
lst = ["rootpw", "user", "group"]
59
self.handler.maskAllExcept(lst)
60
for cmd in self.handler.commands:
62
self.assertIsNotNone(self.handler.commands[cmd])
64
self.assertIsNone(self.handler.commands[cmd])
66
# These attributes should still be set to their defaults.
67
self.handler.dispatcher(["autopart", "--encrypted", "--passphrase", "something"], 1)
68
self.assertFalse(self.handler.autopart.encrypted)
69
self.assertEqual(self.handler.autopart.passphrase, "")
71
if __name__ == "__main__":