From b83b45c6fb5d1b7fed31f7311530e3e58dd5be2c Mon Sep 17 00:00:00 2001 From: Aleksey Ripinen Date: Tue, 24 Feb 2015 15:07:59 +0300 Subject: [PATCH] Added subscriptions controller Added subscriptions class and manager. Change-Id: I68ba5d653866dc84ee3489309b966379106c952d --- .../tests/v1/test_subscriptions.py | 40 +++++++++++++++++++ storyboardclient/v1/client.py | 2 + storyboardclient/v1/subscriptions.py | 27 +++++++++++++ 3 files changed, 69 insertions(+) create mode 100644 storyboardclient/tests/v1/test_subscriptions.py create mode 100644 storyboardclient/v1/subscriptions.py diff --git a/storyboardclient/tests/v1/test_subscriptions.py b/storyboardclient/tests/v1/test_subscriptions.py new file mode 100644 index 0000000..ade0208 --- /dev/null +++ b/storyboardclient/tests/v1/test_subscriptions.py @@ -0,0 +1,40 @@ +# Copyright (c) 2015 Mirantis Inc. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or +# implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import mock + +from storyboardclient.tests import base as test_base +from storyboardclient.v1 import subscriptions + + +class SubscriptionsTestCase(test_base.TestCase): + + @mock.patch("storyboardclient.v1.subscriptions.SubscriptionsManager._list") + def test_subscriptions_list(self, mock_private_list): + subscriptions.SubscriptionsManager(mock.MagicMock()).list() + + mock_private_list.assert_called_once_with( + "/subscriptions", None) + + @mock.patch("storyboardclient.v1.subscriptions.SubscriptionsManager._post") + def test_subscriptions_create(self, mock_private_post): + subscriptions.SubscriptionsManager(mock.MagicMock()).create( + target_type="story", + target_id="test_story_id") + + mock_private_post.assert_called_once_with( + "/subscriptions", + {"target_type": "story", + "target_id": "test_story_id"}) diff --git a/storyboardclient/v1/client.py b/storyboardclient/v1/client.py index 31985e4..a6a1691 100644 --- a/storyboardclient/v1/client.py +++ b/storyboardclient/v1/client.py @@ -17,6 +17,7 @@ from storyboardclient import base from storyboardclient.v1 import project_groups from storyboardclient.v1 import projects from storyboardclient.v1 import stories +from storyboardclient.v1 import subscriptions from storyboardclient.v1 import tasks from storyboardclient.v1 import teams from storyboardclient.v1 import users @@ -52,3 +53,4 @@ class Client(base.BaseClient): self.project_groups = project_groups.ProjectGroupsManager(self) self.stories = stories.StoriesManager(self) self.users = users.UsersManager(self) + self.subscriptions = subscriptions.SubscriptionsManager(self) diff --git a/storyboardclient/v1/subscriptions.py b/storyboardclient/v1/subscriptions.py new file mode 100644 index 0000000..6b186d9 --- /dev/null +++ b/storyboardclient/v1/subscriptions.py @@ -0,0 +1,27 @@ +# Copyright (c) 2015 Mirantis Inc. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or +# implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +from storyboardclient import base + + +class Subscription(base.BaseObject): + user_id = None + target_type = None + target_id = None + + +class SubscriptionsManager(base.BaseManager): + url_key = "subscriptions" + resource_class = Subscription