def test_get_by_id_posts_expected_data(self, mock_session, user_context, mock_user_client): detection_list_user_client = DetectionListUserClient( mock_session, user_context, mock_user_client) detection_list_user_client.get_by_id("942897397520289999") posted_data = json.loads(mock_session.post.call_args[1]["data"]) assert mock_session.post.call_count == 1 assert mock_session.post.call_args[0][0] == "/svc/api/v2/user/getbyid" assert (posted_data["tenantId"] == user_context.get_current_tenant_id() and posted_data["userId"] == "942897397520289999")
def test_add_risk_tag_posts_expected_data(self, mock_session, user_context, mock_user_client): detection_list_user_client = DetectionListUserClient( mock_session, user_context, mock_user_client ) detection_list_user_client.add_risk_tags("942897397520289999", u"Test") posted_data = json.loads(mock_session.post.call_args[1]["data"]) assert mock_session.post.call_count == 1 assert mock_session.post.call_args[0][0] == "/svc/api/v2/user/addriskfactors" assert ( posted_data["tenantId"] == user_context.get_current_tenant_id() and posted_data["userId"] == "942897397520289999" and posted_data["riskFactors"] == ["Test"] )
def test_create_posts_expected_data(self, mock_session, user_context, mock_user_client): detection_list_user_client = DetectionListUserClient( mock_session, user_context, mock_user_client) detection_list_user_client.create("942897397520289999") posted_data = json.loads(mock_session.post.call_args[1]["data"]) assert mock_session.post.call_count == 1 assert mock_session.post.call_args[0][0] == "/svc/api/v2/user/create" assert (posted_data["tenantId"] == user_context.get_current_tenant_id() and posted_data["userName"] == "942897397520289999" and posted_data["riskFactors"] == [] and posted_data["cloudUsernames"] == [] and posted_data["notes"] == "")
def test_remove_cloud_alias_posts_expected_data( self, mock_session, user_context, mock_user_client ): detection_list_user_client = DetectionListUserClient( mock_session, user_context, mock_user_client ) detection_list_user_client.remove_cloud_aliases("942897397520289999", u"Test") posted_data = json.loads(mock_session.post.call_args[1]["data"]) assert mock_session.post.call_count == 1 assert mock_session.post.call_args[0][0] == "/svc/api/v2/user/removecloudusernames" assert ( posted_data["tenantId"] == user_context.get_current_tenant_id() and posted_data["userId"] == "942897397520289999" and posted_data["cloudUsernames"] == ["Test"] )
def get_detection_list_user_client(self, user_client): if not self._detection_list_user_client: if not self._ecm_session: self._ecm_session = self._get_jwt_session( u"employeecasemanagement-API_URL") self._detection_list_user_client = DetectionListUserClient( self._ecm_session, self._user_context, user_client) return self._detection_list_user_client
def mock_detection_list_user_client( self, mock_session, user_context, py42_response, mock_user_client ): user_client = DetectionListUserClient( mock_session, user_context, mock_user_client ) mock_session.post.return_value = py42_response return user_client
def test_create_if_not_exists_posts_expected_data_when_user_does_not_exist( self, mock_get_by_id_fails, user_context, mock_user_client ): # In this test case we can't verify create successful, hence we verified failure in create # because same mock_session instance # 'mock_get_by_id_fails' will be called for get & create and its going to return failure. # We verified create is being called and two times post method is called, also we # verified user_client.get_by_uid is successfully called. detection_list_user_client = DetectionListUserClient( mock_get_by_id_fails, user_context, mock_user_client ) with pytest.raises(Py42BadRequestError): detection_list_user_client.create_if_not_exists("942897397520289999") posted_data = json.loads(mock_get_by_id_fails.post.call_args[1]["data"]) assert mock_get_by_id_fails.post.call_args[0][0] == "/svc/api/v2/user/create" assert ( posted_data["tenantId"] == user_context.get_current_tenant_id() and posted_data["userName"] == "username" ) assert mock_get_by_id_fails.post.call_count == 2 assert mock_user_client._session.get.call_count == 1 assert mock_user_client._session.get.call_args[0][0] == "/api/User/942897397520289999"
def get_detection_list_user_client(self): if not self._detection_list_user_client: user_client = self._user_client self._detection_list_user_client = DetectionListUserClient( self._get_ecm_session(), self._user_context, user_client) return self._detection_list_user_client