Skip to content

Commit d5c8cbd

Browse files
committed
improve testing
1 parent 30e7c9d commit d5c8cbd

2 files changed

Lines changed: 34 additions & 1 deletion

File tree

ddsc/sdk/tests/test_client.py

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from unittest import TestCase
22
from 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
44
from ddsc.core.util import KindType
55
from mock import patch, Mock, call
66

@@ -768,6 +768,24 @@ def test_child_not_found(self):
768768
with self.assertRaises(ItemNotFound):
769769
child_finder.get_child()
770770

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_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+
771789

772790
class TestPathToFiles(TestCase):
773791
def test_path_creation(self):

ddsc/sdk/tests/test_dukeds.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,21 @@ def test_move_file_or_folder(self, mock_client):
205205
DukeDS.move_file_or_folder('myproject', '/data/file1.txt', '/data/file1_bak.txt')
206206
mock_project.move_file_or_folder.assert_called_with('/data/file1.txt', '/data/file1_bak.txt')
207207

208+
@patch('ddsc.sdk.dukeds.Client')
209+
def test_create_folder(self, mock_client):
210+
mock_project = Mock()
211+
mock_project.try_get_item_for_path.return_value = None
212+
mock_project.create_folder.return_value.try_get_item_for_path.return_value = None
213+
mock_project.name = 'myproject'
214+
mock_client.return_value.get_projects.return_value = [
215+
mock_project
216+
]
217+
DukeDS.create_folder('myproject', '/data/raw')
218+
mock_project.create_folder.assert_called_with("data")
219+
mock_project.create_folder.return_value.create_folder.assert_called_with("raw")
220+
221+
222+
208223

209224
class TestSession(TestCase):
210225
@patch('ddsc.sdk.dukeds.Client', autospec=True)

0 commit comments

Comments
 (0)