Skip to content

Commit

Permalink
storeapi: use structured data for the conflicted current value (#2316)
Browse files Browse the repository at this point in the history
Instead of relying on the Store's value being in the message of the
error use the structured data found in 'extra' instead. Also updated
the fake store to match reality.

LP: #1795416
  • Loading branch information
sparkiegeek authored and sergiusens committed Oct 4, 2018
1 parent d2b3aca commit f9203ca
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 9 deletions.
2 changes: 1 addition & 1 deletion snapcraft/storeapi/errors.py
Expand Up @@ -516,7 +516,7 @@ def __init__(self, snap_name, response, metadata):
(
"Conflict in {!r} field:".format(field_name),
" In snapcraft.yaml: {!r}".format(sent),
" In the Store: {!r}".format(error["message"]),
" In the Store: {!r}".format(error["extra"]["current"]),
)
)
parts.append(
Expand Down
31 changes: 23 additions & 8 deletions tests/fake_servers/api.py
Expand Up @@ -800,14 +800,19 @@ def snap_metadata(self, request):
error_list = []
for name, value in request.json_body.items():
if name == "test-conflict-with-braces":
message = "value with {braces}"
conflict_value = "value with {braces}"
else:
message = value + "-changed"
conflict_value = value + "-changed"
error_list.append(
{
"message": message,
"message": "Conflict on {}".format(name),
"code": "conflict",
"extra": {"name": name},
"extra": {
"name": name,
"field": name,
"current": conflict_value,
"value": value,
},
}
)
payload = json.dumps({"error_list": error_list}).encode("utf8")
Expand Down Expand Up @@ -856,9 +861,14 @@ def snap_binary_metadata(self, request):
# POST, return error
error_list = [
{
"message": "original-icon",
"message": "Conflict on icon",
"code": "conflict",
"extra": {"name": "icon"},
"extra": {
"name": "icon",
"field": "icon",
"current": "original-icon",
"value": "<posted-icon>",
},
}
]
payload = json.dumps({"error_list": error_list}).encode("utf8")
Expand All @@ -867,9 +877,14 @@ def snap_binary_metadata(self, request):
# POST, return error
error_list = [
{
"message": "original icon with {braces}",
"message": "Conflict on icon",
"code": "conflict",
"extra": {"name": "icon"},
"extra": {
"name": "icon",
"field": "icon",
"current": "original icon with {braces}",
"value": "<posted-icon>",
},
}
]
payload = json.dumps({"error_list": error_list}).encode("utf8")
Expand Down

0 comments on commit f9203ca

Please sign in to comment.