def test_unique_id(self, _1): """Each AppSession should have a unique ID""" file_mgr = MagicMock(spec=UploadedFileManager) lsw = MagicMock() rs1 = AppSession(None, SessionData("", ""), file_mgr, None, lsw) rs2 = AppSession(None, SessionData("", ""), file_mgr, None, lsw) self.assertNotEqual(rs1.id, rs2.id)
def test_clear_cache_resets_session_state(self, _1): rs = AppSession( None, SessionData("", ""), UploadedFileManager(), None, MagicMock() ) rs._session_state["foo"] = "bar" rs.handle_clear_cache_request() self.assertTrue("foo" not in rs._session_state)
def test_shutdown(self, _, patched_disconnect): """Test that AppSession.shutdown behaves sanely.""" file_mgr = MagicMock(spec=UploadedFileManager) rs = AppSession(None, SessionData("", ""), file_mgr, None, MagicMock()) rs.shutdown() self.assertEqual(AppSessionState.SHUTDOWN_REQUESTED, rs._state) file_mgr.remove_session_files.assert_called_once_with(rs.id) patched_disconnect.assert_called_once_with(rs._on_secrets_file_changed) # A 2nd shutdown call should have no effect. rs.shutdown() self.assertEqual(AppSessionState.SHUTDOWN_REQUESTED, rs._state) file_mgr.remove_session_files.assert_called_once_with(rs.id)
def test_creates_session_state_on_init(self, _): rs = AppSession( None, SessionData("", ""), UploadedFileManager(), None, MagicMock() ) self.assertTrue(isinstance(rs.session_state, SessionState))