Merge pull request #2855 from coreos-inc/fix-robots-api

Fix missing to_dict and import in robots model
This commit is contained in:
josephschorr 2017-08-09 20:43:09 -04:00 committed by GitHub
commit 49df658e20
3 changed files with 15 additions and 5 deletions

View file

@ -25,6 +25,11 @@ class Team(namedtuple('Team', ['name', 'avatar'])):
:type name: string :type name: string
:type avatar: {string -> string} :type avatar: {string -> string}
""" """
def to_dict(self):
return {
'name': self.name,
'avatar': self.avatar,
}
class RobotWithPermissions( class RobotWithPermissions(

View file

@ -1,7 +1,8 @@
from app import avatar from app import avatar
from data import model from data import model
from data.database import User, FederatedLogin, Team, Repository from data.database import User, FederatedLogin, Team as TeamTable, Repository
from endpoints.api.robot_models_interface import RobotInterface, Robot, RobotWithPermissions, Permission from endpoints.api.robot_models_interface import (RobotInterface, Robot, RobotWithPermissions, Team,
Permission)
class RobotPreOCIModel(RobotInterface): class RobotPreOCIModel(RobotInterface):
@ -31,7 +32,7 @@ class RobotPreOCIModel(RobotInterface):
}) })
robots[robot_name] = Robot(robot_dict['name'], robot_dict['token']) robots[robot_name] = Robot(robot_dict['name'], robot_dict['token'])
if include_permissions: if include_permissions:
team_name = robot_tuple.get(Team.name) team_name = robot_tuple.get(TeamTable.name)
repository_name = robot_tuple.get(Repository.name) repository_name = robot_tuple.get(Repository.name)
if team_name is not None: if team_name is not None:

View file

@ -3234,10 +3234,11 @@ class TestUserRobots(ApiTestCase):
class TestOrgRobots(ApiTestCase): class TestOrgRobots(ApiTestCase):
def getRobotNames(self): def getRobotNames(self, include_permissions=False):
params = dict(orgname=ORGANIZATION, permissions=include_permissions)
return [ return [
r['name'] r['name']
for r in self.getJsonResponse(OrgRobotList, params=dict(orgname=ORGANIZATION))['robots'] for r in self.getJsonResponse(OrgRobotList, params=params)['robots']
] ]
def test_create_robot_with_underscores(self): def test_create_robot_with_underscores(self):
@ -3256,6 +3257,9 @@ class TestOrgRobots(ApiTestCase):
self.getJsonResponse(OrgRobot, params=dict(orgname=ORGANIZATION, robot_shortname='mr_bender'), self.getJsonResponse(OrgRobot, params=dict(orgname=ORGANIZATION, robot_shortname='mr_bender'),
expected_code=200) expected_code=200)
# Make sure the robot shows up in the org robots list.
self.assertTrue(membername in self.getRobotNames(include_permissions=True))
def test_delete_robot_after_use(self): def test_delete_robot_after_use(self):
self.login(ADMIN_ACCESS_USER) self.login(ADMIN_ACCESS_USER)