PATCH lot name

This commit is contained in:
Xavier Bustamante Talavera 2018-10-19 10:35:23 +02:00
parent 6751f0db16
commit 7ad7ab1d8a
2 changed files with 18 additions and 1 deletions

View File

@ -4,7 +4,7 @@ from enum import Enum
from typing import List, Set
import marshmallow as ma
from flask import jsonify, request
from flask import Response, jsonify, request
from marshmallow import Schema as MarshmallowSchema, fields as f
from teal.marshmallow import EnumField
from teal.resource import View
@ -36,6 +36,14 @@ class LotView(View):
ret.status_code = 201
return ret
def patch(self, id):
l = request.get_json()
lot = Lot.query.filter_by(id=id).one()
for key, value in l.items():
setattr(lot, key, value)
db.session.commit()
return Response(status=204)
def one(self, id: uuid.UUID):
"""Gets one event."""
lot = Lot.query.filter_by(id=id).one() # type: Lot

View File

@ -23,6 +23,15 @@ In case of error, debug with:
"""
def test_lot_modify_patch_endpoint(user: UserClient):
"""Creates and modifies lot properties through the endpoint"""
l, _ = user.post({'name': 'foo'}, res=Lot)
assert l['name'] == 'foo'
user.patch({'name': 'bar'}, res=Lot, item=l['id'], status=204)
l_after, _ = user.get(res=Lot, item=l['id'])
assert l_after['name'] == 'bar'
@pytest.mark.xfail(reason='Components are not added to lots!')
@pytest.mark.usefixtures(conftest.auth_app_context.__name__)
def test_lot_device_relationship():