Source

vasm / src / tests / test_LOGINMANAGERS.py

Full commit
#!/usr/bin/env python

#    This file is part of VASM.
#
#    VASM is free software: you can redistribute it and/or modify
#    it under the terms of the GNU General Public License v3 as published by
#    the Free Software Foundation.
#
#    VASM is distributed in the hope that it will be useful,
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#    GNU General Public License for more details.
#
#    You should have received a copy of the GNU General Public License
#    along with VASM.  If not, see <http://www.gnu.org/licenses/>.

__author__ = "Moises Henriquez"
__author_email__ = "moc.liamg@xnl.E0M"[::-1]

import sys
import os
import shutil
import unittest
vasmdir = os.path.join(os.path.dirname(
    os.path.dirname(os.path.abspath(__file__))), 'vasm')
if not vasmdir in sys.path: sys.path.append(vasmdir)
from backend import LOGINMANAGERS as gestores


class BootModeTest(unittest.TestCase):
    def setUp(self):
        self.file = "/tmp/rc.X"
        shutil.copy2("/etc/rc.d/rc.X", "/tmp/rc.X")
        self.model = gestores.LoginManagers(specfile=self.file)
    
    def tearDown(self):
        # remove the temp file
        os.remove(self.file)
        
    def test_getCurrent(self):
        gestor = self.model.get_current()
        self.assertTrue(type(gestor) == str)
    
    def test_setMode(self):
        # copy the file to tmp
        manager = "FOO"
        res = self.model.set_manager("FOO")
        read_man = self.model.get_current()
        self.assertEqual(read_man, manager)
    
    def test_roundTest(self):
        man = "BAR"
        # set the mode
        res = self.model.set_manager(man)
        # read it to make sure it comes back the same
        read = self.model.get_current()
        self.assertEqual(read, man)
    
    def test_managers(self):
        res = self.model.list_existing()
        self.assertTrue(len(res) > 0)
    
    def test_descriptions(self):
        manager = self.model.list_existing()[0].lower()
        res = self.model._describe_manager(manager)
        self.assertTrue(type(res), str)
        
        
        
        

if __name__ == "__main__":
    unittest.main()