def test_create_team_throws_if_no_name(self): """ Newly-created teams must have a name """ with self.assertRaises(BadRequestException, msg="Teams must have a name"): TeamService.create_team(name="", website="-")
def test_get_team(self): """ Create and retrieve a team. """ name = "Glen Eira Band" website = "http://gleneiraband.com.au/" team = TeamService.create_team_with_user_as_owner( self.user, name, website) retrieved_team = TeamService.get(team.id) self.assertEqual(team.id, retrieved_team.id) self.assertEqual(team.name, retrieved_team.name) self.assertEqual(team.website, retrieved_team.website)
def test_create_team_for_new_user(self): """ A new user should be able to create a team and be registered as a member. """ name = "Glen Eira Band" website = "http://gleneiraband.com.au/" # A new team should be created team = TeamService.create_team_with_user_as_owner( self.user, name, website) self.assertEqual(team.name, name) self.assertEqual(team.website, website) # The user must be a member of this team teams_of_user = TeamService.get_teams_of_user_with_id(self.user.id) self.assertEqual(len(teams_of_user), 1) self.assertEqual(teams_of_user[0].id, team.id)
def get_team_by_id(self, request): """ Get a team by their ID. """ user = IdentityService.get_required_session_user(request) team_id = re.match(r"/api/teams/([0-9]*)", request.path)[1] team = TeamService.get(team_id) return JsonResponse({"team": serialize_team(team)}, status=200)
def get_teams_of_user(self, request): """ Get the teams of which the session user is a member. """ user = IdentityService.get_required_session_user(request) teams = TeamService.get_teams_of_user_with_id(user.id) return JsonResponse( {"teams": [serialize_team(team) for team in teams]}, status=200)
def create_team(self, request): """ Create a new team, with the session user as a member. If roles are implemented, this may also include asssigning them as an 'owner'-like role. """ user = IdentityService.get_required_session_user(request) body = json.loads(request.body.decode("utf-8")) name = body["name"] website = body["website"] team = TeamService.create_team_with_user_as_owner(user, name, website) return JsonResponse({"team": serialize_team(team)}, status=201)
def setUp(self): self.user = UserService.create("*****@*****.**", "hunter2", "John", "Doe") self.team = TeamService.create_team_with_user_as_owner( self.user, "John's team", "") self.meeting = MeetingService.create(self.team.id, "A meeting")