Commit c612430d authored by Tristan Cavelier's avatar Tristan Cavelier

JIO scripts upgrade + Unit tests

All commands are now complete. But some errors may occur
with unexpected metadata type.
parent 25dcd0f5
...@@ -51,14 +51,13 @@ ...@@ -51,14 +51,13 @@
<item> <item>
<key> <string>_body</string> </key> <key> <string>_body</string> </key>
<value> <string>import json\n <value> <string>import json\n
from Products.ERP5Type.Log import log\n #from Products.ERP5Type.Log import log\n
# use JSON.parse as json.loads and JSON.stringify as json.dumps\n # use JSON.parse as json.loads and JSON.stringify as json.dumps\n
\n \n
context.REQUEST.response.setHeader("Access-Control-Allow-Origin", "*")\n context.REQUEST.response.setHeader("Access-Control-Allow-Origin", "*")\n
\n \n
jio = context.JIO_class()\n jio = context.JIO_class()\n
\n \n
log(context.REQUEST.form["option"])\n
try: option = jio.jsonUtf8Loads(context.REQUEST.form["option"])\n try: option = jio.jsonUtf8Loads(context.REQUEST.form["option"])\n
except KeyError:\n except KeyError:\n
option = {}\n option = {}\n
......
...@@ -75,7 +75,7 @@ jio.setMode(mode)\n ...@@ -75,7 +75,7 @@ jio.setMode(mode)\n
try:\n try:\n
metadata_json = jio.getDocumentMetadata(doc)\n metadata_json = jio.getDocumentMetadata(doc)\n
except ValueError as e:\n except ValueError as e:\n
return jio.sendError(jio.createBadRequestDict("Cannot get document", str(e)))\n return jio.sendError(jio.createConflictDict("Cannot get document", str(e)))\n
except LookupError as e:\n except LookupError as e:\n
return jio.sendError(jio.createNotFoundDict("Cannot get document", str(e)))\n return jio.sendError(jio.createNotFoundDict("Cannot get document", str(e)))\n
\n \n
......
...@@ -75,7 +75,7 @@ jio.setMode(mode)\n ...@@ -75,7 +75,7 @@ jio.setMode(mode)\n
try:\n try:\n
attachment_data = jio.getDocumentAttachment(doc)\n attachment_data = jio.getDocumentAttachment(doc)\n
except ValueError as e:\n except ValueError as e:\n
return jio.sendError(jio.createBadRequestDict("Cannot get attachment", str(e)))\n return jio.sendError(jio.createConflictDict("Cannot get attachment", str(e)))\n
except LookupError as e:\n except LookupError as e:\n
return jio.sendError(jio.createNotFoundDict("Cannot get attachment", str(e)))\n return jio.sendError(jio.createNotFoundDict("Cannot get attachment", str(e)))\n
\n \n
......
...@@ -60,7 +60,8 @@ jio = context.JIO_class()\n ...@@ -60,7 +60,8 @@ jio = context.JIO_class()\n
\n \n
try: doc = jio.jsonUtf8Loads(context.REQUEST.form["doc"])\n try: doc = jio.jsonUtf8Loads(context.REQUEST.form["doc"])\n
except KeyError:\n except KeyError:\n
return jio.sendError(jio.createBadRequestDict("Cannot get document", "No document information received"))\n return jio.sendError(jio.createBadRequestDict(\n
"Cannot get document", "No document information received"))\n
\n \n
try: mode = str(context.REQUEST.form["mode"])\n try: mode = str(context.REQUEST.form["mode"])\n
except KeyError: mode = "generic"\n except KeyError: mode = "generic"\n
...@@ -68,10 +69,12 @@ jio.setMode(mode)\n ...@@ -68,10 +69,12 @@ jio.setMode(mode)\n
\n \n
try:\n try:\n
response_json = jio.putDocumentMetadata(doc, overwrite=False)\n response_json = jio.putDocumentMetadata(doc, overwrite=False)\n
except (ValueError, TypeError) as e:\n except (ValueError, TypeError, LookupError) as e:\n
return jio.sendError(jio.createBadRequestDict("Cannot post document", str(e)))\n
except LookupError as e:\n
return jio.sendError(jio.createConflictDict("Cannot post document", str(e)))\n return jio.sendError(jio.createConflictDict("Cannot post document", str(e)))\n
# except KeyError as e:\n
# return jio.sendError(jio.createForbiddenDict("Cannot post document", str(e)))\n
# except LookupError as e:\n
# return jio.sendError(jio.createConflictDict("Cannot post document", str(e)))\n
\n \n
return jio.sendSuccess(response_json)\n return jio.sendSuccess(response_json)\n
</string> </value> </string> </value>
......
...@@ -67,9 +67,11 @@ except KeyError: mode = "generic"\n ...@@ -67,9 +67,11 @@ except KeyError: mode = "generic"\n
jio.setMode(mode)\n jio.setMode(mode)\n
\n \n
try:\n try:\n
response_json = jio.putDocumentMetadata(doc)\n response_json = jio.putDocumentMetadata(doc, need_id=True)\n
except (ValueError, TypeError) as e:\n except (ValueError, TypeError, KeyError) as e:\n
return jio.sendError(jio.createBadRequestDict("Cannot put document", str(e)))\n return jio.sendError(jio.createConflictDict("Cannot put document", str(e)))\n
# except KeyError as e:\n
# return jio.sendError(jio.createForbiddenDict("Cannot put document", str(e)))\n
\n \n
return jio.sendSuccess(response_json)\n return jio.sendSuccess(response_json)\n
</string> </value> </string> </value>
......
...@@ -68,10 +68,10 @@ jio.setMode(mode)\n ...@@ -68,10 +68,10 @@ jio.setMode(mode)\n
\n \n
try:\n try:\n
response_json = jio.putDocumentAttachment(doc)\n response_json = jio.putDocumentAttachment(doc)\n
except ValueError as e:\n except (ValueError, TypeError, KeyError) as e:\n
return jio.sendError(jio.createBadRequestDict("Cannot put attachment", str(e)))\n return jio.sendError(jio.createConflictDict("Cannot put attachment", str(e)))\n
except TypeError as e:\n # except TypeError as e:\n
return jio.sendError(jio.createBadRequestDict("Cannot put attachment", str(e)))\n # return jio.sendError(jio.createBadRequestDict("Cannot put attachment", str(e)))\n
\n \n
return jio.sendSuccess(response_json)\n return jio.sendSuccess(response_json)\n
</string> </value> </string> </value>
......
...@@ -69,7 +69,7 @@ jio.setMode(mode)\n ...@@ -69,7 +69,7 @@ jio.setMode(mode)\n
try:\n try:\n
response_json = jio.removeAttachment(doc)\n response_json = jio.removeAttachment(doc)\n
except (ValueError, TypeError) as e:\n except (ValueError, TypeError) as e:\n
return jio.sendError(jio.createBadRequestDict("Cannot remove attachment", str(e)))\n return jio.sendError(jio.createConflictDict("Cannot remove attachment", str(e)))\n
except LookupError as e:\n except LookupError as e:\n
return jio.sendError(jio.createNotFoundDict("Cannot remove attachment", str(e)))\n return jio.sendError(jio.createNotFoundDict("Cannot remove attachment", str(e)))\n
\n \n
......
This diff is collapsed.
4 5
\ No newline at end of file \ No newline at end of file
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment