Skip to content

Commit

Permalink
Closes frol#30: Regular user now becomes a leader when he creates team
Browse files Browse the repository at this point in the history
  • Loading branch information
khorolets committed Sep 27, 2016
1 parent e17bde5 commit 4c75687
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 1 deletion.
2 changes: 1 addition & 1 deletion app/modules/teams/parameters.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from .models import Team


class CreateTeamParameters(PostFormParameters, schemas.BaseTeamSchema):
class CreateTeamParameters(PostFormParameters, schemas.BaseTeamSchema): # pylint: disable=too-many-ancestors

class Meta(schemas.BaseTeamSchema.Meta):
# This is not supported yet: https://github.com/marshmallow-code/marshmallow/issues/344
Expand Down
3 changes: 3 additions & 0 deletions app/modules/teams/resources.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

import logging

from flask_login import current_user
from flask_restplus import Resource
from flask_restplus_patched._http import HTTPStatus

Expand Down Expand Up @@ -57,6 +58,8 @@ def post(self, args):
):
team = Team(**args)
db.session.add(team)
team_member = TeamMember(team=team, user=current_user, is_leader=True)
db.session.add(team_member)
return team


Expand Down
23 changes: 23 additions & 0 deletions tests/modules/teams/resources/test_modifying_teams.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,29 @@ def test_new_team_creation(flask_app_client, db, regular_user):
db.session.delete(team)
db.session.commit()

def test_new_team_first_member_is_creator(flask_app_client, db, regular_user):
# pylint: disable=invalid-name
team_title = "Test Team Title"
with flask_app_client.login(
regular_user,
auth_scopes=('teams:write', 'teams:read')
):
response = flask_app_client.post('/api/v1/teams/', data={'title': team_title})

assert response.status_code == 200
assert response.content_type == 'application/json'
assert set(response.json.keys()) >= {'id', 'title'}
assert response.json['title'] == team_title
assert len(response.json['members']) == 1
assert response.json['members'][0]['user']['id'] == regular_user.id
assert response.json['members'][0]['is_leader'] == True

# Cleanup
team = models.Team.query.get(response.json['id'])
assert team.title == team_title
db.session.delete(team)
db.session.commit()


def test_new_team_creation_with_invalid_data_must_fail(flask_app_client, regular_user):
# pylint: disable=invalid-name
Expand Down

0 comments on commit 4c75687

Please sign in to comment.