You've already forked oncall
mirror of
https://github.com/linkedin/oncall.git
synced 2025-11-29 23:38:17 +02:00
Adding team_services/team_users routes (#370)
These routes essentially dump the corresponding SQL tables. Added tests for the new routes.
This commit is contained in:
@@ -51,6 +51,13 @@ def test_teams_services_mappings(team, service):
|
||||
json={'name': service_name})
|
||||
assert re.status_code == 201
|
||||
|
||||
# test get all team,service pairs
|
||||
re = requests.get(api_v0('team_services'))
|
||||
assert re.status_code == 200
|
||||
team_services = re.json()
|
||||
assert isinstance(team_services, list)
|
||||
assert (team_name, service_name) in set((item['team'], item['service']) for item in team_services)
|
||||
|
||||
# test get service list for a team
|
||||
re = requests.get(api_v0('teams/%s/services' % team_name))
|
||||
assert re.status_code == 200
|
||||
|
||||
@@ -195,6 +195,14 @@ def test_api_v0_team_members(team, user, roster):
|
||||
assert isinstance(users, list)
|
||||
assert set(users) == set([user_name, test_user])
|
||||
|
||||
# test the user shows up in the team_users endpoint to
|
||||
re = requests.get(api_v0('team_users'))
|
||||
assert re.status_code == 200
|
||||
team_users = re.json()
|
||||
assert isinstance(users, list)
|
||||
users = set(item['user'] for item in team_users if item['team'] == team_name)
|
||||
assert set(users) == set([user_name, test_user])
|
||||
|
||||
# test duplicate user creation
|
||||
re = requests.post(api_v0('teams/%s/users') % team_name, json={'name': user_name})
|
||||
assert re.status_code == 422
|
||||
|
||||
@@ -16,6 +16,7 @@ def init(application, config):
|
||||
application.add_route('/api/v0/teams/{team}/admins/{user}', team_admin)
|
||||
|
||||
from . import team_users, team_user
|
||||
application.add_route('/api/v0/team_users', team_user)
|
||||
application.add_route('/api/v0/teams/{team}/users', team_users)
|
||||
application.add_route('/api/v0/teams/{team}/users/{user}', team_user)
|
||||
|
||||
@@ -45,6 +46,7 @@ def init(application, config):
|
||||
application.add_route('/api/v0/services/{service}/oncall/{role}', service_oncall)
|
||||
|
||||
from . import team_services, team_service, service_teams
|
||||
application.add_route('/api/v0/team_services', team_service)
|
||||
application.add_route('/api/v0/teams/{team}/services', team_services)
|
||||
application.add_route('/api/v0/teams/{team}/services/{service}', team_service)
|
||||
application.add_route('/api/v0/services/{service}/teams', service_teams)
|
||||
|
||||
@@ -4,11 +4,49 @@
|
||||
from urllib.parse import unquote
|
||||
|
||||
from falcon import HTTPNotFound
|
||||
from ujson import dumps as json_dumps
|
||||
|
||||
from ...auth import login_required, check_team_auth
|
||||
from ... import db
|
||||
|
||||
|
||||
def on_get(req, resp):
|
||||
"""
|
||||
Get list of team to service mappings
|
||||
|
||||
**Example request**:
|
||||
|
||||
.. sourcecode:: http
|
||||
|
||||
GET /api/v0/team_services HTTP/1.1
|
||||
Host: example.com
|
||||
|
||||
**Example response**:
|
||||
|
||||
.. sourcecode:: http
|
||||
|
||||
HTTP/1.1 200 OK
|
||||
Content-Type: application/json
|
||||
|
||||
[
|
||||
{
|
||||
"team": "team1",
|
||||
"service" : "service-foo"
|
||||
}
|
||||
]
|
||||
"""
|
||||
query = '''SELECT `team`.`name` as team_name, `service`.`name` as service_name FROM `team_service`
|
||||
JOIN `service` ON `team_service`.`service_id`=`service`.`id`
|
||||
JOIN `team` ON `team_service`.`team_id`=`team`.`id`'''
|
||||
connection = db.connect()
|
||||
cursor = connection.cursor()
|
||||
cursor.execute(query)
|
||||
data = [{'team': r[0], 'service': r[1]} for r in cursor]
|
||||
cursor.close()
|
||||
connection.close()
|
||||
resp.body = json_dumps(data)
|
||||
|
||||
|
||||
@login_required
|
||||
def on_delete(req, resp, team, service):
|
||||
"""
|
||||
|
||||
@@ -4,11 +4,49 @@
|
||||
from urllib.parse import unquote
|
||||
|
||||
from falcon import HTTPNotFound
|
||||
from ujson import dumps as json_dumps
|
||||
|
||||
from ...auth import login_required, check_team_auth
|
||||
from ... import db
|
||||
|
||||
|
||||
def on_get(req, resp):
|
||||
"""
|
||||
Get list of team to user mappings
|
||||
|
||||
**Example request**:
|
||||
|
||||
.. sourcecode:: http
|
||||
|
||||
GET /api/v0/team_users HTTP/1.1
|
||||
Host: example.com
|
||||
|
||||
**Example response**:
|
||||
|
||||
.. sourcecode:: http
|
||||
|
||||
HTTP/1.1 200 OK
|
||||
Content-Type: application/json
|
||||
|
||||
[
|
||||
{
|
||||
"team": "team1",
|
||||
"user" : "jdoe"
|
||||
}
|
||||
]
|
||||
"""
|
||||
query = '''SELECT `team`.`name` as team_name, `user`.`name` as user_name FROM `team_user`
|
||||
JOIN `user` ON `team_user`.`user_id`=`user`.`id`
|
||||
JOIN `team` ON `team_user`.`team_id`=`team`.`id`'''
|
||||
connection = db.connect()
|
||||
cursor = connection.cursor()
|
||||
cursor.execute(query)
|
||||
data = [{'team': r[0], 'user': r[1]} for r in cursor]
|
||||
cursor.close()
|
||||
connection.close()
|
||||
resp.body = json_dumps(data)
|
||||
|
||||
|
||||
@login_required
|
||||
def on_delete(req, resp, team, user):
|
||||
"""
|
||||
|
||||
Reference in New Issue
Block a user