Browse Source

creating groups makes the owner belong to that group

master
Julio Biason 11 years ago
parent
commit
e19f859bb2
  1. 4
      luncho/blueprints/groups.py
  2. 12
      tests/group_tests.py

4
luncho/blueprints/groups.py

@ -35,11 +35,12 @@ def user_groups(token):
for group in user.groups:
groups[group.id] = {'id': group.id,
'name': group.name,
'admin': group.owner.username == user.username}
'admin': group.owner == user.username}
return jsonify(status='OK',
groups=groups.values())
@groups.route('<token>/', methods=['PUT'])
@ForceJSON(required=['name'])
def create_group(token):
@ -58,6 +59,7 @@ def create_group(token):
new_group = Group(name=json['name'],
owner=user.username)
LOG.debug('Current user groups: {groups}'.format(groups=user.groups))
user.groups.append(new_group)
db.session.add(new_group)

12
tests/group_tests.py

@ -58,5 +58,17 @@ class TestGroups(LunchoTests):
self.assertStatusCode(rv, 412)
self.assertJson(expected, rv.data)
def test_user_in_own_group(self):
"""The user must belong to a group it owns."""
token = self.user.token
self.test_create_group()
rv = self.get('/group/{token}/'.format(token=token))
expected = {'status': 'OK',
'groups': [{'id': 1,
'name': 'Test group',
'admin': True}]}
self.assertStatusCode(rv, 200)
self.assertJson(expected, rv.data)
if __name__ == '__main__':
unittest.main()

Loading…
Cancel
Save