Added tags controller

Added Tag object, manager and nested
manager.

Change-Id: I8b67ebf5919adfb641381be6facc98d0a428fcdd
This commit is contained in:
Aleksey Ripinen 2015-02-20 19:26:17 +03:00
parent 4772d5b1db
commit c93ed03539
5 changed files with 89 additions and 0 deletions

View File

@ -117,3 +117,13 @@ class StoriesTestCase(test_base.TestCase):
mock_private_put.assert_called_once_with(
"/stories/test_story_id/comments/comment_id",
{"content": "updated_test_comment"})
@mock.patch("storyboardclient.v1.tags.TagsNestedManager._put")
def test_stories_update_tags(self, mock_private_put):
test_story = stories.Story(mock.MagicMock(),
info={"id": "test_story_id"})
test_story.tags_manager.update(["first_test_tag", "second_test_tag"])
mock_private_put.assert_called_once_with(
"/stories/test_story_id/tags",
["first_test_tag", "second_test_tag"])

View File

@ -0,0 +1,37 @@
# 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 tags
class TagsTestCase(test_base.TestCase):
@mock.patch("storyboardclient.v1.tags.TagsManager._list")
def test_tags_list(self, mock_private_list):
tags.TagsManager(mock.MagicMock()).list()
mock_private_list.assert_called_once_with(
"/tags", None)
@mock.patch("storyboardclient.v1.tags.TagsManager._post")
def test_tags_create(self, mock_private_post):
tags.TagsManager(mock.MagicMock()).create(
tag_name="test_tag")
mock_private_post.assert_called_once_with(
"/tags",
{"tag_name": "test_tag"})

View File

@ -18,6 +18,7 @@ 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 tags
from storyboardclient.v1 import tasks
from storyboardclient.v1 import teams
from storyboardclient.v1 import users
@ -54,3 +55,4 @@ class Client(base.BaseClient):
self.stories = stories.StoriesManager(self)
self.users = users.UsersManager(self)
self.subscriptions = subscriptions.SubscriptionsManager(self)
self.tags = tags.TagsManager(self)

View File

@ -14,6 +14,7 @@
# limitations under the License.
from storyboardclient import base
from storyboardclient.v1 import tags as tags_api
from storyboardclient.v1 import tasks
from storyboardclient.v1 import timeline
@ -24,10 +25,12 @@ class Story(base.BaseObject):
is_bug = None
creator_id = None
status = None
tags = None
tasks = tasks.TasksNestedManager
comments = timeline.CommentsNestedManager
events = timeline.TimeLineEventsNestedManager
tags_manager = tags_api.TagsNestedManager
class StoriesManager(base.BaseManager):

View File

@ -0,0 +1,37 @@
# 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 Tag(base.BaseObject):
name = None
class TagsManager(base.BaseManager):
url_key = "tags"
resource_class = Tag
class TagsNestedManager(base.BaseNestedManager):
parent_url_key = "stories"
url_key = "tags"
resource_class = Tag
def update(self, tags):
return self._put(self.build_url(), tags)
def delete(self, tags):
return self.client.delete(self.build_url(), json=tags)