# Copyright (c) LinkedIn Corporation. All rights reserved. Licensed under the BSD-2 Clause license. # See LICENSE in the project root for license information. #!/usr/bin/env python # -*- coding:utf-8 -*- import requests import ujson from testutils import prefix, api_v0 @prefix('test_v0_rosters') def test_api_v0_rosters(team): team_name = team.create() roster_name = 'test_v0_rosters_roster_0' roster_name2 = 'test_v0_rosters_roster_1' def clean_up(): requests.delete(api_v0('teams/%s/rosters/%s' % (team_name, roster_name))) requests.delete(api_v0('teams/%s/rosters/%s' % (team_name, roster_name2))) clean_up() # test create rosters re = requests.post(api_v0('teams/%s/rosters' % team_name), json={'name': roster_name}) assert re.status_code == 201 re = requests.post(api_v0('teams/%s/rosters' % team_name), json={'name': roster_name2}) assert re.status_code == 201 # test fetch rosters re = requests.get(api_v0('teams/%s/rosters' % team_name)) assert re.status_code == 200 rosters = re.json() assert roster_name in rosters assert roster_name2 in rosters re = requests.get(api_v0('teams/%s/rosters?name__contains=%s&name__startswith=%s&name__endswith=%s' % (team_name, roster_name, roster_name, roster_name))) assert re.status_code == 200 rosters = re.json() assert roster_name in rosters roster_id = rosters[roster_name]['id'] re = requests.get(api_v0('teams/%s/rosters?id=%s' % (team_name, roster_id))) assert re.status_code == 200 rosters = re.json() assert roster_name in rosters # test fetch single roster re = requests.get(api_v0('teams/%s/rosters/%s' % (team_name, roster_name))) assert re.status_code == 200 roster = re.json() assert set(['users', 'schedules']) == set(roster.keys()) # test rename roster to an existing roster re = requests.put(api_v0('teams/%s/rosters/%s' % (team_name, roster_name)), json={'name': roster_name2}) assert re.status_code == 422 assert re.json() == { 'title': 'IntegrityError', 'description': "roster '%s' already existed for team '%s'" % (roster_name2, team_name), } # test delete rosters re = requests.delete(api_v0('teams/%s/rosters/%s' % (team_name, roster_name))) assert re.status_code == 200 re = requests.get(api_v0('teams/%s/rosters' % team_name)) assert re.status_code == 200 rosters = re.json() assert roster_name not in rosters assert roster_name2 in rosters re = requests.delete(api_v0('teams/%s/rosters/%s' % (team_name, roster_name2))) assert re.status_code == 200 re = requests.get(api_v0('teams/%s/rosters' % team_name)) assert re.status_code == 200 rosters = re.json() assert len(rosters.keys()) == 0 clean_up() @prefix('test_v0_create_invalid_roster') def test_api_v0_create_invalid_roster(team, roster): team_name = team.create() roster_name = "v0_create_