| 79 | | |
|---|
| 80 | | |
|---|
| 81 | | class TestRemoveAndRename(Base): |
|---|
| 82 | | """Removing and renaming files.""" |
|---|
| 83 | | |
|---|
| 84 | | def test_remove(self): |
|---|
| 85 | | """Test FTPHost.remove.""" |
|---|
| 86 | | host = self.host |
|---|
| 87 | | # try to remove a file which is not there |
|---|
| 88 | | self.assertRaises( ftputil.PermanentError, host.remove, |
|---|
| 89 | | host.path.join(self.testdir, 'notthere') ) |
|---|
| 90 | | # remove a directory and check if it's removed |
|---|
| 91 | | host.mkdir( host.path.join(self.testdir, '__test2') ) |
|---|
| 92 | | host.remove( host.path.join(self.testdir, '__test2') ) |
|---|
| 93 | | self.failIf( host.path.exists( host.path.join( |
|---|
| 94 | | self.testdir, '__test2') ) ) |
|---|
| 95 | | # remove a file and check if it's removed |
|---|
| 96 | | host.upload( 'ftputil.py', host.path.join(self.testdir, |
|---|
| 97 | | 'ftputil2.py'), 'b' ) |
|---|
| 98 | | host.unlink( host.path.join(self.testdir, |
|---|
| 99 | | 'ftputil2.py') ) |
|---|
| 100 | | self.failIf( host.path.exists( host.path.join( |
|---|
| 101 | | self.testdir, 'ftputil2.py') ) ) |
|---|
| 102 | | |
|---|
| 103 | | def test_rename(self): |
|---|
| 104 | | """Test FTPHost.rename.""" |
|---|
| 105 | | host = self.host |
|---|
| 106 | | # try to rename a file which is not there |
|---|
| 107 | | host.chdir(self.testdir) |
|---|
| 108 | | self.assertRaises(ftputil.PermanentError, host.rename, |
|---|
| 109 | | 'notthere', 'notthere2') |
|---|
| 110 | | # upload a file, rename it and look if the name |
|---|
| 111 | | # has changed |
|---|
| 112 | | host.upload('ftputil.py', 'ftputil2.py', 'b') |
|---|
| 113 | | host.rename('ftputil2.py', 'ftputil3.py') |
|---|
| 114 | | self.failIf( host.path.exists('ftputil2.py') ) |
|---|
| 115 | | self.failUnless( host.path.exists('ftputil3.py') ) |
|---|
| 116 | | # clean up |
|---|
| 117 | | host.remove('ftputil3.py') |
|---|
| 118 | | host.chdir(self.rootdir) |
|---|