def test_put_object(self): resp = Response(FauxResponse()) app = ApplicationAPI(self.portal, '') objs = { 'front-page': [{ 'text': "<p>Action and reaction, ebb and flow, trial and error, change - this is the rhythm of living. Out of our over-confidence, fear; out of our fear, clearer vision, fresh hope. And out of hope, progress.</p><br /> --<i>Bruce Barton</i>" }], '/plone/events': [ { 'description': 'What\'s up doc?' }, ] } self.login('test_user_1_') put_obj_data = app.put_object(objs) self.logout() resp.setBody(put_obj_data) put_obj_resp, method = xmlrpclib.loads(resp._body) expected_resp = ['/plone/front-page', '/plone/events'] self.failUnlessEqual(len(put_obj_resp[0]), len(expected_resp)) for i in put_obj_resp[0]: self.failUnless(i in expected_resp, "'%s' is not in %s?" % (i, expected_resp)) self.failUnlessEqual(self.portal['front-page']['text'].getRaw(), objs['front-page'][0]['text']) self.failUnlessEqual(self.portal['events']['description'], objs['/plone/events'][0]['description'])
def test_get_workflow(self): """This tests for the results of the get_workflow logic and the format of the results.""" # Setup the context variable. fp = self.portal['front-page'] # First, setup the call results. resp = Response(FauxResponse()) wf = Workflow(fp, '') self.login('test_user_1_') wf_data = wf.get_workflow() self.logout() resp.setBody(wf_data) wf_body = resp._body wf_resp, method = xmlrpclib.loads(wf_body) wf_results = wf_resp[0] # Now, get the results directly from the tool. portal_workflow = getToolByName(self.portal, 'portal_workflow') self.login('test_user_1_') state = portal_workflow.getInfoFor(fp, 'review_state') transitions = portal_workflow.getTransitionsFor(fp) self.logout() transitions_list = [x['id'] for x in transitions] self.failUnlessEqual(state, wf_results['state']) self.failUnlessEqual(transitions_list, wf_results['transitions'])
def test_get_workflow(self): """This tests for the results of the get_workflow logic and the format of the results.""" # Setup the context variable. fp = self.portal['front-page'] # First, setup the call results. resp = Response(FauxResponse()) wf = Workflow(fp, '') self.login('test_user_1_') wf_data = wf.get_workflow() self.logout() resp.setBody(wf_data) wf_body = resp._body wf_resp, method = xmlrpclib.loads(wf_body) wf_results = wf_resp[0] # Now, get the results directly from the tool. portal_workflow = getToolByName(self.portal, 'portal_workflow') self.login('test_user_1_') state = portal_workflow.getInfoFor(fp, 'review_state') transitions = portal_workflow.getTransitionsFor(fp) self.logout() transitions_list = [ x['id'] for x in transitions ] self.failUnlessEqual(state, wf_results['state']) self.failUnlessEqual(transitions_list, wf_results['transitions'])
def test_query(self): resp = Response(FauxResponse()) q = Query(self.portal, '') queryFormater = getUtility(IFormatQueryResults) portal_catalog = getToolByName(self.portal, 'portal_catalog') criteria = {'Type': 'Collection'} tool_results = queryFormater(portal_catalog(criteria)) q_data = q.query(criteria) resp.setBody(q_data) q_body = resp._body q_resp, method = xmlrpclib.loads(q_body) q_results = q_resp[0] for path in q_results: self.failUnless(path in tool_results.keys()) q_index = q_results[path] tool_index = tool_results[path] for i in tool_index: if isinstance(q_index[i], xmlrpclib.DateTime): # xmlrpclib formats dates to the ISO 8601 standard. self.failUnlessEqual(tool_index[i].ISO8601(), q_index[i]) continue elif isinstance(q_index[i], list): # xmlrpclib converts tuples to lists. q_index[i] = tuple(q_index[i]) self.failUnlessEqual(tool_index[i], q_index[i])
def test_query(self): resp = Response(FauxResponse()) q = Query(self.portal, '') queryFormater = getUtility(IFormatQueryResults) portal_catalog = getToolByName(self.portal, 'portal_catalog') criteria = {'Type': 'Collection'} tool_results = queryFormater(portal_catalog(criteria)) q_data = q.query(criteria) resp.setBody(q_data) q_body = resp._body q_resp, method = xmlrpclib.loads(q_body) q_results = q_resp[0] for path in q_results: self.failUnless(path in tool_results.keys()) q_index = q_results[path] tool_index = tool_results[path] for i in tool_index: if isinstance(q_index[i], xmlrpclib.DateTime): # xmlrpclib formats dates to the ISO 8601 standard. self.failUnlessEqual(tool_index[i].ISO8601(), q_index[i]) continue elif isinstance(q_index[i], list): # xmlrpclib converts tuples to lists. q_index[i] = tuple(q_index[i]) self.failUnlessEqual(tool_index[i], q_index[i])
def test_types(self): resp = Response(FauxResponse()) t = Types(self.folder, '') type_results = [ [x.id, x.title_or_id()] for x in self.folder.allowedContentTypes() ] t_data = t.get_types() resp.setBody(t_data) t_body = resp._body t_resp, method = xmlrpclib.loads(t_body) t_results = t_resp[0] self.failUnlessEqual(type_results, t_results)
def test_anonymous_get_object(self): resp = Response(FauxResponse()) app = ApplicationAPI(self.portal, '') get_obj_data = app.get_object(['/'.join(self.folder.getPhysicalPath()), '']) resp.setBody(get_obj_data) get_obj_resp, method = xmlrpclib.loads(resp._body) get_obj_results = get_obj_resp[0] for path in get_obj_results: self.failUnless(type(get_obj_results[path][0]) == dict) self.failUnless(type(get_obj_results[path][1]) == str) self.failUnless(type(get_obj_results[path][2]) == dict or get_obj_results[path][2] == None)
def test_post_object(self): resp = Response(FauxResponse()) app = ApplicationAPI(self.portal, '') objs = {'news1': [{'description': 'News One', 'title': 'news1', 'text': '\n<p>Hot off the press!</p>\n', 'id': 'news1'}, 'News Item']} self.login('test_user_1_') post_obj_data = app.post_object(objs) self.logout() resp.setBody(post_obj_data) post_obj_resp, method = xmlrpclib.loads(resp._body) self.failUnlessEqual(post_obj_resp[0], ['/plone/news1']) self.assertTrue(self.portal['news1'])
def test_delete_object(self): resp = Response(FauxResponse()) app = ApplicationAPI(self.portal, '') self.portal.invokeFactory(type_name='News Item', id='news1') objs = ['news1'] self.login('test_user_1_') del_obj_data = app.delete_object(objs) self.logout() resp.setBody(del_obj_data) del_obj_resp, method = xmlrpclib.loads(resp._body) self.failUnlessEqual(del_obj_resp[0], None) self.failUnlessEqual(self.portal.get('news1', 100), 100)
def test_delete_object(self): resp = Response(FauxResponse()) app = ApplicationAPI(self.portal, '') self.portal.invokeFactory(type_name='News Item', id='news1') objs = ['news1'] self.login('test_user_1_') del_obj_data = app.delete_object(objs) self.logout() resp.setBody(del_obj_data) del_obj_resp, method = xmlrpclib.loads(resp._body) self.failUnlessEqual(del_obj_resp[0], None) self.failUnlessEqual(self.portal.get('news1', 100), 100)
def test_anonymous_get_object(self): resp = Response(FauxResponse()) app = ApplicationAPI(self.portal, '') get_obj_data = app.get_object( ['/'.join(self.folder.getPhysicalPath()), '']) resp.setBody(get_obj_data) get_obj_resp, method = xmlrpclib.loads(resp._body) get_obj_results = get_obj_resp[0] for path in get_obj_results: self.failUnless(type(get_obj_results[path][0]) == dict) self.failUnless(type(get_obj_results[path][1]) == str) self.failUnless( type(get_obj_results[path][2]) == dict or get_obj_results[path][2] == None)
def test_put_object(self): resp = Response(FauxResponse()) app = ApplicationAPI(self.portal, '') objs = {'front-page': [{'text': "<p>Action and reaction, ebb and flow, trial and error, change - this is the rhythm of living. Out of our over-confidence, fear; out of our fear, clearer vision, fresh hope. And out of hope, progress.</p><br /> --<i>Bruce Barton</i>"}], '/plone/events': [{'description': 'What\'s up doc?'},]} self.login('test_user_1_') put_obj_data = app.put_object(objs) self.logout() resp.setBody(put_obj_data) put_obj_resp, method = xmlrpclib.loads(resp._body) expected_resp = ['/plone/front-page', '/plone/events'] self.failUnlessEqual(len(put_obj_resp[0]), len(expected_resp)) for i in put_obj_resp[0]: self.failUnless(i in expected_resp, "'%s' is not in %s?" % (i, expected_resp)) self.failUnlessEqual(self.portal['front-page']['text'].getRaw(), objs['front-page'][0]['text']) self.failUnlessEqual(self.portal['events']['description'], objs['/plone/events'][0]['description'])
def test_get_schema_with_path(self): resp = Response(FauxResponse()) app = ApplicationAPI(self.portal, '') type_ = 'Link' self.login('test_user_1_') schema_data = app.get_schema(type_, "Members") resp.setBody(schema_data) schema_resp, method = xmlrpclib.loads(resp._body) self.logout() schema_results = schema_resp[0] expected_results = {'excludeFromNav': {'required': False, 'type': 'boolean'}, 'remoteUrl': {'required': True, 'type': 'string'}, 'description': {'required': False, 'type': 'text'}, 'contributors': {'required': False, 'type': 'lines'}, 'title': {'required': 1, 'type': 'string'}, 'language': {'required': False, 'type': 'string'}, 'rights': {'required': False, 'type': 'text'}, 'modification_date': {'required': False, 'type': 'datetime'}, 'location': {'required': False, 'type': 'string'}, 'creation_date': {'required': False, 'type': 'datetime'}, 'effectiveDate': {'required': False, 'type': 'datetime'}, 'relatedItems': {'required': False, 'type': 'reference'}, 'expirationDate': {'required': False, 'type': 'datetime'}, 'allowDiscussion': {'required': False, 'type': 'boolean'}, 'creators': {'required': False, 'type': 'lines'}, 'id': {'required': 0, 'type': 'string'}, 'subject': {'required': False, 'type': 'lines'}} self.failUnlessEqual(len(schema_results), len(expected_results)) for attr, value in expected_results.iteritems(): self.failUnlessEqual(value, schema_results[attr], "%s != %s for schema attribute '%s'" % (value, schema_results[attr], attr))
def test_query_with_datetime(self): # This test heavily depends on the front-page document creation date resp = Response(FauxResponse()) q = Query(self.portal, '') queryFormater = getUtility(IFormatQueryResults) portal_catalog = getToolByName(self.portal, 'portal_catalog') # python2.4's xmlrpclib.DateTime constructor doesn't seem to like the provided datetime object # min_date = xmlrpclib.DateTime(datetime.datetime(2007, 12, 31)) min_date = xmlrpclib.DateTime('20071231T00:00:00') # max_date = xmlrpclib.DateTime(datetime.datetime(2007, 1, 1)) max_date = xmlrpclib.DateTime('20070101T00:00:00') xmlrpc_criteria = { 'created': { 'query': [min_date, max_date], 'range': 'min:max' } } normal_criteria = { 'created': { 'query': [_convert_datetime(min_date), _convert_datetime(max_date)], 'range': 'min:max' } } tool_results = queryFormater(portal_catalog(normal_criteria)) q_data = q.query(xmlrpc_criteria) resp.setBody(q_data) q_body = resp._body q_resp, method = xmlrpclib.loads(q_body) q_results = q_resp[0] for path in q_results: self.failUnless(path in tool_results.keys()) q_index = q_results[path] tool_index = tool_results[path] for i in tool_index: if isinstance(q_index[i], xmlrpclib.DateTime): # xmlrpclib formats dates to the ISO 8601 standard. self.failUnlessEqual(tool_index[i].ISO8601(), q_index[i]) continue elif isinstance(q_index[i], list): # xmlrpclib converts tuples to lists. q_index[i] = tuple(q_index[i]) self.failUnlessEqual(tool_index[i], q_index[i])
def test_post_object(self): resp = Response(FauxResponse()) app = ApplicationAPI(self.portal, '') objs = { 'news1': [{ 'description': 'News One', 'title': 'news1', 'text': '\n<p>Hot off the press!</p>\n', 'id': 'news1' }, 'News Item'] } self.login('test_user_1_') post_obj_data = app.post_object(objs) self.logout() resp.setBody(post_obj_data) post_obj_resp, method = xmlrpclib.loads(resp._body) self.failUnlessEqual(post_obj_resp[0], ['/plone/news1']) self.assertTrue(self.portal['news1'])
def test_set_workflow(self): # Setup the context variable. fp = self.portal['front-page'] resp = Response(FauxResponse()) # First, setup the call results. resp = Response(FauxResponse()) wf = Workflow(fp, '') # Transition the workflow. self.login('test_user_1_') wf_data = wf.set_workflow('retract') self.logout() resp.setBody(wf_data) wf_body = resp._body wf_resp, method = xmlrpclib.loads(wf_body) wf_results = wf_resp[0] # Test the result of the set_workflow call is None. self.failUnlessEqual(wf_results, None) # Verify the worflow has been changed. portal_workflow = getToolByName(self.portal, 'portal_workflow') state = portal_workflow.getInfoFor(fp, 'review_state') self.failUnlessEqual(state, 'private')
def test_set_workflow(self): # Setup the context variable. fp = self.portal['front-page'] resp = Response(FauxResponse()) # First, setup the call results. resp = Response(FauxResponse()) wf = Workflow(fp, '') # Transition the workflow. self.login('test_user_1_') wf_data = wf.set_workflow('retract') self.logout() resp.setBody(wf_data) wf_body = resp._body wf_resp, method = xmlrpclib.loads(wf_body) wf_results = wf_resp[0] # Test the result of the set_workflow call is None. self.failUnlessEqual(wf_results, None) # Verify the worflow has been changed. portal_workflow = getToolByName(self.portal, 'portal_workflow') state = portal_workflow.getInfoFor(fp, 'review_state') self.failUnlessEqual(state, 'private')
def test_query_with_datetime(self): # This test heavily depends on the front-page document creation date resp = Response(FauxResponse()) q = Query(self.portal, '') queryFormater = getUtility(IFormatQueryResults) portal_catalog = getToolByName(self.portal, 'portal_catalog') # python2.4's xmlrpclib.DateTime constructor doesn't seem to like the provided datetime object # min_date = xmlrpclib.DateTime(datetime.datetime(2007, 12, 31)) min_date = xmlrpclib.DateTime('20071231T00:00:00') # max_date = xmlrpclib.DateTime(datetime.datetime(2007, 1, 1)) max_date = xmlrpclib.DateTime('20070101T00:00:00') xmlrpc_criteria = {'created': {'query': [min_date, max_date], 'range': 'min:max'}} normal_criteria = {'created': {'query': [_convert_datetime(min_date), _convert_datetime(max_date)], 'range': 'min:max'}} tool_results = queryFormater(portal_catalog(normal_criteria)) q_data = q.query(xmlrpc_criteria) resp.setBody(q_data) q_body = resp._body q_resp, method = xmlrpclib.loads(q_body) q_results = q_resp[0] for path in q_results: self.failUnless(path in tool_results.keys()) q_index = q_results[path] tool_index = tool_results[path] for i in tool_index: if isinstance(q_index[i], xmlrpclib.DateTime): # xmlrpclib formats dates to the ISO 8601 standard. self.failUnlessEqual(tool_index[i].ISO8601(), q_index[i]) continue elif isinstance(q_index[i], list): # xmlrpclib converts tuples to lists. q_index[i] = tuple(q_index[i]) self.failUnlessEqual(tool_index[i], q_index[i])
def test_get_schema_with_path(self): resp = Response(FauxResponse()) app = ApplicationAPI(self.portal, '') type_ = 'Link' self.login('test_user_1_') schema_data = app.get_schema(type_, "Members") resp.setBody(schema_data) schema_resp, method = xmlrpclib.loads(resp._body) self.logout() schema_results = schema_resp[0] expected_results = { 'excludeFromNav': { 'required': False, 'type': 'boolean' }, 'remoteUrl': { 'required': True, 'type': 'string' }, 'description': { 'required': False, 'type': 'text' }, 'contributors': { 'required': False, 'type': 'lines' }, 'title': { 'required': 1, 'type': 'string' }, 'language': { 'required': False, 'type': 'string' }, 'rights': { 'required': False, 'type': 'text' }, 'modification_date': { 'required': False, 'type': 'datetime' }, 'location': { 'required': False, 'type': 'string' }, 'creation_date': { 'required': False, 'type': 'datetime' }, 'effectiveDate': { 'required': False, 'type': 'datetime' }, 'relatedItems': { 'required': False, 'type': 'reference' }, 'expirationDate': { 'required': False, 'type': 'datetime' }, 'allowDiscussion': { 'required': False, 'type': 'boolean' }, 'creators': { 'required': False, 'type': 'lines' }, 'id': { 'required': 0, 'type': 'string' }, 'subject': { 'required': False, 'type': 'lines' } } self.failUnlessEqual(len(schema_results), len(expected_results)) for attr, value in expected_results.iteritems(): self.failUnlessEqual( value, schema_results[attr], "%s != %s for schema attribute '%s'" % (value, schema_results[attr], attr))