/usr/lib/python2.7/dist-packages/nss_cache/maps/automount_test.py is in nsscache 0.32-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 | # Copyright 2007 Google Inc.
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program 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 this program; if not, write to the Free Software Foundation,
# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
"""Unit tests for automount.py.
We only test what is overridden in the automount subclasses, most
functionality is in base.py and tested in passwd_test.py since a
subclass is required to test the abstract class functionality.
"""
__author__ = 'vasilios@google.com (Vasilios Hoffman)'
import unittest
from nss_cache.maps import automount
from nss_cache.maps import passwd
class TestAutomountMap(unittest.TestCase):
"""Tests for the AutomountMap class."""
def __init__(self, obj):
"""Set some default avalible data for testing."""
super(TestAutomountMap, self).__init__(obj)
self._good_entry = automount.AutomountMapEntry()
self._good_entry.key = 'foo'
self._good_entry.options = '-tcp'
self._good_entry.location = 'nfsserver:/mah/stuff'
def testInit(self):
"""Construct an empty or seeded AutomountMap."""
self.assertEquals(automount.AutomountMap, type(automount.AutomountMap()),
msg='failed to create an empty AutomountMap')
amap = automount.AutomountMap([self._good_entry])
self.assertEquals(self._good_entry, amap.PopItem(),
msg='failed to seed AutomountMap with list')
self.assertRaises(TypeError, automount.AutomountMap, ['string'])
def testAdd(self):
"""Add throws an error for objects it can't verify."""
amap = automount.AutomountMap()
entry = self._good_entry
self.assert_(amap.Add(entry), msg='failed to append new entry.')
self.assertEquals(1, len(amap), msg='unexpected size for Map.')
ret_entry = amap.PopItem()
self.assertEquals(ret_entry, entry, msg='failed to pop correct entry.')
pentry = passwd.PasswdMapEntry()
pentry.name = 'foo'
pentry.uid = 10
pentry.gid = 10
self.assertRaises(TypeError, amap.Add, pentry)
class TestAutomountMapEntry(unittest.TestCase):
"""Tests for the AutomountMapEntry class."""
def testInit(self):
"""Construct an empty and seeded AutomountMapEntry."""
self.assert_(automount.AutomountMapEntry(),
msg='Could not create empty AutomountMapEntry')
seed = {'key': 'foo', 'location': '/dev/sda1'}
entry = automount.AutomountMapEntry(seed)
self.assert_(entry.Verify(),
msg='Could not verify seeded AutomountMapEntry')
self.assertEquals(entry.key, 'foo',
msg='Entry returned wrong value for name')
self.assertEquals(entry.options, None,
msg='Entry returned wrong value for options')
self.assertEquals(entry.location, '/dev/sda1',
msg='Entry returned wrong value for location')
def testAttributes(self):
"""Test that we can get and set all expected attributes."""
entry = automount.AutomountMapEntry()
entry.key = 'foo'
self.assertEquals(entry.key, 'foo',
msg='Could not set attribute: key')
entry.options = 'noatime'
self.assertEquals(entry.options, 'noatime',
msg='Could not set attribute: options')
entry.location = '/dev/ipod'
self.assertEquals(entry.location, '/dev/ipod',
msg='Could not set attribute: location')
def testVerify(self):
"""Test that the object can verify it's attributes and itself."""
entry = automount.AutomountMapEntry()
# Empty object should bomb
self.failIf(entry.Verify())
def testKey(self):
"""Key() should return the value of the 'key' attribute."""
entry = automount.AutomountMapEntry()
entry.key = 'foo'
self.assertEquals(entry.Key(), entry.key)
if __name__ == '__main__':
unittest.main()
|