Browse Source

unplugging places from groups works

master
Julio Biason 11 years ago
parent
commit
dd35d910b5
  1. 30
      luncho/blueprints/groups.py
  2. 23
      tests/group_tests.py

30
luncho/blueprints/groups.py

@ -144,7 +144,7 @@ def create_group():
id=new_group.id) id=new_group.id)
@groups.route('<group_id>/', methods=['PUT']) @groups.route('<int:group_id>/', methods=['PUT'])
@ForceJSON() @ForceJSON()
@auth @auth
def update_group(group_id): def update_group(group_id):
@ -204,7 +204,7 @@ def update_group(group_id):
return jsonify(status='OK') return jsonify(status='OK')
@groups.route('<group_id>/', methods=['DELETE']) @groups.route('<int:group_id>/', methods=['DELETE'])
@auth @auth
def delete_group(group_id): def delete_group(group_id):
"""*Authenticated request* """*Authenticated request*
@ -243,7 +243,7 @@ def delete_group(group_id):
group_users = Blueprint('group_users', __name__) group_users = Blueprint('group_users', __name__)
@group_users.route('<group_id>/users/', methods=['PUT']) @group_users.route('<int:group_id>/users/', methods=['PUT'])
@ForceJSON(required=['usernames']) @ForceJSON(required=['usernames'])
@auth @auth
def add_users_to_group(group_id): def add_users_to_group(group_id):
@ -304,7 +304,7 @@ def add_users_to_group(group_id):
not_found=unknown) not_found=unknown)
@group_users.route('<group_id>/users/', methods=['GET']) @group_users.route('<int:group_id>/users/', methods=['GET'])
@auth @auth
def list_group_members(group_id): def list_group_members(group_id):
"""*Authenticated request* """*Authenticated request*
@ -359,7 +359,7 @@ def list_group_members(group_id):
group_places = Blueprint('group_places', __name__) group_places = Blueprint('group_places', __name__)
@group_places.route('<group_id>/places/', methods=['GET']) @group_places.route('<int:group_id>/places/', methods=['GET'])
@auth @auth
def get_group_places(group_id): def get_group_places(group_id):
"""*Authenticated request* """*Authenticated request*
@ -407,7 +407,7 @@ def get_group_places(group_id):
places=places) places=places)
@group_places.route('<group_id>/places/', methods=['POST']) @group_places.route('<int:group_id>/places/', methods=['POST'])
@ForceJSON(required=['places']) @ForceJSON(required=['places'])
@auth @auth
def group_add_places(group_id): def group_add_places(group_id):
@ -477,7 +477,8 @@ def group_add_places(group_id):
rejected=rejected) rejected=rejected)
@group_places.route('<group_id>/places/<place_id>/', methods=['DELETE']) @group_places.route('<int:group_id>/places/<int:place_id>/',
methods=['DELETE'])
@auth @auth
def group_remove_place(group_id, place_id): def group_remove_place(group_id, place_id):
"""*Authenticated request* """*Authenticated request*
@ -504,10 +505,17 @@ def group_remove_place(group_id, place_id):
if not group: if not group:
raise ElementNotFoundException('Group') raise ElementNotFoundException('Group')
index = None index = -1
try: LOG.debug('Places: {places}'.format(places=group.places))
index = group.places.index(place_id) for (pos, place) in enumerate(group.places):
except ValueError: LOG.debug('Place {pos} = {place} (search {search})'.format(
pos=pos, place=place.id, search=place_id))
if place.id == place_id:
index = pos
break
LOG.debug('Index: {index}'.format(index=index))
if index == -1:
raise ElementNotFoundException('Place') raise ElementNotFoundException('Place')
del group.places[index] del group.places[index]

23
tests/group_tests.py

@ -499,5 +499,28 @@ class TestPlacesInGroup(LunchoTests):
self.assertTrue('places' in json) self.assertTrue('places' in json)
self.assertEquals(place.id, json['places'][0]['id']) self.assertEquals(place.id, json['places'][0]['id'])
def test_delete_place(self):
"""Delete a place from a group."""
group = self._group()
place = self._place()
group.places.append(place)
server.db.session.commit()
group_id = group.id
place_id = place.id
url = '/group/{group_id}/places/{place_id}/'.format(
group_id=group_id, place_id=place_id)
rv = self.delete(url,
token=self.user.token)
self.assertJsonOk(rv)
# check if it was really removed in the database
group = Group.query.get(group_id)
for place in group.places:
if place.id == place_id:
self.fail('Place still connected to group')
if __name__ == '__main__': if __name__ == '__main__':
unittest.main() unittest.main()

Loading…
Cancel
Save