def test_repr(self): s = SessionMixin() s.expiry_date = 10 s.session_id = 42 s.promoted = 1 self.assertTrue(str(s.expiry_date) in repr(s)) self.assertTrue(str(s.session_id) in repr(s)) self.assertTrue(str(s.expiry_date) in repr(s))
def test_is_alive_correctly_handles_expiration(self): time = TimeMock(0) s = SessionMixin(expiry=42, time_module=time) self.assertTrue(s.is_alive()) s = SessionMixin(expiry=42, time_module=time) time.set(43) self.assertFalse(s.is_alive())
def test_promote(self): time = TimeMock(42) s = SessionMixin(expiry=10, time_module=time) s.promote() self.assertEquals(s.expiry_date, 52)
def test_repr_with_unpromoted_session(self): s = SessionMixin() s.promoted = None self.assertTrue('0' in repr(s))
def session_factory(expiry): time = TimeMock(0) return SessionMixin(expiry=expiry, time_module=time)
def test_creation_with_expiry_arg_also_sets_expiry_date(self): s = SessionMixin(expiry=42) self.assertTrue(s.expiry_date is not None)
def test_creation_with_no_sid_sets_a_random_one(self): s = SessionMixin() self.assertTrue(s.session_id is not None)
def test_repr_with_no_expiry_date(self): s = SessionMixin() self.assertTrue('-1' in repr(s))