Teams endpoint

Added teams endpoint with support for nested Users resource.

Change-Id: I5d93e91c268d5b35d10641bfce13e425f153d40d
This commit is contained in:
Nikita Konovalov 2015-01-13 15:34:38 +03:00
parent a5c1b220ac
commit c6c73ebeb9
3 changed files with 123 additions and 0 deletions

View File

@ -0,0 +1,71 @@
# Copyright (c) 2014 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 teams
from storyboardclient.v1 import users
class TeamsTestCase(test_base.TestCase):
@mock.patch("storyboardclient.v1.teams.TeamsManager._list")
def test_teams_list(self, mock_private_list):
mock_private_list.return_value = [
teams.Team(mock.MagicMock(), info={"name": "test_team"}),
teams.Team(mock.MagicMock(), info={"name": "test_team_2"})]
teams_list = teams.TeamsManager(mock.MagicMock()).list()
self.assertEqual(2, len(teams_list))
@mock.patch("storyboardclient.v1.teams.TeamsManager._post")
def test_teams_create(self, mock_private_post):
teams.TeamsManager(mock.MagicMock()).create(name="test_team")
mock_private_post.assert_called_once_with("/teams",
{"name": "test_team"})
@mock.patch("storyboardclient.v1.teams.TeamsManager._put")
def test_teams_update(self, mock_private_put):
teams.TeamsManager(mock.MagicMock()).update(id="team_id",
name="test_team_updated")
mock_private_put.assert_called_once_with(
"/teams/team_id",
{"name": "test_team_updated"})
@mock.patch("storyboardclient.v1.teams.UsersNestedManager._put")
def test_teams_add_user(self, mock_private_put):
test_team = teams.Team(mock.MagicMock(),
info={"id": "test_team_id"})
test_user = users.User(mock.MagicMock(), info={"id": "test_user_id"})
test_team.users.add(test_user)
mock_private_put.assert_called_once_with(
"/teams/test_team_id/users/test_user_id")
@mock.patch("storyboardclient.v1.teams.UsersNestedManager._delete")
def test_teams_delete_user(self, mock_private_delete):
test_team = teams.Team(mock.MagicMock(),
info={"id": "test_team_id"})
test_user = users.User(mock.MagicMock(), info={"id": "test_user_id"})
test_team.users.remove(test_user)
mock_private_delete.assert_called_once_with(
"/teams/test_team_id/users/test_user_id")

View File

@ -14,6 +14,7 @@
# limitations under the License.
from storyboardclient import base
from storyboardclient.v1 import teams
from storyboardclient.v1 import users
@ -41,4 +42,5 @@ class Client(base.BaseClient):
super(Client, self).__init__(api_url=api_url,
access_token=access_token)
self.teams = teams.TeamsManager(self)
self.users = users.UsersManager(self)

View File

@ -0,0 +1,50 @@
# Copyright (c) 2014 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
from storyboardclient.v1 import users
class UsersNestedManager(base.BaseNestedManager):
parent_url_key = "teams"
url_key = "users"
resource_class = users.User
def add(self, user):
if isinstance(user, users.User):
user_id = user.id
else:
user_id = user
self.put(id=user_id)
def remove(self, user):
if isinstance(user, users.User):
user_id = user.id
else:
user_id = user
self.delete(id=user_id)
class Team(base.BaseObject):
name = None
users = UsersNestedManager
class TeamsManager(base.BaseManager):
url_key = "teams"
resource_class = Team