Browse Source

delete places

master
Julio Biason 11 years ago
parent
commit
f68964a706
  1. 44
      luncho/blueprints/places.py
  2. 7
      tests/place_tests.py

44
luncho/blueprints/places.py

@ -14,6 +14,8 @@ from luncho.helpers import ForceJSON
from luncho.exceptions import AccountNotVerifiedException from luncho.exceptions import AccountNotVerifiedException
from luncho.exceptions import ElementNotFoundException from luncho.exceptions import ElementNotFoundException
from luncho.exceptions import UserIsNotAdminException
from luncho.exceptions import NewMaintainerDoesNotExistException
places = Blueprint('places', __name__) places = Blueprint('places', __name__)
@ -126,6 +128,8 @@ def update_place(placeId):
HTTP/1.1 200 OK HTTP/1.1 200 OK
Content-Type: text/json Content-Type: text/json
{ "status": "OK" }
**Request not in JSON format (400)**: **Request not in JSON format (400)**:
:py:class:`RequestMustBeJSONException` :py:class:`RequestMustBeJSONException`
@ -165,3 +169,43 @@ def update_place(placeId):
db.session.commit() db.session.commit()
return jsonify(status='OK') return jsonify(status='OK')
@places.route('<placeId>/', methods=['DELETE'])
@auth
def delete_place(placeId):
"""*Authenticated request* Delete the place. The user must be
the maintainer of the place to delete it.
**Success (200)**:
.. sourcecode:: http
HTTP/1.1 200 OK
Content-Type: text/json
{ "status": "OK" }
**User is not administrator of the group (403)**:
:py:class:`UserIsNotAdminException`
**User not found (via token) (404)**:
:py:class:`UserNotFoundException`
**The place does not exist (404)**:
:py:class:`ElementNotFoundException`
**Authorization required (412)**:
:py:class:`AuthorizationRequiredException`
"""
place = Place.query.get(placeId)
if not place:
raise ElementNotFoundException('Place')
if not place.owner == request.user.username:
raise UserIsNotAdminException()
db.session.delete(place)
db.session.commit()
return jsonify(status='OK')

7
tests/place_tests.py

@ -7,7 +7,6 @@ from json import loads
from luncho import server from luncho import server
from luncho.server import User
from luncho.server import Place from luncho.server import Place
from base import LunchoTests from base import LunchoTests
@ -87,6 +86,12 @@ class TestExistingPlaces(LunchoTests):
place = Place.query.get(placeId) place = Place.query.get(placeId)
self.assertEqual(place.owner, 'newUser') self.assertEqual(place.owner, 'newUser')
def test_delete_place(self):
"""Delete a place."""
rv = self.delete('/place/{placeId}/'.format(placeId=self.place.id),
token=self.user.token)
self.assertJsonOk(rv)
if __name__ == '__main__': if __name__ == '__main__':
unittest.main() unittest.main()

Loading…
Cancel
Save