import unittest
import nfs
import mock
import sys


class Test_nfs(unittest.TestCase):

    @mock.patch('util.pread')
    def test_check_server_tcp(self, pread):
        nfs.check_server_tcp('aServer')

        pread.assert_called_once_with(['/usr/sbin/rpcinfo', '-p', 'aServer'], quiet=False)

    @mock.patch('util.pread')
    def test_check_server_tcp_nfsversion(self, pread):
        nfs.check_server_tcp('aServer', 'aNfsversion')

        pread.assert_called_once_with(['/usr/sbin/rpcinfo', '-p', 'aServer'], quiet=False)

    def get_soft_mount_pread(self, binary, vers):
        return ([binary, 'remoteserver:remotepath', 'mountpoint', '-o',
                 'soft,proto=transport,vers=%s,acdirmin=0,acdirmax=0' % vers])

    @mock.patch('util.makedirs')
    @mock.patch('util.pread')
    def test_soft_mount(self, pread, makedirs):
        nfs.soft_mount('mountpoint', 'remoteserver', 'remotepath', 'transport',
                       timeout=None)

        pread.assert_called_once_with(self.get_soft_mount_pread('mount.nfs',
                                                                '3'))

    @mock.patch('util.makedirs')
    @mock.patch('util.pread')
    def test_soft_mount_nfsversion_3(self, pread, makedirs):
        nfs.soft_mount('mountpoint', 'remoteserver', 'remotepath', 'transport',
                       timeout=None, nfsversion='3')

        pread.assert_called_once_with(self.get_soft_mount_pread('mount.nfs',
                                                                '3'))

    @mock.patch('util.makedirs')
    @mock.patch('util.pread')
    def test_soft_mount_nfsversion_4(self, pread, makedirs):
        nfs.soft_mount('mountpoint', 'remoteserver', 'remotepath', 'transport',
                       timeout=None, nfsversion='4')

        pread.assert_called_once_with(self.get_soft_mount_pread('mount.nfs4',
                                                                '4'))

    def test_validate_nfsversion_invalid(self):
        for thenfsversion in ['2', '4.1']:
            self.assertRaises(nfs.NfsException, nfs.validate_nfsversion,
                              thenfsversion)

    def test_validate_nfsversion_default(self):
        for thenfsversion in ['', None]:
            self.assertEquals(nfs.validate_nfsversion(thenfsversion), '3')

    def test_validate_nfsversion_valid(self):
        for thenfsversion in ['3', '4']:
            self.assertEquals(nfs.validate_nfsversion(thenfsversion),
                              thenfsversion)

@@ -517,24 +517,273 @@
 iet=False)%0A%0A
+    @mock.patch('util.pread')%0A    def test_check_server_service(self, pread):%0A        nfs.check_server_service('aServer')%0A%0A        pread.assert_called_once_with(%5B'/usr/sbin/rpcinfo', '-t', %0A                                       'aServer', 'nfs'%5D)%0A%0A
     def get_
@@ -997,32 +997,76 @@
 util.makedirs')%0A
+    @mock.patch('nfs.check_server_service')%0A
     @mock.patch(
@@ -1107,32 +1107,54 @@
 unt(self, pread,
+ check_server_service,
  makedirs):%0A    
@@ -1263,24 +1263,93 @@
 eout=None)%0A%0A
+        check_server_service.assert_called_once_with('remoteserver')%0A
         prea
@@ -1509,32 +1509,76 @@
 util.makedirs')%0A
+    @mock.patch('nfs.check_server_service')%0A
     @mock.patch(
@@ -1633,32 +1633,92 @@
 _3(self, pread, 
+%0A                                     check_server_service, 
 makedirs):%0A     
@@ -1846,37 +1846,52 @@
 n='3')%0A%0A        
-pread
+check_server_service
 .assert_called_o
@@ -1891,32 +1891,81 @@
 alled_once_with(
+'remoteserver')%0A        pread.assert_called_with(
 self.get_soft_mo
@@ -2083,32 +2083,76 @@
 util.makedirs')%0A
+    @mock.patch('nfs.check_server_service')%0A
     @mock.patch(
@@ -2215,16 +2215,76 @@
  pread, 
+%0A                                     check_server_service, 
 makedirs
@@ -2416,24 +2416,93 @@
 rsion='4')%0A%0A
+        check_server_service.assert_called_once_with('remoteserver')%0A
         prea
@@ -2509,37 +2509,32 @@
 d.assert_called_
-once_
 with(self.get_so

Create unit tests for check_server_service