Back to index

plone3  3.1.7
testLoggedIn.py
Go to the documentation of this file.
00001 #
00002 # logged_in.cpy tests
00003 #
00004 
00005 from Products.CMFPlone.tests import PloneTestCase
00006 
00007 from Products.CMFCore.permissions import SetOwnProperties
00008 from DateTime import DateTime
00009 from time import sleep
00010 
00011 
00012 class TestLogin(PloneTestCase.PloneTestCase):
00013 
00014     def afterSetUp(self):
00015         self.membership = self.portal.portal_membership
00016         self.membership.addMember('member', 'secret', ['Member'], [])
00017         self.login('member')
00018 
00019     def testLoggedInCreatesMemberArea(self):
00020         if self.membership.memberareaCreationFlag == 'True':
00021             self.assertEqual(self.membership.getHomeFolder(), None) 
00022             self.portal.logged_in()
00023             self.failIfEqual(self.membership.getHomeFolder(), None)
00024 
00025     def testLoggedInSetsLoginTime(self):
00026         now = DateTime()
00027         member = self.membership.getAuthenticatedMember()
00028         self.failUnless(DateTime(member.getProperty('login_time')) < now)
00029         self.portal.logged_in()
00030         member = self.membership.getAuthenticatedMember()
00031         self.failUnless(DateTime(member.getProperty('login_time')) >= now)
00032 
00033     def testLoggedInSetsLastLoginTime(self):
00034         now = DateTime()
00035         member = self.membership.getAuthenticatedMember()
00036         self.failUnless(DateTime(member.getProperty('last_login_time')) < now)
00037         self.portal.logged_in()
00038         member = self.membership.getAuthenticatedMember()
00039         self.failUnless(DateTime(member.getProperty('last_login_time')) >= now)
00040 
00041     def testLoggedInSetsLastLoginTimeIfMemberLacksSetOwnPropertiesPermission(self):
00042         # If members lack the "Set own properties" permission, they should still
00043         # be able to log in, and their login times should be set.
00044         now = DateTime()
00045         self.portal.manage_permission(SetOwnProperties, ['Manager'], acquire=0)
00046         self.portal.logged_in()
00047         member = self.membership.getAuthenticatedMember()
00048         self.failUnless(DateTime(member.getProperty('last_login_time')) >= now)
00049 
00050     def testInitialLoginTimeDoesChange(self):
00051         member = self.membership.getAuthenticatedMember()
00052         self.portal.logged_in()
00053         member = self.membership.getAuthenticatedMember()
00054         login_time = DateTime(member.getProperty('login_time'))
00055         # Log in again later
00056         sleep(0.2)
00057         self.portal.logged_in()
00058         # login_time did change
00059         member = self.membership.getAuthenticatedMember()
00060         self.failUnless(DateTime(member.getProperty('login_time')) > login_time)
00061 
00062 
00063 def test_suite():
00064     from unittest import TestSuite, makeSuite
00065     suite = TestSuite()
00066     suite.addTest(makeSuite(TestLogin))
00067     return suite