From c56df5ba281c7cea05f28c45156ce380ba12284b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Tillenius?= Date: Wed, 28 Nov 2018 20:58:48 +0100 Subject: [PATCH] Fix a logic error deciding whether to return a patchable schema (#153) This partly fixes issue #98, where a field that has io="cr" wouldn't show up in the "create" schema. --- flask_potion/fields.py | 2 +- tests/test_model_resource.py | 29 +++++++++++++++++++++++++++++ 2 files changed, 30 insertions(+), 1 deletion(-) diff --git a/flask_potion/fields.py b/flask_potion/fields.py index 6f2989a..d87e145 100644 --- a/flask_potion/fields.py +++ b/flask_potion/fields.py @@ -717,7 +717,7 @@ def _response_schema(): return {"$ref": "#"} return {"$ref": self.target.routes["describedBy"].rule_factory(self.target)} - if not not self.patchable: + if not self.patchable: return _response_schema() else: return _response_schema(), self.target.schema.patchable.update diff --git a/tests/test_model_resource.py b/tests/test_model_resource.py index 9bf864c..4e920fd 100644 --- a/tests/test_model_resource.py +++ b/tests/test_model_resource.py @@ -85,3 +85,32 @@ class Meta: foo.bind(BarResource) self.assertEqual({'$ref': '/foo/schema'}, foo.response) + + def test_schema_io_create_flag(self): + + class FooResource(ModelResource): + class Schema: + name = fields.String() + slug = fields.String(io="cr") + + class Meta: + name = "foo" + + self.api.add_resource(FooResource) + data, code, headers = FooResource().described_by() + [create_link] = [ + link for link in data['links'] if link['rel'] == 'create'] + [update_link] = [ + link for link in data['links'] if link['rel'] == 'update'] + self.assertEqual({'$ref': '#'}, create_link['schema']) + self.assertEqual({ + "type": "object", + "additionalProperties": False, + "properties": { + "name": { + "type": "string" + } + } + }, update_link["schema"]) + self.assertEqual( + ["$uri", "name", "slug"], sorted(data["properties"].keys()))