Commits

Anonymous committed c91453f

Better bootloader tests, fstab.py tests

  • Participants
  • Parent commits d861d6a

Comments (0)

Files changed (2)

vinstall/backend/bootloader.py

         self.assertEqual(mbr.bootloader(), GRUB2)
 
 
-#class Grub2TestCase(FakeDeviceTestCase):
-#
-#    def test_grub2(self):
-#        return True
-#        grub2 = Grub2(self.path)
-#        grub2.write_config(config_path="/tmp/grub2-test")
-#        grub2.test_install("/tmp/grub2-test", self.path)
-#        mbr = MasterBootRecord(self.path)
-#        self.assertEqual(mbr.bootloader(), GRUB2)
-
-
 if __name__ == "__main__":
     unittest.main()

vinstall/backend/fstab.py

 
 
 import os
+import unittest
 
 
+    
 class FstabEntry(object):
     """ Object representing an entry in /etc/fstab
 
         """
         assert isinstance(entry, FstabEntry), "entry argument is of invalid type"
         assert hasattr(entry, 'mountpoint'), "Missing mountpoint attribute."
+        assert entry.device is not None, "No device specified"
+        assert entry.mountpoint is not None, "No mountpoint defined for this entry"
         sep = " "*5
         if entry.uuid is None:
             entry.uuid = entry.find_uuid()
             if item.device == device_path:
                 return True
         return False
+
+
+class FstabTests(unittest.TestCase):
+    def setUp(self):
+        self.fobject = Fstab(fstab_path = "/tmp/test-fstab")
+        self.fentry = FstabEntry(device = "/dev/sda1",
+            mountpoint = "/",
+            filesystem = "ext2")
+    
+    def test_makeEntry(self):
+        """Test the attributes on the entry"""
+        self.assertEqual(self.fentry.device, "/dev/sda1")
+        self.assertEqual(self.fentry.filesystem, "ext2")
+        self.assertEqual(self.fentry.mountpoint, "/")
+    
+    def test_add_invalid_entry(self):
+        self.assertRaises(AssertionError, self.fobject.add_entry, "/dev/sda1")
+    
+    def test_add_incomplete_entry(self):
+        self.fentry.mountpoint = None
+        self.fentry.device = None
+        self.assertRaises(AssertionError, self.fobject.add_entry, self.fentry)
+        self.assertRaises(AssertionError, self.fobject.add_entry, self.fentry)
+    
+    def test_add_valid_entry(self):
+        self.fobject.add_entry(self.fentry)
+        self.assertTrue(self.fobject.has_entry, "/dev/sda1")
+        rentry = self.fobject.get_entry("/dev/sda1")
+        
+        self.assertEqual(rentry.device, self.fentry.device)
+        self.assertEqual(rentry.filesystem, self.fentry.filesystem)
+        self.assertEqual(rentry.mountpoint, self.fentry.mountpoint)
+    
+
+if __name__ == "__main__":
+    unittest.main()