Skip to content

Commit

Permalink
Fix (#103)
Browse files Browse the repository at this point in the history
  • Loading branch information
Juliya Smith committed May 4, 2020
1 parent 7ad5967 commit 1301183
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 63 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
The intended audience of this file is for py42 consumers -- as such, changes that don't affect
how a consumer would use the library (e.g. adding unit tests, updating documentation, etc) are not captured here.

## 1.1.1 - 2020-05-04

### Fixed

- Issue causing `detectionlists` functions to fail.

## 1.1.0 - 2020-05-01

### Added
Expand Down
2 changes: 1 addition & 1 deletion src/py42/__version__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
# py42

__version__ = "1.1.0"
__version__ = "1.1.1"
2 changes: 1 addition & 1 deletion src/py42/_internal/initialization.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ def __init__(self, host_address, session_factory, root_session):
self.security_client, self.storage_client_factory, microservice_client_factory
)
self.detection_lists_module = detectionlists.DetectionListsModule(
microservice_client_factory, self.user_client
microservice_client_factory
)

self.alerts_module = alerts.AlertsModule(microservice_client_factory)
Expand Down
47 changes: 19 additions & 28 deletions src/py42/modules/detectionlists.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
class DetectionListsModule(object):
def __init__(self, microservice_client_factory, user_client):
def __init__(self, microservice_client_factory):
self._microservice_client_factory = microservice_client_factory
self._user_client = user_client
self._detection_list_user_client = None

@property
def departing_employee(self):
return self._microservice_client_factory.get_departing_employee_client(self._user_client)
return self._microservice_client_factory.get_departing_employee_client()

@property
def high_risk_employee(self):
return self._microservice_client_factory.get_high_risk_employee_client(self._user_client)
return self._microservice_client_factory.get_high_risk_employee_client()

def create_user(self, username):
"""Create a detection list profile for a user.
Expand All @@ -21,9 +20,8 @@ def create_user(self, username):
Returns:
:class:`py42.response.Py42Response`
"""
self._detection_list_user_client = self._microservice_client_factory.get_detection_list_user_client(
self._user_client
)
factory = self._microservice_client_factory
self._detection_list_user_client = factory.get_detection_list_user_client()
return self._detection_list_user_client.create(username)

def get_user(self, username):
Expand All @@ -35,9 +33,8 @@ def get_user(self, username):
Returns:
:class:`py42.response.Py42Response`
"""
self._detection_list_user_client = self._microservice_client_factory.get_detection_list_user_client(
self._user_client
)
factory = self._microservice_client_factory
self._detection_list_user_client = factory.get_detection_list_user_client()
return self._detection_list_user_client.get(username)

def get_user_by_id(self, user_id):
Expand All @@ -49,9 +46,8 @@ def get_user_by_id(self, user_id):
Returns:
:class:`py42.response.Py42Response`
"""
self._detection_list_user_client = self._microservice_client_factory.get_detection_list_user_client(
self._user_client
)
factory = self._microservice_client_factory
self._detection_list_user_client = factory.get_detection_list_user_client()
return self._detection_list_user_client.get_by_id(user_id)

def update_user_notes(self, user_id, notes):
Expand All @@ -64,9 +60,8 @@ def update_user_notes(self, user_id, notes):
Returns:
:class:`py42.response.Py42Response`
"""
self._detection_list_user_client = self._microservice_client_factory.get_detection_list_user_client(
self._user_client
)
factory = self._microservice_client_factory
self._detection_list_user_client = factory.get_detection_list_user_client()
self._detection_list_user_client.update_notes(user_id, notes)

def add_user_risk_tags(self, user_id, tags):
Expand All @@ -81,9 +76,8 @@ def add_user_risk_tags(self, user_id, tags):
Returns:
:class:`py42.response.Py42Response`
"""
self._detection_list_user_client = self._microservice_client_factory.get_detection_list_user_client(
self._user_client
)
factory = self._microservice_client_factory
self._detection_list_user_client = factory.get_detection_list_user_client()
self._detection_list_user_client.add_risk_tags(user_id, tags)

def remove_user_risk_tags(self, user_id, tags):
Expand All @@ -98,9 +92,8 @@ def remove_user_risk_tags(self, user_id, tags):
Returns:
:class:`py42.response.Py42Response`
"""
self._detection_list_user_client = self._microservice_client_factory.get_detection_list_user_client(
self._user_client
)
factory = self._microservice_client_factory
self._detection_list_user_client = factory.get_detection_list_user_client()
self._detection_list_user_client.remove_risk_tags(user_id, tags)

def add_user_cloud_alias(self, user_id, alias):
Expand All @@ -113,9 +106,8 @@ def add_user_cloud_alias(self, user_id, alias):
Returns:
:class:`py42.response.Py42Response`
"""
self._detection_list_user_client = self._microservice_client_factory.get_detection_list_user_client(
self._user_client
)
factory = self._microservice_client_factory
self._detection_list_user_client = factory.get_detection_list_user_client()
self._detection_list_user_client.add_cloud_alias(user_id, alias)

def remove_user_cloud_alias(self, user_id, alias):
Expand All @@ -128,7 +120,6 @@ def remove_user_cloud_alias(self, user_id, alias):
Returns:
:class:`py42.response.Py42Response`
"""
self._detection_list_user_client = self._microservice_client_factory.get_detection_list_user_client(
self._user_client
)
factory = self._microservice_client_factory
self._detection_list_user_client = factory.get_detection_list_user_client()
self._detection_list_user_client.remove_cloud_alias(user_id, alias)
57 changes: 24 additions & 33 deletions tests/modules/test_detectionlists.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,118 +16,109 @@ 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
self, mock_microservice_client_factory
):
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
)
module = DetectionListsModule(mock_microservice_client_factory)
_ = module.departing_employee
assert mock_microservice_client_factory.get_departing_employee_client.call_count

def test_high_risk_employee_returns_high_risk_employee_client(
self, mock_microservice_client_factory, mock_user_client
self, mock_microservice_client_factory
):
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
)
module = DetectionListsModule(mock_microservice_client_factory)
_ = module.high_risk_employee
assert mock_microservice_client_factory.get_high_risk_employee_client.call_count

def test_create_user_calls_user_client_with_expected_values(
self, mock_microservice_client_factory, mock_detection_list_user_client, mock_user_client
self, mock_microservice_client_factory, mock_detection_list_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 = DetectionListsModule(mock_microservice_client_factory)
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
self, mock_microservice_client_factory, mock_detection_list_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 = DetectionListsModule(mock_microservice_client_factory)
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
self, mock_microservice_client_factory, mock_detection_list_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 = DetectionListsModule(mock_microservice_client_factory)
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
self, mock_microservice_client_factory, mock_detection_list_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 = DetectionListsModule(mock_microservice_client_factory)
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
self, mock_microservice_client_factory, mock_detection_list_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 = DetectionListsModule(mock_microservice_client_factory)
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
self, mock_microservice_client_factory, mock_detection_list_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 = DetectionListsModule(mock_microservice_client_factory)
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
self, mock_microservice_client_factory, mock_detection_list_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 = DetectionListsModule(mock_microservice_client_factory)
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
self, mock_microservice_client_factory, mock_detection_list_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 = DetectionListsModule(mock_microservice_client_factory)
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"
Expand Down

0 comments on commit 1301183

Please sign in to comment.