From 7ad7ab1d8a12ec1ced0da5d7b80ac12b0f56404a Mon Sep 17 00:00:00 2001 From: Xavier Bustamante Talavera Date: Fri, 19 Oct 2018 10:35:23 +0200 Subject: [PATCH] PATCH lot name --- ereuse_devicehub/resources/lot/views.py | 10 +++++++++- tests/test_lot.py | 9 +++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/ereuse_devicehub/resources/lot/views.py b/ereuse_devicehub/resources/lot/views.py index 9b2707dc..5532a2e5 100644 --- a/ereuse_devicehub/resources/lot/views.py +++ b/ereuse_devicehub/resources/lot/views.py @@ -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 diff --git a/tests/test_lot.py b/tests/test_lot.py index 8749ed96..f84345c2 100644 --- a/tests/test_lot.py +++ b/tests/test_lot.py @@ -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():