Commit 5c94dbca authored by Ivan Tyagov's avatar Ivan Tyagov

Initial import of test for Session Tool.

git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@12870 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 541d20ac
##############################################################################
#
# Copyright (c) 2005 Nexedi SARL and Contributors. All Rights Reserved.
# Ivan Tyagov <ivan@nexedi.com>
#
# WARNING: This program as such is intended to be used by professional
# programmers who take the whole responsability of assessing all potential
# consequences resulting from its eventual inadequacies and bugs
# End users who are looking for a ready-to-use solution with commercial
# garantees and support are strongly adviced to contract a Free Software
# Service Company
#
# This program is Free Software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#
##############################################################################
import os, sys
if __name__ == '__main__':
execfile(os.path.join(sys.path[0], 'framework.py'))
# Needed in order to have a log file inside the current folder
os.environ['EVENT_LOG_FILE'] = os.path.join(os.getcwd(), 'zLOG.log')
os.environ['EVENT_LOG_SEVERITY'] = '-300'
from Testing import ZopeTestCase
from Products.ERP5Type.tests.ERP5TypeTestCase import ERP5TypeTestCase
from Products.ERP5Type.Document import newTempOrder
from AccessControl.SecurityManagement import newSecurityManager
from zLOG import LOG
import time
try:
from transaction import get as get_transaction
except ImportError:
pass
class TestSessionTool(ERP5TypeTestCase):
run_all_test = 1
session_id = "123456789"
def getTitle(self):
return "Session Tool"
def afterSetUp(self):
self.login()
def login(self, quiet=0, run=run_all_test):
uf = self.getPortal().acl_users
uf._doAddUser('ivan', '', ['Manager'], [])
uf._doAddUser('ERP5TypeTestCase', '', ['Manager'], [])
user = uf.getUserById('ivan').__of__(uf)
newSecurityManager(None, user)
def test_01_CheckSessionTool(self, quiet=0, run=run_all_test):
""" Create portal_sessions tool and needed cache factory. """
if not run:
return
if not quiet:
message = '\nCheck SessionTool '
ZopeTestCase._print(message)
LOG('Testing... ',0,message)
portal = self.getPortal()
portal_caches = portal.portal_caches
portal.manage_addProduct['ERP5Type'].manage_addTool('ERP5 Session Tool')
self.assertNotEqual(None,getattr(portal, 'portal_sessions', None))
## create needed cache fatory for Session Tool
session_cache_factory = portal_caches.newContent(portal_type="Cache Factory", \
id = 'erp5_session_cache')
session_cache_factory.setCacheDuration(36000)
ram_cache_plugin = session_cache_factory.newContent(portal_type="Ram Cache")
ram_cache_plugin.setCacheDuration(36000)
ram_cache_plugin.setIntIndex(0)
## update Ram Cache structure
portal_caches.updateCache()
get_transaction().commit()
def test_02_CreateSessionObject(self, quiet=0, run=run_all_test):
""" Create a session object and check if API (newContent) is properly working.
Check if storing objects is working as expected. """
if not run:
return
if not quiet:
message = '\nCreate of session object and assign attributes.'
ZopeTestCase._print(message)
LOG('Testing... ',0,message)
portal = self.getPortal()
portal_sessions = portal.portal_sessions
session = portal_sessions.newContent(
self.session_id, \
attr_1 = newTempOrder(portal_sessions, '1'), \
attr_2 = newTempOrder(portal_sessions, '2'), \
attr_3 = 1,
attr_4 = 0.1,
attr_5 = {},
attr_6 = 'string',)
## check temp (RAM based) attributes stored in session
for i in range (1, 3):
attr_name = 'attr_%s' %i
self.assert_(attr_name in session.keys())
attr = session[attr_name]
self.assert_(str(i), attr.getId())
self.assert_(0 == len(attr.objectIds()))
## check primitive stype storage
self.assert_(1 == session['attr_3'])
self.assert_(0.1 == session['attr_4'])
self.assert_({} == session['attr_5'])
self.assert_('string' == session['attr_6'])
def test_03_DeleteSessionObjectAttributes(self, quiet=0, run=run_all_test):
""" Delete session keys."""
if not run:
return
if not quiet:
message = '\nDelete some session keys.'
ZopeTestCase._print(message)
LOG('Testing... ',0,message)
portal = self.getPortal()
portal_sessions = portal.portal_sessions
session = portal_sessions[self.session_id]
session.pop('attr_1')
session.pop('attr_2')
self.assert_(not 'attr_1' in session.keys())
self.assert_(not 'attr_2' in session.keys())
def test_04_DeleteSessionObject(self, quiet=0, run=run_all_test):
""" Get session object and check keys stored in previous test. """
if not run:
return
if not quiet:
message = '\nDelete session object.'
ZopeTestCase._print(message)
LOG('Testing... ',0,message)
portal = self.getPortal()
portal_sessions = portal.portal_sessions
## delete it
portal_sessions.manage_delObjects(self.session_id)
session = portal_sessions[self.session_id]
self.assert_(0 == len(session.keys()))
if __name__ == '__main__':
framework()
else:
import unittest
def test_suite():
suite = unittest.TestSuite()
suite.addTest(unittest.makeSuite(TestSessionTool))
return suite
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