diff --git a/luncho/blueprints/groups.py b/luncho/blueprints/groups.py index 4d45da5..cde105c 100644 --- a/luncho/blueprints/groups.py +++ b/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('/', 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) diff --git a/tests/group_tests.py b/tests/group_tests.py index 094b9f3..d253f56 100644 --- a/tests/group_tests.py +++ b/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()