11from unittest import TestCase
22from ddsc .sdk .client import Client , DDSConnection , BaseResponseItem , Project , Folder , File , FileDownload , FileUpload , \
3- ChildFinder , PathToFiles , ItemNotFound , ProjectSummary
3+ ChildFinder , PathToFiles , ItemNotFound , ProjectSummary , REMOTE_PATH_SEP
44from ddsc .core .util import KindType
55from mock import patch , Mock , call
66
@@ -472,40 +472,14 @@ def test_get_children(self):
472472 def test_get_child_for_path (self , mock_child_finder ):
473473 mock_dds_connection = Mock ()
474474 mock_child = Mock ()
475- mock_child_finder .return_value . get_child .return_value = mock_child
475+ mock_child_finder .get_child_for_path .return_value = mock_child
476476
477477 project = Project (mock_dds_connection , self .project_dict )
478478 child = project .get_child_for_path ('/data/file1.dat' )
479479
480- mock_child_finder .assert_called_with ('/data/file1.dat' , project )
480+ mock_child_finder .get_child_for_path . assert_called_with (project , '/data/file1.dat' )
481481 self .assertEqual (child , mock_child )
482482
483- @patch ('ddsc.sdk.client.ChildFinder' )
484- def test_try_get_item_for_path__with_project (self , mock_child_finder ):
485- mock_dds_connection = Mock ()
486- project = Project (mock_dds_connection , self .project_dict )
487- project .get_child_for_path = Mock ()
488- item = project .try_get_item_for_path ('/' )
489- self .assertEqual (item , project )
490- project .get_child_for_path .assert_not_called ()
491-
492- def test_try_get_item_for_path__with_child (self ):
493- mock_dds_connection = Mock ()
494- project = Project (mock_dds_connection , self .project_dict )
495- project .get_child_for_path = Mock ()
496- item = project .try_get_item_for_path ('/data/file1.dat' )
497- self .assertEqual (item , project .get_child_for_path .return_value )
498- project .get_child_for_path .assert_called_with ('/data/file1.dat' )
499-
500- def test_try_get_item_for_path__child_not_found (self ):
501- mock_dds_connection = Mock ()
502- project = Project (mock_dds_connection , self .project_dict )
503- project .get_child_for_path = Mock ()
504- project .get_child_for_path .side_effect = ItemNotFound ("Not Found" )
505- item = project .try_get_item_for_path ('/data/file1.dat' )
506- self .assertEqual (item , None )
507- project .get_child_for_path .assert_called_with ('/data/file1.dat' )
508-
509483 def test_create_folder (self ):
510484 mock_dds_connection = Mock ()
511485 mock_folder = Mock ()
@@ -764,7 +738,7 @@ def test_direct_children(self):
764738 mock_folder ,
765739 mock_file
766740 ]
767- child_finder = ChildFinder ('data.txt' , mock_project )
741+ child_finder = ChildFinder (mock_project , 'data.txt' )
768742 found_child = child_finder .get_child ()
769743 self .assertEqual (found_child , mock_file )
770744
@@ -780,7 +754,7 @@ def test_grand_children(self):
780754 mock_project .get_children .return_value = [
781755 mock_folder ,
782756 ]
783- child_finder = ChildFinder ('results/data.txt' , mock_project )
757+ child_finder = ChildFinder (mock_project , 'results/data.txt' )
784758 found_child = child_finder .get_child ()
785759 self .assertEqual (found_child , mock_file )
786760
@@ -790,10 +764,28 @@ def test_child_not_found(self):
790764 mock_project .get_children .return_value = [
791765 mock_folder ,
792766 ]
793- child_finder = ChildFinder ('data.txt' , mock_project )
767+ child_finder = ChildFinder (mock_project , 'data.txt' )
794768 with self .assertRaises (ItemNotFound ):
795769 child_finder .get_child ()
796770
771+ def test_try_get_item_for_path_with_slash (self ):
772+ node = Mock ()
773+ result = ChildFinder .try_get_item_for_path (node , REMOTE_PATH_SEP )
774+ self .assertEqual (result , node )
775+
776+ @patch ('ddsc.sdk.client.ChildFinder.get_child_for_path' )
777+ def test_try_get_item_for_path_with_child_found (self , mock_get_child_for_path ):
778+ node = Mock ()
779+ result = ChildFinder .try_get_item_for_path (node , '/file.txt' )
780+ self .assertEqual (result , mock_get_child_for_path .return_value )
781+
782+ @patch ('ddsc.sdk.client.ChildFinder.get_child_for_path' )
783+ def test_try_get_item_for_path_with_child_not_found (self , mock_get_child_for_path ):
784+ mock_get_child_for_path .side_effect = ItemNotFound ()
785+ node = Mock ()
786+ result = ChildFinder .try_get_item_for_path (node , '/file.txt' )
787+ self .assertEqual (result , None )
788+
797789
798790class TestPathToFiles (TestCase ):
799791 def test_path_creation (self ):
0 commit comments