def test_run_recorder(self): """ - call session.run() - call session.delete() Expected: vnc_recorder was started and stopped """ endpoint = Mock(ip='127.0.0.1', name='test_endpoint') dc = {'takeScreencast': True, 'platform': 'test_origin_1'} with patch('core.db.models.Session', Mock()), patch("core.network.Network", Mock()), patch( "core.connection.Virsh", Mock()), patch('core.db.Database', DatabaseMock()): from core.sessions import Session self.session = Session(dc=dc) self.session.name = "session1" with patch('core.video.VNCVideoHelper._flvrec', Mock()), patch('core.video.VNCVideoHelper._flv2webm', Mock()): self.session.run(endpoint=endpoint) self.assertTrue( isinstance(self.session.vnc_helper.recorder, Process)) self.session.close() self.assertTrue( wait_for(lambda: not self.session.vnc_helper.recorder. is_alive()))
def setUp(self): setup_config('data/config.py') self.address = ("localhost", 9001) with patch( 'core.connection.Virsh', Mock(), ), patch('core.network.Network', Mock()), patch('core.db.Database', DatabaseMock()): from vmmaster.server import VMMasterServer self.vmmaster = VMMasterServer(reactor, self.address[1]) self.pool = self.vmmaster.app.pool server_is_up(self.address) self.desired_caps = { 'desiredCapabilities': { 'platform': self.pool.platforms.platforms.keys()[0] } } from core.config import config config.SESSION_TIMEOUT = 1 self.ctx = self.vmmaster.app.app_context() self.ctx.push()
def setUpClass(cls): from core.config import setup_config setup_config('data/config.py') cls.app = Flask(__name__) cls.app.database = DatabaseMock() cls.app.sessions = Mock()
def test_500_code_run_script_during_add_tasks(self): """ - add tasks Expected: selenium log was saved and endpoint was deleted """ from vmpool.artifact_collector import ArtifactCollector with patch("core.network.Network", Mock()), patch("core.connection.Virsh", Mock()), patch('core.db.Database', DatabaseMock()): from core.sessions import Session session = Session(dc={'platform': 'test_origin_1'}) session.id = 1 endpoint = Mock(ip='127.0.0.1', name='test_endpoint', delete=Mock()) session.endpoint = endpoint self.app.database.get_session = Mock(return_value=session) vmpool = Mock(get_by_name=Mock(return_value=endpoint)) vmpool.app = self.app self.app.pool = vmpool art_collector = ArtifactCollector(vmpool) in_queue = art_collector.add_tasks( session.id, {'selenium_server': '/var/log/selenium_server.log'}) self.assertTrue(in_queue) self.assertTrue(wait_for(lambda: not session.selenium_log)) self.assertTrue(wait_for(lambda: len(art_collector.get_queue()) == 0)) self.assertTrue(wait_for(lambda: session.endpoint.delete.called)) art_collector.stop()
def setUp(self): with patch( 'core.connection.Virsh', Mock(), ), patch('core.network.Network', Mock()), patch('core.db.Database', DatabaseMock()), patch( 'core.sessions.SessionWorker', Mock()): from vmmaster.server import VMMasterServer self.vmmaster = VMMasterServer(reactor, self.address[1]) self.pool = self.vmmaster.app.pool server_is_up(self.address)
def test_add_tasks(self): """ - add tasks Expected: selenium log was saved and endpoint was deleted """ from vmpool.artifact_collector import ArtifactCollector with patch("core.network.Network", Mock()), patch("core.connection.Virsh", Mock()), patch('core.db.Database', DatabaseMock()): from core.sessions import Session session = Session(dc={'platform': 'test_origin_1'}) session.id = 1 log_path = os.sep.join([ config.SCREENSHOTS_DIR, str(session.id), 'selenium_server.log' ]) endpoint = Mock(ip='127.0.0.1', name='test_endpoint', delete=Mock(), selenium_port=4455, agent_port=9000, vnc_port=5900) session.endpoint = endpoint self.app.database.get_session = Mock(return_value=session) vmpool = Mock(get_by_name=Mock(return_value=endpoint)) vmpool.app = self.app self.app.pool = vmpool art_collector = ArtifactCollector(vmpool) in_queue = art_collector.add_tasks( session, {'selenium_server': '/var/log/selenium_server.log'}) self.assertTrue(in_queue) self.assertTrue(wait_for(lambda: session.selenium_log == log_path)) with open(session.selenium_log, 'r') as f: text = f.read() self.assertEqual(text, 'test text') self.assertTrue(wait_for(lambda: len(art_collector.get_queue()) == 0)) self.assertTrue(wait_for(lambda: session.endpoint.delete.called)) art_collector.stop()
def setUpClass(cls): setup_config('data/config.py') cls.app = Flask(__name__) cls.app.database = DatabaseMock() cls.app.sessions = Mock()