diff --git a/tests/actionsapitests.py b/tests/actionsapitests.py index 30cf65af..3b7dda80 100644 --- a/tests/actionsapitests.py +++ b/tests/actionsapitests.py @@ -9,6 +9,8 @@ import unittest import zipfile +import shutil +import os import testcase @@ -55,4 +57,52 @@ class ActionsAPITestCase(testcase.TestCase): for file in self.filelist: self.assert_(fileContent.__contains__(file)) + def testShellToolsCopy(self): + from pisi.actionsapi.shelltools import copy + + copy('tests/actionsapitests/brokenlink', 'tests/actionsapitests/brokenlink-copy') + self.assertEqual(os.path.islink('tests/actionsapitests/brokenlink-copy'), True) + os.remove('tests/actionsapitests/brokenlink-copy') + + copy('tests/actionsapitests/brokenlink', 'tests/actionsapitests/adirectory') + self.assertEqual(os.path.islink('tests/actionsapitests/adirectory/brokenlink'), True) + + copy('tests/actionsapitests/brokenlink', 'tests/actionsapitests/adirectory/bl') + self.assertEqual(os.path.islink('tests/actionsapitests/adirectory/bl'), True) + os.remove('tests/actionsapitests/adirectory/bl') + + self.assertEqual(os.readlink('tests/actionsapitests/adirectory/brokenlink'), '/no/such/place') + os.remove('tests/actionsapitests/adirectory/brokenlink') + + copy('tests/actionsapitests/linktoadirectory', 'tests/actionsapitests/adirectory/', False) + self.assertEqual(os.path.exists('tests/actionsapitests/adirectory/linkeddir/file'), True) + self.assertEqual(os.path.getsize('tests/actionsapitests/adirectory/linkeddir/file'), 321) + shutil.rmtree('tests/actionsapitests/adirectory/linkeddir') + + copy('tests/actionsapitests/file', 'tests/actionsapitests/adirectory') + self.assertEqual(os.path.isfile('tests/actionsapitests/adirectory/file'), True) + #overwrite.. + copy('tests/actionsapitests/file', 'tests/actionsapitests/adirectory') + os.remove('tests/actionsapitests/adirectory/file') + + copy('tests/actionsapitests/linktoafile', 'tests/actionsapitests/adirectory', False) + self.assertEqual(os.path.exists('tests/actionsapitests/adirectory/%s' % (os.path.basename(os.readlink('tests/actionsapitests/linktoafile')))), True) + os.remove('tests/actionsapitests/adirectory/%s' % (os.path.basename(os.readlink('tests/actionsapitests/linktoafile')))) + + copy('tests/actionsapitests/file', 'tests/actionsapitests/file-copy') + self.assertEqual(os.path.exists('tests/actionsapitests/file-copy'), True) + os.remove('tests/actionsapitests/file-copy') + + copy('tests/actionsapitests/file', 'tests/actionsapitests/adirectory/filewithanothername') + self.assertEqual(os.path.exists('tests/actionsapitests/adirectory/filewithanothername'), True) + os.remove('tests/actionsapitests/adirectory/filewithanothername') + + copy('tests/actionsapitests/linkeddir', 'tests/actionsapitests/adirectory') + self.assertEqual(os.path.exists('tests/actionsapitests/adirectory/linkeddir/file'), True) + shutil.rmtree('tests/actionsapitests/adirectory/linkeddir') + + copy('tests/actionsapitests/linkeddir', 'tests/actionsapitests/adirectory/withanothername') + self.assertEqual(os.path.exists('tests/actionsapitests/adirectory/withanothername/file'), True) + shutil.rmtree('tests/actionsapitests/adirectory/withanothername') + suite = unittest.makeSuite(ActionsAPITestCase) diff --git a/tests/actionsapitests/brokenlink b/tests/actionsapitests/brokenlink new file mode 120000 index 00000000..8f608d48 --- /dev/null +++ b/tests/actionsapitests/brokenlink @@ -0,0 +1 @@ +/no/such/place \ No newline at end of file diff --git a/tests/actionsapitests/file b/tests/actionsapitests/file new file mode 100644 index 00000000..2c435ef3 --- /dev/null +++ b/tests/actionsapitests/file @@ -0,0 +1,6 @@ +toplam 4 +drwxr-xr-x 2 meren users 4096 Mar 10 12:55 adirectory +lrwxrwxrwx 1 meren users 14 Mar 10 12:41 brokenlink -> /no/such/place +-rw-r--r-- 1 meren users 0 Mar 10 12:57 file +lrwxrwxrwx 1 meren users 4 Mar 10 12:42 linktoadirectory -> /etc +lrwxrwxrwx 1 meren users 11 Mar 10 12:42 linktoafile -> /etc/passwd diff --git a/tests/actionsapitests/linkeddir/file b/tests/actionsapitests/linkeddir/file new file mode 100644 index 00000000..2c435ef3 --- /dev/null +++ b/tests/actionsapitests/linkeddir/file @@ -0,0 +1,6 @@ +toplam 4 +drwxr-xr-x 2 meren users 4096 Mar 10 12:55 adirectory +lrwxrwxrwx 1 meren users 14 Mar 10 12:41 brokenlink -> /no/such/place +-rw-r--r-- 1 meren users 0 Mar 10 12:57 file +lrwxrwxrwx 1 meren users 4 Mar 10 12:42 linktoadirectory -> /etc +lrwxrwxrwx 1 meren users 11 Mar 10 12:42 linktoafile -> /etc/passwd diff --git a/tests/actionsapitests/linktoadirectory b/tests/actionsapitests/linktoadirectory new file mode 120000 index 00000000..f70a2aa6 --- /dev/null +++ b/tests/actionsapitests/linktoadirectory @@ -0,0 +1 @@ +tests/actionsapitests/linkeddir/ \ No newline at end of file diff --git a/tests/actionsapitests/linktoafile b/tests/actionsapitests/linktoafile new file mode 120000 index 00000000..41a5880c --- /dev/null +++ b/tests/actionsapitests/linktoafile @@ -0,0 +1 @@ +tests/actionsapitests/file \ No newline at end of file