Commit abeaee60 authored by Titouan Soulard's avatar Titouan Soulard

erp5_api_style: update tests for new API

parent 9d4b6f0f
...@@ -122,8 +122,6 @@ class jIOWebSection(WebSection): ...@@ -122,8 +122,6 @@ class jIOWebSection(WebSection):
__bobo_traverse__ from DocumentExtensibleTraversableMixin is not called __bobo_traverse__ from DocumentExtensibleTraversableMixin is not called
""" """
# Register current web site physical path for later URL generation # Register current web site physical path for later URL generation
if not self.REQUEST.get("live_test", False) and self.REQUEST.REQUEST_METHOD == "GET":
return self._asjIOStyle(mode="get", text_content=self.REQUEST.form.keys()[0])
return self._asjIOStyle(mode="get", text_content=self.REQUEST.get('BODY')) return self._asjIOStyle(mode="get", text_content=self.REQUEST.get('BODY'))
security.declareProtected(Permissions.View, 'post') security.declareProtected(Permissions.View, 'post')
...@@ -151,6 +149,4 @@ class jIOWebSection(WebSection): ...@@ -151,6 +149,4 @@ class jIOWebSection(WebSection):
__bobo_traverse__ from DocumentExtensibleTraversableMixin is not called __bobo_traverse__ from DocumentExtensibleTraversableMixin is not called
""" """
# Register current web site physical path for later URL generation # Register current web site physical path for later URL generation
if not self.REQUEST.get("live_test", False) and self.REQUEST.REQUEST_METHOD == "GET":
return self._asjIOStyle(mode="allDocs", text_content=self.REQUEST.form.keys()[0])
return self._asjIOStyle(mode="allDocs", text_content=self.REQUEST.get('BODY')) return self._asjIOStyle(mode="allDocs", text_content=self.REQUEST.get('BODY'))
...@@ -757,11 +757,11 @@ result_list = context.getPortalObject().portal_catalog( ...@@ -757,11 +757,11 @@ result_list = context.getPortalObject().portal_catalog(
select_list=("relative_url", "portal_type", "title"), select_list=("relative_url", "portal_type", "title"),
**search_kw **search_kw
) )
return [{ return json.dumps([{
"id": x.relative_url, "id": x.relative_url,
"portal_type": x.portal_type, "portal_type": x.portal_type,
"title": x.title, "title": x.title,
} for x in result_list] } for x in result_list])
""" % (self.id_template)) """ % (self.id_template))
def test_action_all_docs_success_one_action_one_result(self): def test_action_all_docs_success_one_action_one_result(self):
...@@ -785,14 +785,12 @@ return [{ ...@@ -785,14 +785,12 @@ return [{
"title": "%s" "title": "%s"
}""" % self.id_template }""" % self.id_template
)) ))
if not "result_list" in response: self.assertEqual(1, len(response))
raise ValueError("Unexcpected Answer %s" % response)
self.assertEqual(1, len(response["result_list"]))
self.assertEqual({ self.assertEqual({
u"id": person.getRelativeUrl().decode(), u"id": person.getRelativeUrl().decode(),
u"portal_type": person.getPortalType().decode(), u"portal_type": person.getPortalType().decode(),
u"title": person.getTitle().decode(), u"title": person.getTitle().decode(),
}, response["result_list"][0]) }, response[0])
def test_action_all_docs_success_one_action_no_result(self): def test_action_all_docs_success_one_action_no_result(self):
""" """
...@@ -815,9 +813,7 @@ return [{ ...@@ -815,9 +813,7 @@ return [{
"title": "BAR" "title": "BAR"
}""" }"""
)) ))
if not "result_list" in response: self.assertEqual(0, len(response))
raise ValueError("Unexcpected Answer %s" % response)
self.assertEqual(0, len(response["result_list"]))
def createUpdateScriptjIOWebSectionSearchOrganisationFromJSON(self): def createUpdateScriptjIOWebSectionSearchOrganisationFromJSON(self):
createZODBPythonScript( createZODBPythonScript(
...@@ -839,11 +835,11 @@ result_list = context.getPortalObject().portal_catalog( ...@@ -839,11 +835,11 @@ result_list = context.getPortalObject().portal_catalog(
select_list=("relative_url", "portal_type", "title"), select_list=("relative_url", "portal_type", "title"),
**search_kw **search_kw
) )
return [{ return json.dumps([{
"id": x.relative_url, "id": x.relative_url,
"portal_type": x.portal_type, "portal_type": x.portal_type,
"title": x.title, "title": x.title,
} for x in result_list] } for x in result_list])
""") """)
def test_action_all_docs_success_two_actions_with_result(self): def test_action_all_docs_success_two_actions_with_result(self):
...@@ -879,14 +875,12 @@ return [{ ...@@ -879,14 +875,12 @@ return [{
"title": "%s" "title": "%s"
}""" % self.id_template }""" % self.id_template
)) ))
if not "result_list" in response: self.assertEqual(1, len(response))
raise ValueError("Unexcpected Answer %s" % response)
self.assertEqual(1, len(response["result_list"]))
self.assertEqual({ self.assertEqual({
u"id": organisation.getRelativeUrl().decode(), u"id": organisation.getRelativeUrl().decode(),
u"portal_type": organisation.getPortalType().decode(), u"portal_type": organisation.getPortalType().decode(),
u"title": organisation.getTitle().decode(), u"title": organisation.getTitle().decode(),
}, response["result_list"][0]) }, response[0])
# Check Second action # Check Second action
response = json.loads(self.allDocsToApi( response = json.loads(self.allDocsToApi(
"""{ """{
...@@ -894,14 +888,12 @@ return [{ ...@@ -894,14 +888,12 @@ return [{
"title": "%s" "title": "%s"
}""" % self.id_template }""" % self.id_template
)) ))
if not "result_list" in response: self.assertEqual(1, len(response))
raise ValueError("Unexcpected Answer %s" % response)
self.assertEqual(1, len(response["result_list"]))
self.assertEqual({ self.assertEqual({
u"id": person.getRelativeUrl().decode(), u"id": person.getRelativeUrl().decode(),
u"portal_type": person.getPortalType().decode(), u"portal_type": person.getPortalType().decode(),
u"title": person.getTitle().decode(), u"title": person.getTitle().decode(),
}, response["result_list"][0]) }, response[0])
def test_action_all_docs_success_two_actions_with_no_result(self): def test_action_all_docs_success_two_actions_with_no_result(self):
""" """
...@@ -936,9 +928,7 @@ return [{ ...@@ -936,9 +928,7 @@ return [{
"title": "BAR" "title": "BAR"
}""" }"""
)) ))
if not "result_list" in response: self.assertEqual(0, len(response))
raise ValueError("Unexcpected Answer %s" % response)
self.assertEqual(0, len(response["result_list"]))
# Check Second action # Check Second action
response = json.loads(self.allDocsToApi( response = json.loads(self.allDocsToApi(
"""{ """{
...@@ -946,9 +936,7 @@ return [{ ...@@ -946,9 +936,7 @@ return [{
"title": "BAR" "title": "BAR"
}""" }"""
)) ))
if not "result_list" in response: self.assertEqual(0, len(response))
raise ValueError("Unexcpected Answer %s" % response)
self.assertEqual(0, len(response["result_list"]))
def test_action_all_docs_no_action_matches(self): def test_action_all_docs_no_action_matches(self):
""" """
......
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