def test_when_during_proxy_starting_session_was_closed(self): from core.db.models import Session, Endpoint, Provider provider = Provider(name='noname', url='nourl') endpoint = Endpoint(Mock(), '', provider) endpoint.ip = '127.0.0.1' endpoint.name = 'test_endpoint' endpoint.ports = {'4455': 4455, '9000': 9000, '5900': 5900} session = Session("some_platform") session.id = 1 session.name = "session1" session.status = "running" session.closed = True type(session).vnc_proxy_port = PropertyMock( side_effect=[None, 55555, 55555]) session.vnc_proxy_pid = 55555 session.created = session.modified = datetime.now() session.endpoint = endpoint session.stop_vnc_proxy = Mock() with patch('flask.current_app.sessions.get_session', Mock(return_value=session)): response = self.vmmaster_client.get('/api/session/%s/vnc_info' % session.id) body = json.loads(response.data) self.assertEqual(200, response.status_code) self.assertDictEqual({}, body['result']) self.assertEqual(500, body['metacode'])
def test_session_keep_forever(self): user = Mock(id=1, max_stored_sessions=0) from core.db.models import Session session1 = Session(platform='some_platform', name='__test_keep_forever_sessions_1') session1.closed = True session1.keep_forever = True session1.save() session2 = Session(platform='some_platform', name='__test_keep_forever_sessions_2') session2.closed = True session2.keep_forever = False session2.save() session_ids_to_delete = [ p.id for p in self.cleanup.sessions_overflow(user) ] self.assertNotIn(session1.id, session_ids_to_delete) self.assertIn(session2.id, session_ids_to_delete) self.cleanup.delete_session_data([session1, session2])
def test_sessions_overflow(self): user = Mock(id=1, max_stored_sessions=0) from core.db.models import Session session = Session('some_platform') session.status = 'unknown' session.closed = True session.name = '__test_outdated_sessions' session.save() session_ids_to_delete = [ p.id for p in self.cleanup.sessions_overflow(user) ] self.assertIn(session.id, session_ids_to_delete) self.cleanup.delete_session_data([session])