Ticket #1652: patch.diff

File patch.diff, 2.9 kB (added by mschw, 7 months ago)
  • turbogears/identity/tests/test_visit.py

    old new  
    2727        cherrypy.root = VisitRoot() 
    2828 
    2929    def tearDown(self): 
     30        turbogears.startup.stopTurboGears() 
    3031        turbogears.config.update({'visit.timeout': self._visit_timeout}) 
    3132        turbogears.config.update({'visit.on': self._visit_on}) 
    3233 
     
    3839        # the following command shuts down the visit framework properly 
    3940        # the test still passes without it, but exceptions are thrown later 
    4041        # once nose wants to quit. 
    41         turbogears.startup.stopTurboGears() 
    4242 
    4343    def test_new_visit(self): 
    4444        "Test that we can see a new visit on the server." 
    4545        testutil.create_request("/") 
    4646        assert turbogears.visit.current().is_new 
    47         turbogears.startup.stopTurboGears() 
    4847 
    4948    def test_old_visit(self): 
    5049        "Test if we can track a visitor over time." 
     
    5352        morsel = cherrypy.response.simple_cookie[self.cookie_name] 
    5453        testutil.create_request("/", headers=cookie_header(morsel)) 
    5554        assert not turbogears.visit.current().is_new 
    56         turbogears.startup.stopTurboGears() 
    5755 
    5856    def test_cookie_expires(self): 
    5957        "Test if the visit timeout mechanism works." 
     
    6765            'cookie values should not match' 
    6866        assert turbogears.visit.current().is_new, \ 
    6967            'this should be a new visit, as the cookie has expired' 
    70         turbogears.startup.stopTurboGears() 
     68 
     69    def test_cookie_re_sent(self): 
     70        "Test whether the visit cookie is re-sent with new expiry time." 
     71        testutil.create_request('/') 
     72        morsel = cherrypy.response.simple_cookie[self.cookie_name] 
     73        exp1 = time.strptime(morsel['expires'], '%a, %d-%b-%Y %H:%M:%S GMT') 
     74        # sleep one second to ensure that we get a new expiry time. 
     75        time.sleep(1) 
     76        headers = {'Cookie': morsel.output(header='')[1:]} 
     77        testutil.create_request('/', headers=headers) 
     78        assert self.cookie_name in cherrypy.response.simple_cookie 
     79        morsel = cherrypy.response.simple_cookie[self.cookie_name] 
     80        exp2 = time.strptime(morsel['expires'], '%a, %d-%b-%Y %H:%M:%S GMT') 
     81        assert exp1 < exp2 
  • turbogears/visit/api.py

    old new  
    229229            if not visit: 
    230230                visit_key = self._generate_key() 
    231231                visit = _manager.new_visit_with_key(visit_key) 
    232                 self.send_cookie(visit_key) 
    233232 
     233            self.send_cookie(visit_key) 
     234 
    234235            set_current(visit) 
    235236 
    236237        # Inform all the plugins that a request has been made for the current