Skip to content

Commit

Permalink
Add Dashboard Actions #72: Update
Browse files Browse the repository at this point in the history
Had to update some tests/class references/method calls to match the
final interface over in the `jira` lib.

* `Gadget` renamed to `DashboardGadget`.
* `gadgets` method renamed to `all_dashboard_gadgets`.
* Update
`%s/update_dashboard_automatic_refresh_seconds/update_dashboard/automatic_refresh_minutes`
  • Loading branch information
jpavlav committed Mar 26, 2024
1 parent 8874181 commit 22ad346
Show file tree
Hide file tree
Showing 8 changed files with 19 additions and 17 deletions.
2 changes: 1 addition & 1 deletion actions/get_available_gadgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@

class GetAvailableGadgetsAction(BaseJiraAction):
def run(self):
gadgets = self._client.gadgets()
gadgets = self._client.all_dashboard_gadgets()
return [gadget.raw for gadget in gadgets]
2 changes: 1 addition & 1 deletion actions/update_dashboard_automatic_refresh.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@

class UpdateJiraDashboardAutomaticRefreshAction(BaseJiraAction):
def run(self, id, minutes):
response = self._client.update_dashboard_automatic_refresh_seconds(id, minutes)
response = self._client.update_dashboard_automatic_refresh_minutes(id, minutes)
result = {"status_code": response.status_code, "response_text": response.text}
return bool(response.status_code == 204), result
4 changes: 2 additions & 2 deletions tests/test_action_add_gadget.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import mock
from add_gadget import AddGadgetAction
from jira.resources import Gadget
from jira.resources import DashboardGadget

from tests.lib.actions import JIRABaseActionTestCase

Expand All @@ -15,7 +15,7 @@ def test_add_gadget(self, mocked_add_gadget, mocked_request):
dashboard_id = 1

action = self.get_action_instance(self.full_auth_passwd_config)
mocked_add_gadget.return_value = Gadget(
mocked_add_gadget.return_value = DashboardGadget(
{}, {}, self.load_json_fixture("gadget.json")
)
result = action.run(dashboard_id)
Expand Down
6 changes: 3 additions & 3 deletions tests/test_action_get_available_gadgets.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import mock
from get_available_gadgets import GetAvailableGadgetsAction
from jira.resources import Gadget
from jira.resources import DashboardGadget

from tests.lib.actions import JIRABaseActionTestCase

Expand All @@ -10,10 +10,10 @@ class GetAvailableGadgetsTests(JIRABaseActionTestCase):
action_cls = GetAvailableGadgetsAction

@mock.patch("requests.Session.request")
@mock.patch("lib.base.JIRA.gadgets")
@mock.patch("lib.base.JIRA.all_dashboard_gadgets")
def test_get_available_gadgets(self, mocked_gadgets, mocked_request):
action = self.get_action_instance(self.full_auth_passwd_config)
gadget = Gadget({}, {}, self.load_json_fixture("gadget.json"))
gadget = DashboardGadget({}, {}, self.load_json_fixture("gadget.json"))
mocked_gadgets.return_value = [gadget]
result = action.run()
self.assertIsInstance(result, list)
Expand Down
4 changes: 2 additions & 2 deletions tests/test_action_get_dashboard_gadgets.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import mock
from get_dashboard_gadgets import GetDashboardGadgetsAction
from jira.resources import Dashboard, Gadget
from jira.resources import Dashboard, DashboardGadget

from tests.lib.actions import JIRABaseActionTestCase

Expand All @@ -13,7 +13,7 @@ class GetDashboardGadgetsTest(JIRABaseActionTestCase):
@mock.patch("requests.Session.request")
def test_get_dashboard_gadgets(self, mocked_request, mocked_dashboard):
dashboard = Dashboard({}, {}, raw=self.load_json_fixture("dashboard.json"))
gadget = Gadget({}, {}, raw=self.load_json_fixture("gadget.json"))
gadget = DashboardGadget({}, {}, raw=self.load_json_fixture("gadget.json"))

dashboard.gadgets.append(gadget)
mocked_dashboard.return_value = dashboard.gadgets
Expand Down
6 changes: 3 additions & 3 deletions tests/test_action_remove_gadget.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import mock
from jira.resources import Dashboard, Gadget
from jira.resources import Dashboard, DashboardGadget
from remove_gadget import RemoveGadgetAction

from tests.lib.actions import JIRABaseActionTestCase
Expand All @@ -11,14 +11,14 @@ class RemoveGadgetTests(JIRABaseActionTestCase):

@mock.patch("lib.base.JIRA.dashboard")
@mock.patch("requests.Session.request")
@mock.patch("jira.resources.Gadget.delete")
@mock.patch("jira.resources.DashboardGadget.delete")
def test_remove_gadget(
self, mocked_delete_gadget, mocked_request, mocked_dashboard
):
status_code = 204
text = ""

gadget = Gadget({}, {}, raw=self.load_json_fixture("gadget.json"))
gadget = DashboardGadget({}, {}, raw=self.load_json_fixture("gadget.json"))
dashboard = Dashboard({}, {}, raw=self.load_json_fixture("dashboard.json"))
dashboard.gadgets.append(gadget)
mocked_dashboard.return_value = dashboard
Expand Down
2 changes: 1 addition & 1 deletion tests/test_action_update_dashboard_automatic_refresh.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class UpdateJiraDashboardAutomaticRefreshActionDashboardTests(JIRABaseActionTest
action_cls = UpdateJiraDashboardAutomaticRefreshAction

@mock.patch("requests.Session.request")
@mock.patch("lib.base.JIRA.update_dashboard_automatic_refresh_seconds")
@mock.patch("lib.base.JIRA.update_dashboard_automatic_refresh_minutes")
def test_update_dashboard_automatic_refresh(
self, mock_automatic_refresh, mock_request
):
Expand Down
10 changes: 6 additions & 4 deletions tests/test_action_update_gadget.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import mock
from jira.resources import Dashboard, Gadget
from jira.resources import Dashboard, DashboardGadget
from update_gadget import UpdateGadgetAction

from tests.lib.actions import JIRABaseActionTestCase
Expand All @@ -9,7 +9,7 @@ class UpdateGadgetTests(JIRABaseActionTestCase):
__test__ = True
action_cls = UpdateGadgetAction

@mock.patch("jira.resources.Gadget.update")
@mock.patch("jira.resources.DashboardGadget.update")
@mock.patch("requests.Session.request")
@mock.patch("lib.base.JIRA.dashboard")
def test_update_gadget(
Expand All @@ -22,14 +22,16 @@ def test_update_gadget(
original_gadget_data = self.load_json_fixture("gadget.json")

action = self.get_action_instance(self.full_auth_passwd_config)
original_gadget = Gadget({}, {}, raw=original_gadget_data)
original_gadget = DashboardGadget({}, {}, raw=original_gadget_data)
dashboard = Dashboard({}, {}, raw=self.load_json_fixture("dashboard.json"))
dashboard.gadgets.append(original_gadget)

original_gadget_data.update(update_data)

mocked_dashboard.return_value = dashboard
mocked_update_gadget.return_value = Gadget({}, {}, raw=original_gadget_data)
mocked_update_gadget.return_value = DashboardGadget(
{}, {}, raw=original_gadget_data
)

result = action.run(dashboard.id, str(original_gadget.id), **update_data)
self.assertEqual(result["color"], updated_color)
Expand Down

0 comments on commit 22ad346

Please sign in to comment.