Skip to content

Commit

Permalink
Bugfix/detection list module (#87)
Browse files Browse the repository at this point in the history
  • Loading branch information
alanag13 committed Apr 21, 2020
1 parent 97a49f6 commit 8e2fb9e
Show file tree
Hide file tree
Showing 2 changed files with 140 additions and 8 deletions.
14 changes: 6 additions & 8 deletions src/py42/modules/detectionlists.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,34 +101,32 @@ def remove_user_risk_tags(self, user_id, tags):
)
self._detection_list_user_client.remove_risk_tags(user_id, tags)

def add_user_cloud_aliases(self, user_id, aliases):
def add_user_cloud_alias(self, user_id, alias):
"""Add one or more cloud alias.
Args:
user_id (str or int): The user_id whose alias(es) need to be updated.
aliases (str or list of str ): A single alias or multiple aliases in a list to be added.
e.g u"x" or ["email@id", "y"], for python version 2.X, pass u"str" instead of "str"
alias (str): An alias to be added.
Returns:
:class:`py42.response.Py42Response`
"""
self._detection_list_user_client = self._microservice_client_factory.get_detection_list_user_client(
self._user_client
)
self._detection_list_user_client.add_cloud_aliases(user_id, aliases)
self._detection_list_user_client.add_cloud_alias(user_id, alias)

def remove_user_cloud_aliases(self, user_id, aliases):
def remove_user_cloud_alias(self, user_id, alias):
"""Remove one or more cloud alias.
Args:
user_id (str or int): The user_id whose alias(es) need to be removed.
aliases (str or list of str ): A single alias or multiple aliases in a list to be removed.
e.g u"x" or ["email@id", "y"], for python version 2.X, pass u"str" instead of "str"
alias (str): An alias to be removed.
Returns:
:class:`py42.response.Py42Response`
"""
self._detection_list_user_client = self._microservice_client_factory.get_detection_list_user_client(
self._user_client
)
self._detection_list_user_client.remove_cloud_aliases(user_id, aliases)
self._detection_list_user_client.remove_cloud_alias(user_id, alias)
134 changes: 134 additions & 0 deletions tests/modules/test_detectionlists.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
import pytest

from py42._internal.client_factories import MicroserviceClientFactory
from py42._internal.clients.detection_list_user import DetectionListUserClient
from py42.clients.users import UserClient
from py42.modules.detectionlists import DetectionListsModule


@pytest.fixture
def mock_microservice_client_factory(mocker):
return mocker.MagicMock(spec=MicroserviceClientFactory)


@pytest.fixture
def mock_detection_list_user_client(mocker):
return mocker.MagicMock(spec=DetectionListUserClient)


@pytest.fixture
def mock_user_client(mocker):
return mocker.MagicMock(spec=UserClient)


TEST_USER_ID = "12345"


class TestDetectionListModule(object):
def test_departing_employee_call_get_departing_employee_client_with_expected_values(
self, mock_microservice_client_factory, mock_user_client
):
module = DetectionListsModule(mock_microservice_client_factory, mock_user_client)
test = module.departing_employee
mock_microservice_client_factory.get_departing_employee_client.assert_called_once_with(
mock_user_client
)

def test_high_risk_employee_returns_high_risk_employee_client(
self, mock_microservice_client_factory, mock_user_client
):
module = DetectionListsModule(mock_microservice_client_factory, mock_user_client)
test = module.high_risk_employee
mock_microservice_client_factory.get_high_risk_employee_client.assert_called_once_with(
mock_user_client
)

def test_create_user_calls_user_client_with_expected_values(
self, mock_microservice_client_factory, mock_detection_list_user_client, mock_user_client
):
mock_microservice_client_factory.get_detection_list_user_client.return_value = (
mock_detection_list_user_client
)
module = DetectionListsModule(mock_microservice_client_factory, mock_user_client)
module.create_user("testusername")
mock_detection_list_user_client.create.assert_called_once_with("testusername")

def test_get_user_calls_user_client_with_expected_values(
self, mock_microservice_client_factory, mock_detection_list_user_client, mock_user_client
):
mock_microservice_client_factory.get_detection_list_user_client.return_value = (
mock_detection_list_user_client
)
module = DetectionListsModule(mock_microservice_client_factory, mock_user_client)
module.get_user("testusername")
mock_detection_list_user_client.get.assert_called_once_with("testusername")

def test_get_user_by_id_calls_user_client_with_expected_values(
self, mock_microservice_client_factory, mock_detection_list_user_client, mock_user_client
):
mock_microservice_client_factory.get_detection_list_user_client.return_value = (
mock_detection_list_user_client
)
module = DetectionListsModule(mock_microservice_client_factory, mock_user_client)
module.get_user_by_id(TEST_USER_ID)
mock_detection_list_user_client.get_by_id.assert_called_once_with(TEST_USER_ID)

def test_update_user_notes_calls_user_client_with_expected_values(
self, mock_microservice_client_factory, mock_detection_list_user_client, mock_user_client
):
mock_microservice_client_factory.get_detection_list_user_client.return_value = (
mock_detection_list_user_client
)
module = DetectionListsModule(mock_microservice_client_factory, mock_user_client)
module.update_user_notes(TEST_USER_ID, "newnotes")
mock_detection_list_user_client.update_notes.assert_called_once_with(
TEST_USER_ID, "newnotes"
)

def test_add_user_risk_tag_calls_user_client_with_expected_values(
self, mock_microservice_client_factory, mock_detection_list_user_client, mock_user_client
):
mock_microservice_client_factory.get_detection_list_user_client.return_value = (
mock_detection_list_user_client
)
module = DetectionListsModule(mock_microservice_client_factory, mock_user_client)
module.add_user_risk_tags(TEST_USER_ID, "newtag")
mock_detection_list_user_client.add_risk_tags.assert_called_once_with(
TEST_USER_ID, "newtag"
)

def test_remove_user_risk_tag_calls_user_client_with_expected_values(
self, mock_microservice_client_factory, mock_detection_list_user_client, mock_user_client
):
mock_microservice_client_factory.get_detection_list_user_client.return_value = (
mock_detection_list_user_client
)
module = DetectionListsModule(mock_microservice_client_factory, mock_user_client)
module.remove_user_risk_tags(TEST_USER_ID, "oldtag")
mock_detection_list_user_client.remove_risk_tags.assert_called_once_with(
TEST_USER_ID, "oldtag"
)

def test_add_user_cloud_alias_calls_user_client_with_expected_values(
self, mock_microservice_client_factory, mock_detection_list_user_client, mock_user_client
):
mock_microservice_client_factory.get_detection_list_user_client.return_value = (
mock_detection_list_user_client
)
module = DetectionListsModule(mock_microservice_client_factory, mock_user_client)
module.add_user_cloud_alias(TEST_USER_ID, "newalias")
mock_detection_list_user_client.add_cloud_alias.assert_called_once_with(
TEST_USER_ID, "newalias"
)

def test_remove_user_cloud_alias_calls_user_client_with_expected_values(
self, mock_microservice_client_factory, mock_detection_list_user_client, mock_user_client
):
mock_microservice_client_factory.get_detection_list_user_client.return_value = (
mock_detection_list_user_client
)
module = DetectionListsModule(mock_microservice_client_factory, mock_user_client)
module.remove_user_cloud_alias(TEST_USER_ID, "oldalias")
mock_detection_list_user_client.remove_cloud_alias.assert_called_once_with(
TEST_USER_ID, "oldalias"
)

0 comments on commit 8e2fb9e

Please sign in to comment.