|
| 1 | +# test_submodule.py |
| 2 | +# Copyright (C) 2008-2010 Michael Trier ([email protected]) and contributors |
| 3 | +# |
| 4 | +# This module is part of GitPython and is released under |
| 5 | +# the BSD License: http://www.opensource.org/licenses/bsd-license.php |
| 6 | + |
| 7 | +import os.path |
| 8 | +import sys |
| 9 | + |
| 10 | +execpath = os.getcwd() |
| 11 | +sys.path.append(os.path.join(execpath, 'gitpython\lib')) |
| 12 | + |
| 13 | +import unittest |
| 14 | +import tempfile |
| 15 | +import shutil |
| 16 | +import zipfile |
| 17 | + |
| 18 | +from test.testlib import * |
| 19 | +from git import * |
| 20 | + |
| 21 | +class test_Submodule(unittest.TestCase): |
| 22 | + |
| 23 | + def setUp(self): |
| 24 | + _p = tempfile.mkdtemp() |
| 25 | + demo_repos_file = fixture_path('sample_tree_of_repos_v1.zip') |
| 26 | + zipfile.ZipFile(demo_repos_file).extractall(_p) |
| 27 | + self.base_path = os.path.join(_p, 'reposbase') |
| 28 | + |
| 29 | + def tearDown(self): |
| 30 | + shutil.rmtree(self.base_path, True) |
| 31 | + |
| 32 | + def dtest_01_browser_methods(self): |
| 33 | + _m = self._rpc_tree['browser.listdir'] |
| 34 | + self.assertEquals( |
| 35 | + _m(''), |
| 36 | + {'path':'/', 'dirs':[{'name':'projects'},{'name':'teams'},{'name':'users'}]} |
| 37 | + ) |
| 38 | + self.assertEquals( |
| 39 | + _m('/'), |
| 40 | + {'path':'/', 'dirs':[{'name':'projects'},{'name':'teams'},{'name':'users'}]} |
| 41 | + ) |
| 42 | + self.assertEquals( |
| 43 | + _m('\\'), |
| 44 | + {'path':'/', 'dirs':[{'name':'projects'},{'name':'teams'},{'name':'users'}]} |
| 45 | + ) |
| 46 | + # crossing fingers and hoping the order is same on all platforms. |
| 47 | + self.assertEquals( |
| 48 | + _m('projects'), |
| 49 | + {'path':'/projects', 'dirs':[ |
| 50 | + {'name':'common_files'}, |
| 51 | + {'name':'demorepoone','is_git_dir':True}, |
| 52 | + {'name':'projectone','is_git_dir':True} |
| 53 | + ]} |
| 54 | + ) |
| 55 | + self.assertEquals( |
| 56 | + _m('projects/common_files'), |
| 57 | + {'path':'/projects/common_files', 'dirs':[]} |
| 58 | + ) |
| 59 | + # we don't allow seeing files / folders inside repo folders |
| 60 | + self.assertRaises(grm.PathUnfitError, _m, 'projects/demorepoone') |
| 61 | + self.assertRaises(grm.PathUnfitError, _m, 'projects/demorepoone/objects') |
| 62 | + # on top of fobiden, it also does not exist. |
| 63 | + self.assertRaises(grm.PathUnfitError, _m, 'projects/demorepoone/kjhgjg') |
| 64 | + # all these should not exist |
| 65 | + self.assertRaises(grm.PathUnfitError, _m, 'projects/blah') |
| 66 | + self.assertRaises(grm.PathUnfitError, _m, '/blah') |
| 67 | + # we should forbid seeing contents of folders above base path. |
| 68 | + self.assertRaises(grm.PathUnfitError, _m, 'projects/../../../blah') |
| 69 | + |
| 70 | +if __name__ == "__main__": |
| 71 | + unittest.TextTestRunner(verbosity=2).run( |
| 72 | + unittest.TestSuite([ |
| 73 | + unittest.TestLoader().loadTestsFromTestCase(test_Submodule), |
| 74 | + ]) |
| 75 | + ) |
0 commit comments