Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix a logical error deciding whether to return a patchable schema. #150

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion flask_potion/fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
29 changes: 29 additions & 0 deletions tests/test_model_resource.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()))