[Zope-Checkins] CVS: Zope/lib/python/Products/Sessions/tests - testBrowserIdManager.py:1.3 testSessionDataManager.py:1.6
Chris McDonough
chrism@zope.com
Sat, 17 Nov 2001 11:07:42 -0500
Update of /cvs-repository/Zope/lib/python/Products/Sessions/tests
In directory cvs.zope.org:/tmp/cvs-serv27973/tests
Modified Files:
testBrowserIdManager.py testSessionDataManager.py
Log Message:
As per suggestions by Amos, I changed the terminology used by the browser id manager and session data manager. Previous to the change, browser ids were known as "tokens". I've changed this to "browser id" in the docs as well as in all API methods that used the name "token". Interfaces, permissions, and help have been updated with the changes.
=== Zope/lib/python/Products/Sessions/tests/testBrowserIdManager.py 1.2 => 1.3 ===
del self.m
- def testSetTokenKey(self):
- self.m.setTokenKey('foo')
- assert self.m.getTokenKey()== 'foo'
+ def testSetBrowserIdName(self):
+ self.m.setBrowserIdName('foo')
+ assert self.m.getBrowserIdName()== 'foo'
- def testSetBadKeyString(self):
+ def testSetBadBrowserIdName(self):
try:
- self.m.setTokenKey('')
+ self.m.setBrowserIdName('')
except BrowserIdManagerErr:
pass
else:
assert 1 == 2
try:
- self.m.setTokenKey(1)
+ self.m.setBrowserIdName(1)
except BrowserIdManagerErr:
pass
else:
@@ -134,7 +134,7 @@
def testSetBadNamespaces(self):
d = {1:'gummy', 2:'froopy'}
try:
- self.m.setTokenKeyNamespaces(d)
+ self.m.setBrowserIdNamespaces(d)
except BrowserIdManagerErr:
pass
else:
@@ -142,8 +142,22 @@
def testSetGoodNamespaces(self):
d = {1:'cookies', 2:'form'}
- self.m.setTokenKeyNamespaces(d)
- assert self.m.getTokenKeyNamespaces() == d
+ self.m.setBrowserIdNamespaces(d)
+ assert self.m.getBrowserIdNamespaces() == d
+
+ def testSetNamespacesByLocation(self):
+ self.m.setBrowserIdLocation('cookiesonly')
+ assert self.m.getBrowserIdNamespaces() == {1:'cookies'}
+ assert self.m.getBrowserIdLocation() == 'cookiesonly'
+ self.m.setBrowserIdLocation('cookiesthenform')
+ assert self.m.getBrowserIdNamespaces() == {1:'cookies', 2:'form'}
+ assert self.m.getBrowserIdLocation() == 'cookiesthenform'
+ self.m.setBrowserIdLocation('formonly')
+ assert self.m.getBrowserIdNamespaces() == {1:'form'}
+ assert self.m.getBrowserIdLocation() == 'formonly'
+ self.m.setBrowserIdLocation('formthencookies')
+ assert self.m.getBrowserIdNamespaces() == {1:'form', 2:'cookies'}
+ assert self.m.getBrowserIdLocation() == 'formthencookies'
def testSetBadCookiePath(self):
path = '/;'
@@ -224,131 +238,99 @@
self.m.setCookieSecure(1)
assert self.m.getCookieSecure() == 1
- def testDelegateToParent(self):
- self.m.turnOff()
- try:
- a = self.m.hasToken()
- except BrowserIdManagerErr:
- pass
- else:
- assert 1==2
-
- def testGetTokenCookie(self):
- token = self.m.getToken()
- self.m.REQUEST.browser_token_ = token
- self.m.REQUEST.browser_token_ns_ = 'cookies'
- tokenkey = self.m.getTokenKey()
+ def testGetBrowserIdCookie(self):
+ token = self.m.getBrowserId()
+ self.m.REQUEST.browser_id_ = token
+ self.m.REQUEST.browser_id_ns_ = 'cookies'
+ tokenkey = self.m.getBrowserIdName()
self.m.REQUEST.cookies[tokenkey] = token
- a = self.m.getToken()
+ a = self.m.getBrowserId()
assert a == token, repr(a)
- assert self.m.isTokenFromCookie()
+ assert self.m.isBrowserIdFromCookie()
- def testSetSessionTokenDontCreate(self):
- a = self.m.getToken(0)
+ def testSetBrowserIdDontCreate(self):
+ a = self.m.getBrowserId(0)
assert a == None
- def testSetSessionTokenCreate(self):
- a = self.m.getToken(1)
- tokenkey = self.m.getTokenKey()
+ def testSetBrowserIdCreate(self):
+ a = self.m.getBrowserId(1)
+ tokenkey = self.m.getBrowserIdName()
b = self.m.REQUEST.RESPONSE.cookies[tokenkey]
assert a == b['value'], (a, b)
def testHasToken(self):
- assert not self.m.hasToken()
- a = self.m.getToken()
- assert self.m.hasToken()
+ assert not self.m.hasBrowserId()
+ a = self.m.getBrowserId()
+ assert self.m.hasBrowserId()
def testTokenIsNew(self):
- a = self.m.getToken()
- assert self.m.isTokenNew()
+ a = self.m.getBrowserId()
+ assert self.m.isBrowserIdNew()
- def testIsTokenFromCookieFirst(self):
- token = self.m.getToken()
- self.m.REQUEST.browser_token_ = token
- self.m.REQUEST.browser_token_ns_ = 'cookies'
- tokenkey = self.m.getTokenKey()
+ def testIsBrowserIdFromCookieFirst(self):
+ token = self.m.getBrowserId()
+ self.m.REQUEST.browser_id_ = token
+ self.m.REQUEST.browser_id_ns_ = 'cookies'
+ tokenkey = self.m.getBrowserIdName()
self.m.REQUEST.cookies[tokenkey] = token
- self.m.setTokenKeyNamespaces({1:'cookies', 2:'form'})
- a = self.m.getToken()
- assert self.m.isTokenFromCookie()
-
- def testIsTokenFromFormFirst(self):
- token = self.m.getToken()
- self.m.REQUEST.browser_token_ = token
- self.m.REQUEST.browser_token_ns_ = 'form'
- tokenkey = self.m.getTokenKey()
+ self.m.setBrowserIdNamespaces({1:'cookies', 2:'form'})
+ a = self.m.getBrowserId()
+ assert self.m.isBrowserIdFromCookie()
+
+ def testIsBrowserIdFromFormFirst(self):
+ token = self.m.getBrowserId()
+ self.m.REQUEST.browser_id_ = token
+ self.m.REQUEST.browser_id_ns_ = 'form'
+ tokenkey = self.m.getBrowserIdName()
self.m.REQUEST.form[tokenkey] = token
- self.m.setTokenKeyNamespaces({1:'form', 2:'cookies'})
- a = self.m.getToken()
- assert self.m.isTokenFromForm()
+ self.m.setBrowserIdNamespaces({1:'form', 2:'cookies'})
+ a = self.m.getBrowserId()
+ assert self.m.isBrowserIdFromForm()
def testIsTokenFromCookieOnly(self):
- token = self.m.getToken()
- self.m.REQUEST.browser_token_ = token
- self.m.REQUEST.browser_token_ns_ = 'cookies'
- tokenkey = self.m.getTokenKey()
- self.m.REQUEST.cookies[tokenkey] = token
- self.m.setTokenKeyNamespaces({1:'cookies'})
- a = self.m.getToken()
- assert self.m.isTokenFromCookie()
- assert not self.m.isTokenFromForm()
-
+ token = self.m.getBrowserId()
+ self.m.REQUEST.browser_id_ = token
+ self.m.REQUEST.browser_id_ns_ = 'cookies'
+ tokenkey = self.m.getBrowserIdName()
+ self.m.REQUEST.form[tokenkey] = token
+ self.m.setBrowserIdNamespaces({1:'cookies'})
+ a = self.m.getBrowserId()
+ assert self.m.isBrowserIdFromCookie()
+ assert not self.m.isBrowserIdFromForm()
+
def testIsTokenFromFormOnly(self):
- token = self.m.getToken()
- self.m.REQUEST.browser_token_ = token
- self.m.REQUEST.browser_token_ns_ = 'form'
- tokenkey = self.m.getTokenKey()
+ token = self.m.getBrowserId()
+ self.m.REQUEST.browser_id_ = token
+ self.m.REQUEST.browser_id_ns_ = 'form'
+ tokenkey = self.m.getBrowserIdName()
self.m.REQUEST.form[tokenkey] = token
- self.m.setTokenKeyNamespaces({1:'form'})
- a = self.m.getToken()
- assert self.m.isTokenFromForm()
- assert not self.m.isTokenFromCookie()
+ self.m.setBrowserIdNamespaces({1:'form'})
+ a = self.m.getBrowserId()
+ assert not self.m.isBrowserIdFromCookie()
+ assert self.m.isBrowserIdFromForm()
def testFlushTokenCookie(self):
- token = self.m.getToken()
- self.m.REQUEST.browser_token_ = token
- self.m.REQUEST.browser_token_ns_ = 'cookies'
- tokenkey = self.m.getTokenKey()
+ token = self.m.getBrowserId()
+ self.m.REQUEST.browser_id_ = token
+ self.m.REQUEST.browser_id_ns_ = 'cookies'
+ tokenkey = self.m.getBrowserIdName()
self.m.REQUEST.cookies[tokenkey] = token
- a = self.m.getToken()
+ a = self.m.getBrowserId()
assert a == token, repr(a)
- assert self.m.isTokenFromCookie()
- self.m.flushTokenCookie()
+ assert self.m.isBrowserIdFromCookie()
+ self.m.flushBrowserIdCookie()
c = self.m.REQUEST.RESPONSE.cookies[tokenkey]
assert c['value'] == 'deleted', c
- def testDelegateToParentFail(self):
- self.m.turnOff()
- try:
- self.m.getToken()
- except BrowserIdManagerErr:
- pass
- else:
- assert 1==2
-
- def testDelegateToParentSucceed(self):
- self.m.turnOff()
- class foo:
- pass
- class bar:
- def getToken(unself, create=1):
- return 'worked'
- fooi = foo()
- bari = bar()
- setattr(fooi, self.m.id, bari)
- self.m.aq_parent = fooi
- assert self.m.getToken() == 'worked'
-
def testEncodeUrl(self):
- keystring = self.m.getTokenKey()
- key = self.m.getToken()
+ keystring = self.m.getBrowserIdName()
+ key = self.m.getBrowserId()
u = '/home/chrism/foo'
r = self.m.encodeUrl(u)
assert r == '%s?%s=%s' % (u, keystring, key)
u = 'http://www.zope.org/Members/mcdonc?foo=bar&spam=eggs'
r = self.m.encodeUrl(u)
assert r == '%s&%s=%s' % (u, keystring, key)
-
def test_suite():
testsuite = makeSuite(TestBrowserIdManager, 'test')
=== Zope/lib/python/Products/Sessions/tests/testSessionDataManager.py 1.5 => 1.6 ===
assert hasattr(sd, '_invalid')
- def testSessionTokenIsSet(self):
+ def testBrowserIdIsSet(self):
sd = self.app.session_data_manager.getSessionData()
mgr = getattr(self.app, idmgr_name)
- assert mgr.hasToken()
+ assert mgr.hasBrowserId()
def testGetSessionDataByKey(self):
sd = self.app.session_data_manager.getSessionData()
mgr = getattr(self.app, idmgr_name)
- token = mgr.getToken()
+ token = mgr.getBrowserId()
bykeysd = self.app.session_data_manager.getSessionDataByKey(token)
assert sd == bykeysd, (sd, bykeysd, token)
@@ -324,8 +324,8 @@
self.conn = db.open()
self.app = self.conn.root()['Application']
self.app = makerequest.makerequest(self.app)
- token = self.app.browser_id_manager._getNewToken()
- self.app.REQUEST.session_token_ = token
+ token = self.app.browser_id_manager._getNewBrowserId()
+ self.app.REQUEST.browser_id_ = token
self.iters = iters
self.sdm_name = sdm_name
self.out = []