~registry/pykickstart/trunk

« back to all changes in this revision

Viewing changes to tests/base.py

  • Committer: Chris Lumens
  • Date: 2014-10-22 14:19:44 UTC
  • Revision ID: git-v1:982498c0647c4bc3b4460209d4a76698c0eb6f8c
Add a note that the repo has moved.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
import unittest
2
 
from tests.baseclass import ParserTest
3
 
 
4
 
from pykickstart.base import *
5
 
from pykickstart.version import *
6
 
 
7
 
class BaseClasses_TestCase(ParserTest):
8
 
    def runTest(self):
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, ))
14
 
 
15
 
class HandlerString_TestCase(ParserTest):
16
 
    def runTest(self):
17
 
        self.handler.platform = "x86_64"
18
 
        self.assertIn("#platform=x86_64", str(self.handler))
19
 
 
20
 
class HandlerResetCommand_TestCase(ParserTest):
21
 
    def runTest(self):
22
 
        # fail - tried to reset a command that doesn't exist
23
 
        self.assertRaises(KeyError, self.handler.resetCommand, "fakecommand")
24
 
 
25
 
        # might as well test this way of getting the same information, while we're at it
26
 
        self.assertFalse(self.handler.hasCommand("fakecommand"))
27
 
 
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
34
 
 
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__)
41
 
 
42
 
class HandlerDispatch_TestCase(ParserTest):
43
 
    def runTest(self):
44
 
        # fail - no such command
45
 
        self.assertRaises(KickstartParseError, self.handler.dispatcher, ["fakecommand"], 1)
46
 
 
47
 
class HandlerMask_TestCase(ParserTest):
48
 
    def runTest(self):
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])
53
 
 
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"]
58
 
 
59
 
        self.handler.maskAllExcept(lst)
60
 
        for cmd in self.handler.commands:
61
 
            if cmd in lst:
62
 
                self.assertIsNotNone(self.handler.commands[cmd])
63
 
            else:
64
 
                self.assertIsNone(self.handler.commands[cmd])
65
 
 
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, "")
70
 
 
71
 
if __name__ == "__main__":
72
 
    unittest.main()