diff --git a/luncho/blueprints/groups.py b/luncho/blueprints/groups.py index 6065a1c..86d48af 100644 --- a/luncho/blueprints/groups.py +++ b/luncho/blueprints/groups.py @@ -454,7 +454,8 @@ def group_add_places(group_id): not_found = [] rejected = [] - LOG.debug('Users in the group: {users}'.format(users=group.users)) + group_users = [user.username for user in group.users] + LOG.debug('Users in the group: {users}'.format(users=group_users)) for place_id in request.as_json.get('places', []): place = Place.query.get(place_id) if not place: @@ -464,7 +465,7 @@ def group_add_places(group_id): LOG.debug('Place {place_id} owner: {owner}'.format( place_id=place_id, owner=place.owner)) - if place.owner not in group.users: + if place.owner not in group_users: rejected.append(place_id) continue diff --git a/tests/group_tests.py b/tests/group_tests.py index 72d9554..c301e25 100644 --- a/tests/group_tests.py +++ b/tests/group_tests.py @@ -426,7 +426,7 @@ class TestPlacesInGroup(LunchoTests): user = self.user place = Place(name='Place', - owner=self.user) + owner=user) server.db.session.add(place) server.db.session.commit() return place @@ -470,6 +470,7 @@ class TestPlacesInGroup(LunchoTests): verified=True) group = self._group() # group belongs to self.user place = self._place(new_user) # place belongs to new_user + place_id = place.id request = {'places': [place.id]} group_id = group.id @@ -477,6 +478,9 @@ class TestPlacesInGroup(LunchoTests): request, token=self.user.token) self.assertJsonOk(rv) + json = loads(rv.data) + self.assertTrue('rejected' in json) + self.assertTrue(place_id in json['rejected']) if __name__ == '__main__': unittest.main()