Skip to content

Commit

Permalink
Use the new module api for glossary, uses and dataprocessings
Browse files Browse the repository at this point in the history
  • Loading branch information
drscholly committed Nov 30, 2024
1 parent 04dc5f6 commit 03b438c
Show file tree
Hide file tree
Showing 11 changed files with 236 additions and 231 deletions.
40 changes: 20 additions & 20 deletions tests/test_copy_glossary.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from toolbox.api.datagalaxy_api_glossary import DataGalaxyApiGlossary
from toolbox.api.datagalaxy_api_modules import DataGalaxyApiModules
from toolbox.api.datagalaxy_api_workspaces import DataGalaxyApiWorkspace
from toolbox.commands.copy_glossary import copy_glossary
from toolbox.api.datagalaxy_api import DataGalaxyBulkResult
Expand All @@ -7,32 +7,32 @@

# Mocks

def mock_list_properties_on_source_workspace(self, workspace_name):
def mock_list_objects_on_source_workspace(self, workspace_name):
if workspace_name == 'workspace_source':
return ['property1', 'property1', 'property1']
return [['object1', 'object2', 'object']]
return []


# Scenarios

def test_copy_glossary_when_no_property_on_target(mocker):
def test_copy_objects_when_no_object_on_target(mocker):
# GIVEN
workspaces = mocker.patch.object(DataGalaxyApiWorkspace, 'list_workspaces', autospec=True)
workspaces.return_value = ['workspace_source', 'workspace_target']
workspace_source_mock = mocker.patch.object(DataGalaxyApiWorkspace, 'get_workspace', autospec=True)
workspace_source_mock.return_value = 'workspace_source'
glossary_properties_on_source_workspace_mock = mocker.patch.object(
DataGalaxyApiGlossary,
'list_properties',
workspace_source_mock.return_value = {'name': 'workspace', 'isVersioningEnabled': False}
objects_on_source_workspace_mock = mocker.patch.object(
DataGalaxyApiModules,
'list_objects',
autospec=True
)
glossary_properties_on_source_workspace_mock.side_effect = mock_list_properties_on_source_workspace
bulk_upsert_properties_on_target_workspace_mock = mocker.patch.object(
DataGalaxyApiGlossary,
'bulk_upsert_property_tree',
objects_on_source_workspace_mock.side_effect = mock_list_objects_on_source_workspace
bulk_upsert_objects_on_target_workspace_mock = mocker.patch.object(
DataGalaxyApiModules,
'bulk_upsert_tree',
autospec=True
)
bulk_upsert_properties_on_target_workspace_mock.return_value = DataGalaxyBulkResult(
bulk_upsert_objects_on_target_workspace_mock.return_value = DataGalaxyBulkResult(
total=3,
created=3,
updated=0,
Expand All @@ -54,8 +54,8 @@ def test_copy_glossary_when_no_property_on_target(mocker):
# ASSERT / VERIFY

assert result == DataGalaxyBulkResult(total=3, created=3, updated=0, unchanged=0, deleted=0)
assert glossary_properties_on_source_workspace_mock.call_count == 1
assert bulk_upsert_properties_on_target_workspace_mock.call_count == 1
assert objects_on_source_workspace_mock.call_count == 1
assert bulk_upsert_objects_on_target_workspace_mock.call_count == 1


def test_copy_glossary_when_workspace_target_does_not_exist(mocker):
Expand All @@ -64,13 +64,13 @@ def test_copy_glossary_when_workspace_target_does_not_exist(mocker):
workspaces.return_value = ['workspace_source']
workspace_source_mock = mocker.patch.object(DataGalaxyApiWorkspace, 'get_workspace', autospec=True)
workspace_source_mock.return_value = None
glossary_properties_on_source_workspace_mock = mocker.patch.object(DataGalaxyApiGlossary,
'list_properties',
autospec=True)
glossary_properties_on_source_workspace_mock.side_effect = mock_list_properties_on_source_workspace
objects_on_source_workspace_mock = mocker.patch.object(DataGalaxyApiModules,
'list_objects',
autospec=True)
objects_on_source_workspace_mock.side_effect = mock_list_objects_on_source_workspace

# ASSERT / VERIFY
with pytest.raises(Exception, match='workspace workspace_target does not exist'):
with pytest.raises(Exception, match='workspace workspace_source does not exist'):
copy_glossary(
url_source='url_source',
token_source='token_source',
Expand Down
40 changes: 20 additions & 20 deletions tests/test_copy_usages.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from toolbox.api.datagalaxy_api_usages import DataGalaxyApiUsages
from toolbox.api.datagalaxy_api_modules import DataGalaxyApiModules
from toolbox.commands.copy_usages import copy_usages
from toolbox.api.datagalaxy_api_workspaces import DataGalaxyApiWorkspace
from toolbox.api.datagalaxy_api import DataGalaxyBulkResult
Expand All @@ -7,32 +7,32 @@

# Mocks

def mock_list_usages_on_source_workspace(self, workspace_name):
def mock_list_objects_on_source_workspace(self, workspace_name):
if workspace_name == 'workspace_source':
return ['usage1', 'usage2', 'usage3']
return [['object1', 'object2', 'object3']]
return []


# Scenarios

def test_copy_usages_when_no_usage_on_target(mocker):
def test_copy_objects_when_no_object_on_target(mocker):
# GIVEN
workspaces = mocker.patch.object(DataGalaxyApiWorkspace, 'list_workspaces', autospec=True)
workspaces.return_value = ['workspace_source', 'workspace_target']
workspace_source_mock = mocker.patch.object(DataGalaxyApiWorkspace, 'get_workspace', autospec=True)
workspace_source_mock.return_value = 'workspace_source'
usages_on_source_workspace_mock = mocker.patch.object(
DataGalaxyApiUsages,
'list_usages',
workspace_source_mock.return_value = {'name': 'workspace', 'isVersioningEnabled': False}
objects_on_source_workspace_mock = mocker.patch.object(
DataGalaxyApiModules,
'list_objects',
autospec=True
)
usages_on_source_workspace_mock.side_effect = mock_list_usages_on_source_workspace
bulk_upsert_usages_on_target_workspace_mock = mocker.patch.object(
DataGalaxyApiUsages,
'bulk_upsert_usages_tree',
objects_on_source_workspace_mock.side_effect = mock_list_objects_on_source_workspace
bulk_upsert_objects_on_target_workspace_mock = mocker.patch.object(
DataGalaxyApiModules,
'bulk_upsert_tree',
autospec=True
)
bulk_upsert_usages_on_target_workspace_mock.return_value = DataGalaxyBulkResult(
bulk_upsert_objects_on_target_workspace_mock.return_value = DataGalaxyBulkResult(
total=3,
created=3,
updated=0,
Expand All @@ -54,8 +54,8 @@ def test_copy_usages_when_no_usage_on_target(mocker):
# ASSERT / VERIFY

assert result == DataGalaxyBulkResult(total=3, created=3, updated=0, unchanged=0, deleted=0)
assert usages_on_source_workspace_mock.call_count == 1
assert bulk_upsert_usages_on_target_workspace_mock.call_count == 1
assert objects_on_source_workspace_mock.call_count == 1
assert bulk_upsert_objects_on_target_workspace_mock.call_count == 1


def test_copy_usages_when_workspace_target_does_not_exist(mocker):
Expand All @@ -64,15 +64,15 @@ def test_copy_usages_when_workspace_target_does_not_exist(mocker):
workspaces.return_value = ['workspace_source']
workspace_source_mock = mocker.patch.object(DataGalaxyApiWorkspace, 'get_workspace', autospec=True)
workspace_source_mock.return_value = None
usages_on_source_workspace_mock = mocker.patch.object(
DataGalaxyApiUsages,
'list_usages',
objects_on_source_workspace_mock = mocker.patch.object(
DataGalaxyApiModules,
'list_objects',
autospec=True
)
usages_on_source_workspace_mock.side_effect = mock_list_usages_on_source_workspace
objects_on_source_workspace_mock.side_effect = mock_list_objects_on_source_workspace

# ASSERT / VERIFY
with pytest.raises(Exception, match='workspace workspace_target does not exist'):
with pytest.raises(Exception, match='workspace workspace_source does not exist'):
copy_usages(
url_source='url_source',
token_source='token_source',
Expand Down
33 changes: 15 additions & 18 deletions tests/test_delete_dataprocessings.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,17 @@
from toolbox.api.datagalaxy_api_workspaces import DataGalaxyApiWorkspace
from toolbox.api.datagalaxy_api_dataprocessings import DataGalaxyApiDataprocessings
from toolbox.api.datagalaxy_api_modules import DataGalaxyApiModules
from toolbox.commands.delete_dataprocessings import delete_dataprocessings


# Mock
def mock_list_dataprocessings(self, data_type):
if self.url == 'url':
return [
{
'id': '1',
'name': 'Object',
'description': 'An object in the dataprocessings'
}
]

return []
mock_list_objects = [[
{
'id': '1',
'name': 'Object',
'path': "\\\\Object",
'description': 'Just a simple object'
}
]]


# Scenarios
Expand All @@ -23,14 +20,14 @@ def test_delete_dataprocessings(mocker):
workspaces = mocker.patch.object(DataGalaxyApiWorkspace, 'list_workspaces', autospec=True)
workspaces.return_value = ['workspace']
workspace_mock = mocker.patch.object(DataGalaxyApiWorkspace, 'get_workspace', autospec=True)
workspace_mock.return_value = {'isVersioningEnabled': False}
dataprocessings_list_mock = mocker.patch.object(DataGalaxyApiDataprocessings, 'list_dataprocessings', autospec=True)
dataprocessings_list_mock.side_effect = mock_list_dataprocessings
delete_dataprocessings_mock = mocker.patch.object(DataGalaxyApiDataprocessings, 'delete_objects', autospec=True)
delete_dataprocessings_mock.return_value = True
workspace_mock.return_value = {'name': 'workspace', 'isVersioningEnabled': False}
objects_list_mock = mocker.patch.object(DataGalaxyApiModules, 'list_objects', autospec=True)
objects_list_mock.return_value = mock_list_objects
delete_objects_mock = mocker.patch.object(DataGalaxyApiModules, 'delete_objects', autospec=True)
delete_objects_mock.return_value = True

# THEN
result = delete_dataprocessings(url='url', token='token', workspace_name="workspace")

# ASSERT / VERIFY
assert result is True
assert result == 0
33 changes: 15 additions & 18 deletions tests/test_delete_glossary.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,17 @@
from toolbox.api.datagalaxy_api_workspaces import DataGalaxyApiWorkspace
from toolbox.api.datagalaxy_api_glossary import DataGalaxyApiGlossary
from toolbox.api.datagalaxy_api_modules import DataGalaxyApiModules
from toolbox.commands.delete_glossary import delete_glossary


# Mock
def mock_list_glossary_properties(self, data_type):
if self.url == 'url':
return [
{
'id': '1',
'name': 'Object',
'description': 'An object in the glossary'
}
]

return []
mock_list_objects = [[
{
'id': '1',
'name': 'Object',
'path': "\\\\Object",
'description': 'Just a simple object'
}
]]


# Scenarios
Expand All @@ -23,14 +20,14 @@ def test_delete_glossary(mocker):
workspaces = mocker.patch.object(DataGalaxyApiWorkspace, 'list_workspaces', autospec=True)
workspaces.return_value = ['workspace']
workspace_mock = mocker.patch.object(DataGalaxyApiWorkspace, 'get_workspace', autospec=True)
workspace_mock.return_value = 'workspace'
glossary_list_mock = mocker.patch.object(DataGalaxyApiGlossary, 'list_properties', autospec=True)
glossary_list_mock.side_effect = mock_list_glossary_properties
delete_glossary_mock = mocker.patch.object(DataGalaxyApiGlossary, 'delete_objects', autospec=True)
delete_glossary_mock.return_value = True
workspace_mock.return_value = {'name': 'workspace', 'isVersioningEnabled': False}
objects_list_mock = mocker.patch.object(DataGalaxyApiModules, 'list_objects', autospec=True)
objects_list_mock.return_value = mock_list_objects
delete_objects_mock = mocker.patch.object(DataGalaxyApiModules, 'delete_objects', autospec=True)
delete_objects_mock.return_value = True

# THEN
result = delete_glossary(url='url', token='token', workspace_name="workspace")

# ASSERT / VERIFY
assert result is True
assert result == 0
33 changes: 15 additions & 18 deletions tests/test_delete_usages.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,17 @@
from toolbox.api.datagalaxy_api_workspaces import DataGalaxyApiWorkspace
from toolbox.api.datagalaxy_api_usages import DataGalaxyApiUsages
from toolbox.api.datagalaxy_api_modules import DataGalaxyApiModules
from toolbox.commands.delete_usages import delete_usages


# Mock
def mock_list_usages(self, data_type):
if self.url == 'url':
return [
{
'id': '1',
'name': 'Object',
'description': 'An object in the usages'
}
]

return []
mock_list_objects = [[
{
'id': '1',
'name': 'Object',
'path': "\\\\Object",
'description': 'Just a simple object'
}
]]


# Scenarios
Expand All @@ -23,14 +20,14 @@ def test_delete_usages(mocker):
workspaces = mocker.patch.object(DataGalaxyApiWorkspace, 'list_workspaces', autospec=True)
workspaces.return_value = ['workspace']
workspace_mock = mocker.patch.object(DataGalaxyApiWorkspace, 'get_workspace', autospec=True)
workspace_mock.return_value = 'workspace'
usages_list_mock = mocker.patch.object(DataGalaxyApiUsages, 'list_usages', autospec=True)
usages_list_mock.side_effect = mock_list_usages
delete_usages_mock = mocker.patch.object(DataGalaxyApiUsages, 'delete_objects', autospec=True)
delete_usages_mock.return_value = True
workspace_mock.return_value = {'name': 'workspace', 'isVersioningEnabled': False}
objects_list_mock = mocker.patch.object(DataGalaxyApiModules, 'list_objects', autospec=True)
objects_list_mock.return_value = mock_list_objects
delete_objects_mock = mocker.patch.object(DataGalaxyApiModules, 'delete_objects', autospec=True)
delete_objects_mock.return_value = True

# THEN
result = delete_usages(url='url', token='token', workspace_name="workspace")

# ASSERT / VERIFY
assert result is True
assert result == 0
Loading

0 comments on commit 03b438c

Please sign in to comment.