Skip to content

Commit

Permalink
Remove old authenticate method
Browse files Browse the repository at this point in the history
  • Loading branch information
drscholly committed Nov 25, 2024
1 parent 4aad491 commit 0299ce2
Show file tree
Hide file tree
Showing 37 changed files with 158 additions and 470 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,11 @@ If you want to use Toolbox on Mac or Linux you need to build a binary file follo
##### Flags
- [optional arguments] `-h`, `--help`- show help message
- `--url` - URL
- `--token` - Integration token
- `--token` - Token
- `--url-source`- URL source environnement
- `--url-target` - URL target environnement
- `--token-source` - Integration token from source environnement
- `--token-target` - Integration token from target environnement
- `--token-source` - Token from source environnement
- `--token-target` - Token from target environnement
- `--workspace-source` - Workspace source name
- `--workspace-target` - Workspace target name
- `--tag-value` - Filter objects on a specific tag
Expand Down
39 changes: 8 additions & 31 deletions tests/test_copy_attributes.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
from toolbox.api.datagalaxy_api import DataGalaxyApiAuthentication, Token
from toolbox.api.datagalaxy_api_attributes import AttributeDataType, DataGalaxyApiAttributes
from toolbox.commands.copy_attributes import copy_attributes
from unittest.mock import ANY
Expand Down Expand Up @@ -63,10 +62,6 @@ def test_copy_attributes_when_only_one_source_attr_and_duplicates_on_target(mock
:param mocker:
:return: raise Exception
"""
client_space_mock = mocker.patch.object(Token, 'get_client_space_id', autospec=True)
client_space_mock.return_value = 'cid'
api_authenticate_mock = mocker.patch.object(DataGalaxyApiAuthentication, 'authenticate', autospec=True)
api_authenticate_mock.return_value = 'token'
attributes_list_mock = mocker.patch.object(DataGalaxyApiAttributes, 'list', autospec=True)
attributes_list_mock.side_effect = list_mock_when_duplicates
attributes_bulk_create_mock = mocker.patch.object(DataGalaxyApiAttributes, 'bulk_create', autospec=True)
Expand All @@ -76,8 +71,8 @@ def test_copy_attributes_when_only_one_source_attr_and_duplicates_on_target(mock
result = copy_attributes(
url_source='url_source',
url_target='url_target',
integration_token_source_value='integration_token_source',
integration_token_target_value='integration_token_target'
token_source='token_source',
token_target='token_target'
)
assert attributes_list_mock.call_count == 16
assert attributes_bulk_create_mock.call_count == 1
Expand All @@ -91,10 +86,6 @@ def test_copy_attributes_when_no_source_attr(mocker):
:return: 0
"""
# GIVEN
client_space_mock = mocker.patch.object(Token, 'get_client_space_id', autospec=True)
client_space_mock.return_value = 'cid'
api_authenticate_mock = mocker.patch.object(DataGalaxyApiAuthentication, 'authenticate', autospec=True)
api_authenticate_mock.return_value = 'token'
attributes_list_mock = mocker.patch.object(DataGalaxyApiAttributes, 'list', autospec=True)
attributes_list_mock.return_value = []
attributes_bulk_create_mock = mocker.patch.object(DataGalaxyApiAttributes, 'bulk_create', autospec=True)
Expand All @@ -104,8 +95,8 @@ def test_copy_attributes_when_no_source_attr(mocker):
result = copy_attributes(
url_source='url_source',
url_target='url_target',
integration_token_source_value='integration_token_source',
integration_token_target_value='integration_token_target'
token_source='token_source',
token_target='token_target'
)
# ASSERT / VERIFY
assert attributes_list_mock.call_count == 8
Expand All @@ -120,10 +111,6 @@ def test_copy_attributes_when_many_source_attrs(mocker):
:return: raise Exception
"""
# GIVEN
client_space_mock = mocker.patch.object(Token, 'get_client_space_id', autospec=True)
client_space_mock.return_value = 'cid'
api_authenticate_mock = mocker.patch.object(DataGalaxyApiAuthentication, 'authenticate', autospec=True)
api_authenticate_mock.return_value = 'token'
attributes_list_mock = mocker.patch.object(DataGalaxyApiAttributes, 'list', autospec=True)
attributes_list_mock.side_effect = list_mock_return_many_attr
attributes_bulk_create_mock = mocker.patch.object(DataGalaxyApiAttributes, 'bulk_create', autospec=True)
Expand All @@ -133,8 +120,8 @@ def test_copy_attributes_when_many_source_attrs(mocker):
result = copy_attributes(
url_source='url_source',
url_target='url_target',
integration_token_source_value='integration_token_source',
integration_token_target_value='integration_token_target'
token_source='token_source',
token_target='token_target'
)
# ASSERT / VERIFY
assert attributes_list_mock.call_count == 16
Expand Down Expand Up @@ -168,21 +155,11 @@ def test_copy_attributes_when_many_source_attrs(mocker):

def test_copy_attributes_when_only_one_source_attr_and_empty_target(mocker):
"""
api_authenticate_mock = mocker.patch.object(DataGalaxyApiAuthentication, 'authenticate', autospec=True)
api_authenticate_mock.return_value = 'token'
result = get_access_token('', '')
assert api_authenticate_mock.call_count == 1
assert result == 'token'
Scenario 4. error
:param mocker:
:return: raise Exception
"""
# GIVEN
client_space_mock = mocker.patch.object(Token, 'get_client_space_id', autospec=True)
client_space_mock.return_value = 'cid'
api_authenticate_mock = mocker.patch.object(DataGalaxyApiAuthentication, 'authenticate', autospec=True)
api_authenticate_mock.return_value = 'token'
attributes_list_mock = mocker.patch.object(DataGalaxyApiAttributes, 'list', autospec=True)
attributes_list_mock.side_effect = list_mock_return_one_common_attr
attributes_bulk_create_mock = mocker.patch.object(DataGalaxyApiAttributes, 'bulk_create', autospec=True)
Expand All @@ -192,8 +169,8 @@ def test_copy_attributes_when_only_one_source_attr_and_empty_target(mocker):
result = copy_attributes(
url_source='url_source',
url_target='url_target',
integration_token_source_value='integration_token_source',
integration_token_target_value='integration_token_target'
token_source='token_source',
token_target='token_target'
)

# ASSERT / VERIFY
Expand Down
5 changes: 0 additions & 5 deletions tests/test_copy_dataprocessings.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
from toolbox.api.datagalaxy_api_dataprocessings import DataGalaxyApiDataprocessings
from toolbox.commands.copy_dataprocessings import copy_dataprocessings
from toolbox.api.datagalaxy_api_workspaces import DataGalaxyApiWorkspace
from toolbox.api.datagalaxy_api import DataGalaxyApiAuthentication, Token
import pytest as pytest


Expand All @@ -17,10 +16,6 @@ def mock_list_dataprocessings_on_source_workspace(self, workspace_name):

def test_copy_dataprocessings_when_workspace_source_does_not_exist(mocker):
# GIVEN
client_space_mock = mocker.patch.object(Token, 'get_client_space_id', autospec=True)
client_space_mock.return_value = 'cid'
api_authenticate_mock = mocker.patch.object(DataGalaxyApiAuthentication, 'authenticate', autospec=True)
api_authenticate_mock.return_value = 'token'
workspaces = mocker.patch.object(DataGalaxyApiWorkspace, 'list_workspaces', autospec=True)
workspaces.return_value = ['workspace_source']
workspace_source_mock = mocker.patch.object(DataGalaxyApiWorkspace, 'get_workspace', autospec=True)
Expand Down
5 changes: 0 additions & 5 deletions tests/test_copy_dictionary.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
from toolbox.api.datagalaxy_api_dictionary import DataGalaxyApiDictionary
from toolbox.commands.copy_dictionary import copy_dictionary
from toolbox.api.datagalaxy_api_workspaces import DataGalaxyApiWorkspace
from toolbox.api.datagalaxy_api import DataGalaxyApiAuthentication, Token
import pytest as pytest


Expand All @@ -17,10 +16,6 @@ def mock_list_sources_on_source_workspace(self, workspace_name):

def test_copy_sources_when_workspace_source_does_not_exist(mocker):
# GIVEN
client_space_mock = mocker.patch.object(Token, 'get_client_space_id', autospec=True)
client_space_mock.return_value = 'cid'
api_authenticate_mock = mocker.patch.object(DataGalaxyApiAuthentication, 'authenticate', autospec=True)
api_authenticate_mock.return_value = 'token'
workspaces = mocker.patch.object(DataGalaxyApiWorkspace, 'list_workspaces', autospec=True)
workspaces.return_value = ['workspace_source']
workspace_source_mock = mocker.patch.object(DataGalaxyApiWorkspace, 'get_workspace', autospec=True)
Expand Down
60 changes: 1 addition & 59 deletions tests/test_copy_glossary.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from toolbox.api.datagalaxy_api_glossary import DataGalaxyApiGlossary
from toolbox.api.datagalaxy_api_workspaces import DataGalaxyApiWorkspace
from toolbox.commands.copy_glossary import copy_glossary
from toolbox.api.datagalaxy_api import DataGalaxyApiAuthentication, Token, DataGalaxyBulkResult
from toolbox.api.datagalaxy_api import DataGalaxyBulkResult
import pytest as pytest


Expand All @@ -17,10 +17,6 @@ def mock_list_properties_on_source_workspace(self, workspace_name):

def test_copy_glossary_when_no_property_on_target(mocker):
# GIVEN
client_space_mock = mocker.patch.object(Token, 'get_client_space_id', autospec=True)
client_space_mock.return_value = 'cid'
api_authenticate_mock = mocker.patch.object(DataGalaxyApiAuthentication, 'authenticate', autospec=True)
api_authenticate_mock.return_value = 'token'
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)
Expand Down Expand Up @@ -62,62 +58,8 @@ def test_copy_glossary_when_no_property_on_target(mocker):
assert bulk_upsert_properties_on_target_workspace_mock.call_count == 1


def test_copy_glossary_same_client_space(mocker):
# GIVEN
client_space_mock = mocker.patch.object(Token, 'get_client_space_id', autospec=True)
client_space_mock.return_value = 'cid'
api_authenticate_mock = mocker.patch.object(DataGalaxyApiAuthentication, 'authenticate', autospec=True)
api_authenticate_mock.return_value = 'token'
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',
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',
autospec=True
)
bulk_upsert_properties_on_target_workspace_mock.return_value = DataGalaxyBulkResult(
total=3,
created=3,
updated=0,
unchanged=0,
deleted=0
)

# THEN

copy_glossary(
url_source='url_source',
token_source='token_source',
url_target=None,
token_target=None,
workspace_source_name='workspace_source',
workspace_target_name='workspace_target',
tag_value=None
)

# ASSERT / VERIFY
assert api_authenticate_mock.call_count == 2
api_authenticate_first_call = api_authenticate_mock.call_args_list[0].args[0]
api_authenticate_second_call = api_authenticate_mock.call_args_list[1].args[0]
assert api_authenticate_first_call.datagalaxy_api.url == 'url_source'
assert api_authenticate_first_call.datagalaxy_api.token.value == 'token_source'
assert api_authenticate_second_call.datagalaxy_api.url == 'url_source'
assert api_authenticate_second_call.datagalaxy_api.token.value == 'token_source'


def test_copy_glossary_when_workspace_target_does_not_exist(mocker):
# GIVEN
client_space_mock = mocker.patch.object(Token, 'get_client_space_id', autospec=True)
client_space_mock.return_value = 'cid'
api_authenticate_mock = mocker.patch.object(DataGalaxyApiAuthentication, 'authenticate', autospec=True)
api_authenticate_mock.return_value = 'token'
workspaces = mocker.patch.object(DataGalaxyApiWorkspace, 'list_workspaces', autospec=True)
workspaces.return_value = ['workspace_source']
workspace_source_mock = mocker.patch.object(DataGalaxyApiWorkspace, 'get_workspace', autospec=True)
Expand Down
5 changes: 0 additions & 5 deletions tests/test_copy_links.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
from toolbox.commands.copy_links import copy_links
from toolbox.api.datagalaxy_api_workspaces import DataGalaxyApiWorkspace
from toolbox.api.datagalaxy_api import DataGalaxyApiAuthentication, Token
import pytest as pytest


Expand All @@ -16,10 +15,6 @@ def mock_list_links_on_source_workspace(self, workspace_name):

def test_copy_links_when_workspace_source_does_not_exist(mocker):
# GIVEN
client_space_mock = mocker.patch.object(Token, 'get_client_space_id', autospec=True)
client_space_mock.return_value = 'cid'
api_authenticate_mock = mocker.patch.object(DataGalaxyApiAuthentication, 'authenticate', autospec=True)
api_authenticate_mock.return_value = 'token'
workspaces = mocker.patch.object(DataGalaxyApiWorkspace, 'list_workspaces', autospec=True)
workspaces.return_value = ['workspace_source']
workspace_source_mock = mocker.patch.object(DataGalaxyApiWorkspace, 'get_workspace', autospec=True)
Expand Down
5 changes: 0 additions & 5 deletions tests/test_copy_screens.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
from toolbox.api.datagalaxy_api import DataGalaxyApiAuthentication, Token
from toolbox.api.datagalaxy_api_screens import DataGalaxyApiScreen
from toolbox.commands.copy_screens import copy_screens
import pytest as pytest
Expand All @@ -10,10 +9,6 @@ def test_copy_screens_when_no_screen(mocker):
:param mocker:
:return: raise Exception
"""
client_space_mock = mocker.patch.object(Token, 'get_client_space_id', autospec=True)
client_space_mock.return_value = 'cid'
api_authenticate_mock = mocker.patch.object(DataGalaxyApiAuthentication, 'authenticate', autospec=True)
api_authenticate_mock.return_value = 'token'
source_screens_list_mock = mocker.patch.object(DataGalaxyApiScreen, 'list_screens', autospec=True)
source_screens_list_mock.return_value = []

Expand Down
17 changes: 4 additions & 13 deletions tests/test_copy_technologies.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
from toolbox.api.datagalaxy_api import DataGalaxyApiAuthentication, Token
from toolbox.api.datagalaxy_api_technologies import DataGalaxyApiTechnology
from toolbox.commands.copy_technologies import copy_technologies
import pytest as pytest
Expand All @@ -18,10 +17,6 @@ def test_copy_technologies_when_nothing_on_source(mocker):
:param mocker:
:return: raise Exception
"""
client_space_mock = mocker.patch.object(Token, 'get_client_space_id', autospec=True)
client_space_mock.return_value = 'cid'
api_authenticate_mock = mocker.patch.object(DataGalaxyApiAuthentication, 'authenticate', autospec=True)
api_authenticate_mock.return_value = 'token'
technologies_list_mock = mocker.patch.object(DataGalaxyApiTechnology, 'list_technologies', autospec=True)
technologies_list_mock.return_value = []

Expand All @@ -30,8 +25,8 @@ def test_copy_technologies_when_nothing_on_source(mocker):
copy_technologies(
url_source='url_source',
url_target='url_target',
integration_token_source_value='integration_token_source',
integration_token_target_value='integration_token_target'
token_source='token_source',
token_target='token_target'
)


Expand All @@ -41,19 +36,15 @@ def test_copy_technologies_when_no_custom_technology_on_source(mocker):
:param mocker:
:return: raise Exception
"""
client_space_mock = mocker.patch.object(Token, 'get_client_space_id', autospec=True)
client_space_mock.return_value = 'cid'
api_authenticate_mock = mocker.patch.object(DataGalaxyApiAuthentication, 'authenticate', autospec=True)
api_authenticate_mock.return_value = 'token'
technologies_list_mock = mocker.patch.object(DataGalaxyApiTechnology, 'list_technologies', autospec=True)
technologies_list_mock.return_value = list_mock_technologies_without_custom()

# ASSERT / VERIFY
result = copy_technologies(
url_source='url_source',
url_target='url_target',
integration_token_source_value='integration_token_source',
integration_token_target_value='integration_token_target'
token_source='token_source',
token_target='token_target'
)

assert result == 0
Loading

0 comments on commit 0299ce2

Please sign in to comment.