| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent cfd2121 commit 61dbe88
7 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -29,7 +29,7 @@ class Submodule(object): | |||
| 29 | 29 | """ | |
| 30 | 30 | ||
| 31 | 31 | def __init__(self, repo=None, id=None, mode=None, name='', | |
| 32 | - commit_context=None, path=''): | ||
| 32 | + commit_context='', path=''): | ||
| 33 | 33 | """ | |
| 34 | 34 | Initialize a newly instanced Submodule | |
| 35 | 35 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -10,7 +10,7 @@ | |||
| 10 | 10 | import submodule | |
| 11 | 11 | ||
| 12 | 12 | class Tree(LazyMixin): | |
| 13 | - def __init__(self, repo, id, mode=None, name=None, commit_context = None, path = ''): | ||
| 13 | + def __init__(self, repo, id, mode=None, name=None, commit_context = '', path = ''): | ||
| 14 | 14 | LazyMixin.__init__(self) | |
| 15 | 15 | self.repo = repo | |
| 16 | 16 | self.id = id | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,3 @@ | |||
| 1 | + [Dolphin] | ||
| 2 | + Timestamp=2010,10,28,0,8,28 | ||
| 3 | + ViewMode=1 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,75 @@ | |||
| 1 | + # test_submodule.py | ||
| 2 | + # Copyright (C) 2008-2010 Michael Trier (mtrier@gmail.com) 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 | + ) | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -48,7 +48,11 @@ def test_content_from_string_tree_should_return_commit(self): | |||
| 48 | 48 | text = fixture('ls_tree_commit').split("\n")[1] | |
| 49 | 49 | ||
| 50 | 50 | tree = Tree.content_from_string(None, text) | |
| 51 | - assert_none(tree) | ||
| 51 | + | ||
| 52 | + assert_equal(Submodule, tree.__class__) | ||
| 53 | + assert_equal("d35b34c6e931b9da8f6941007a92c9c9a9b0141a", tree.id) | ||
| 54 | + # assert_equal("100644", tree.mode) # mode of submodule is irrelevant. | ||
| 55 | + assert_equal("bar", tree.name) | ||
| 52 | 56 | ||
| 53 | 57 | @raises(TypeError) | |
| 54 | 58 | def test_content_from_string_invalid_type_should_raise(self): | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,75 @@ | |||
| 1 | + # test_submodule.py | ||
| 2 | + # Copyright (C) 2008-2010 Michael Trier (mtrier@gmail.com) 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 | + ) | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments