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
Disable too-many-ancestors in pylint rcfile
  • Loading branch information
khorolets committed Sep 27, 2016
1 parent e17bde5 commit 6d90f5b
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 1 deletion.
4 changes: 3 additions & 1 deletion .pylintrc
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ confidence=
# --enable=similarities". If you want to run only the classes checker, but have
# no Warning level messages displayed, use"--disable=all --enable=classes
# --disable=W"
disable=locally-disabled,too-few-public-methods,no-self-use
disable=locally-disabled,too-few-public-methods,no-self-use,too-many-ancestors


[REPORTS]
Expand Down Expand Up @@ -336,6 +336,8 @@ max-public-methods=20
# Maximum number of boolean expressions in a if statement
max-bool-expr=5

max-ancestors=15


[IMPORTS]

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 6d90f5b

Please sign in to comment.