Skip to content

Commit

Permalink
PLGN-362-using black format
Browse files Browse the repository at this point in the history
  • Loading branch information
rbowden-r7 committed Oct 30, 2023
1 parent b12fc94 commit 58403b9
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@
# Custom imports below
from komand_pagerduty.util.util import normalize_user

class GetUserByEmail(insightconnect_plugin_runtime.Action):

class GetUserByEmail(insightconnect_plugin_runtime.Action):
def __init__(self):
super(self.__class__, self).__init__(
name="get_user_by_email",
description=Component.DESCRIPTION,
input=GetUserByEmailInput(),
output=GetUserByEmailOutput()
)
name="get_user_by_email",
description=Component.DESCRIPTION,
input=GetUserByEmailInput(),
output=GetUserByEmailOutput(),
)

def run(self, params={}):
user_email = params.get(Input.USER_EMAIL)
Expand All @@ -24,5 +24,5 @@ def run(self, params={}):
if user.get("email", "") == user_email:
normalized_user = normalize_user(user)
return {Output.USER: normalized_user}

raise PluginException(cause=f"No user found for email {user_email}")
2 changes: 1 addition & 1 deletion plugins/pagerduty/komand_pagerduty/util/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ def get_user_by_email(self, user_email: str) -> dict:
:param str user_email: The email address of the user to get information on
:return dict: The information on the user
"""
params = {"query":user_email}
params = {"query": user_email}
return self.send_request(method="GET", path="/users/", params=params)

def list_users(self) -> dict:
Expand Down
4 changes: 3 additions & 1 deletion plugins/pagerduty/unit_test/test_delete_user_by_id.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@ def setUpClass(cls) -> None:
]
]
)
def test_delete_user_by_id_valid(self, _mock_request: MagicMock, _test_name: str, input_params: dict, expected: dict):
def test_delete_user_by_id_valid(
self, _mock_request: MagicMock, _test_name: str, input_params: dict, expected: dict
):
actual = self.action.run(input_params)
self.assertEqual(actual, expected)

Expand Down
23 changes: 9 additions & 14 deletions plugins/pagerduty/unit_test/test_get_user_by_email.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import sys
import os
sys.path.append(os.path.abspath('../'))

sys.path.append(os.path.abspath("../"))

from unittest import TestCase
from komand_pagerduty.actions.get_user_by_email import GetUserByEmail
Expand All @@ -9,9 +10,9 @@
from util import Util
from insightconnect_plugin_runtime.exceptions import PluginException


@patch("requests.Session.request", side_effect=Util.mock_request)
class TestGetUserByEmail(TestCase):

@classmethod
def setUpClass(cls) -> None:
cls.action = Util.default_connector(GetUserByEmail())
Expand All @@ -25,22 +26,16 @@ def setUpClass(cls) -> None:
]
]
)
def test_get_user_by_email_valid(self, _mock_request: MagicMock, _test_name: str, input_params: dict, expected: dict):
def test_get_user_by_email_valid(
self, _mock_request: MagicMock, _test_name: str, input_params: dict, expected: dict
):
actual = self.action.run(input_params)
self.assertEqual(actual, expected)

@parameterized.expand(
[
[
"no_users_found",
{"user_email": "invalid_email"},
"No user found for email invalid_email"
]
]
[["no_users_found", {"user_email": "invalid_email"}, "No user found for email invalid_email"]]
)
def test_get_user_by_email_invalid(
self, _mock_request: MagicMock, _test_name: str, input_params: dict, cause: str
):
def test_get_user_by_email_invalid(self, _mock_request: MagicMock, _test_name: str, input_params: dict, cause: str):
with self.assertRaises(PluginException) as error:
self.action.run(input_params)
self.assertEqual(error.exception.cause, cause)
self.assertEqual(error.exception.cause, cause)
4 changes: 3 additions & 1 deletion plugins/pagerduty/unit_test/test_send_acknowledge_event.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@ def setUpClass(cls) -> None:
]
]
)
def test_send_acknowledge_event(self, _mock_request: MagicMock, _test_name: str, input_params: dict, expected: dict):
def test_send_acknowledge_event(
self, _mock_request: MagicMock, _test_name: str, input_params: dict, expected: dict
):
actual = self.action.run(input_params)
self.assertEqual(actual, expected)

Expand Down
6 changes: 3 additions & 3 deletions plugins/pagerduty/unit_test/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,9 @@ def json(self):
return MockResponse(204, "")
elif method == "GET":
return MockResponse(200, "get_user_valid.json.resp")

elif url == "https://api.pagerduty.com/users/invalid_id/":
return MockResponse(404)
return MockResponse(404)

elif url == "https://api.pagerduty.com/incidents/valid_id/" and method == "PUT":
incident_status = data.get("incident", {}).get("status")
Expand All @@ -94,7 +94,7 @@ def json(self):
return MockResponse(200, "test_acknowledge_valid.json.resp")

elif url == "https://api.pagerduty.com/incidents/invalid_id/" and method == "PUT":
return MockResponse(404)
return MockResponse(404)

elif url == "https://api.pagerduty.com/incidents/" and method == "POST":
title = payload.get("incident", {}).get("title", "")
Expand Down

0 comments on commit 58403b9

Please sign in to comment.