def test_server_create_new_session(self): response = new_session_request(self.address, self.desired_caps) vm_count = len(self.pool.using) self.assertEqual(200, response.status) self.assertEqual(1, vm_count)
def test_always_create_response_for_sub_step(self): """ - exception while executing make_request Expected: session failed, sub_steps was created """ def raise_exception(*args, **kwargs): raise Exception('something ugly happened in make_request') def new_vm_mock(arg): yield Mock(ip=1) with patch('vmpool.endpoint.get_vm', Mock(side_effect=new_vm_mock)), patch( 'core.sessions.Session.make_request', Mock(__name__="make_request", side_effect=raise_exception)), patch( 'core.sessions.Session.add_sub_step', Mock()) as add_sub_step_mock: response = new_session_request(self.address, self.desired_caps) self.assertEqual(500, response.status) self.assertIn('something ugly happened in make_request', response.content) self.assertEqual(add_sub_step_mock.call_count, 2)
def test_max_count_with_run_new_request_during_prevm_is_not_ready(self): """ - do not wait for preloaded vm ready status - make new session request Expected: session created """ response = new_session_request(self.address, self.desired_caps) self.assertEqual(200, response.status) self.assertEqual(1, self.pool.count())
def test_max_count_with_run_new_request_during_prevm_is_ready(self): """ - wait while preloaded is ready - make new session request Expected: session created """ while True: if self.pool.pool[0].ready is True: break response = new_session_request(self.address, self.desired_caps) self.assertEqual(200, response.status) self.assertEqual(1, self.pool.count())
def test_server_create_new_session_with_user_and_token(self): """ - pass user and token via desired capabilities Expected: session created """ _desired_caps = self.desired_caps.copy() _desired_caps["desiredCapabilities"]["user"] = "******" _desired_caps["desiredCapabilities"]["token"] = None response = new_session_request(self.address, _desired_caps) vm_count = len(self.pool.using) self.assertEqual(200, response.status) self.assertEqual(1, vm_count)
def test_check_timer_for_session_activity(self): """ - exception while waiting endpoint Expected: session was created, session_step was created """ def get_vm_mock(arg): yield Mock(name="test_vm_1", ip="127.0.0.1") with patch('vmpool.endpoint.get_vm', Mock(side_effect=get_vm_mock)): response = new_session_request(self.address, self.desired_caps) self.assertEqual(200, response.status) response = get_session_request(self.address, 1) self.assertIn( "SessionException: There is no active session 1 (Unknown session)", response.content)
def test_add_first_two_steps(self): """ - exception while waiting endpoint Expected: session was created, session_step was created """ def raise_exception(dc): raise Exception('something ugly happened in get_vm') with patch('vmpool.endpoint.get_vm', Mock(side_effect=raise_exception)), patch( 'core.sessions.Session.add_session_step', Mock()) as add_step_mock: response = new_session_request(self.address, self.desired_caps) self.assertEqual(500, response.status) self.assertIn('something ugly happened in get_vm', response.content) self.assertEqual(add_step_mock.call_count, 2)
def test_vmmaster_no_such_platform(self): desired_caps = {'desiredCapabilities': {'platform': 'no_platform'}} response = new_session_request(self.address, desired_caps) error = json.loads(response.content).get('value').get('message') self.assertIn('PlatformException: No such platform no_platform', error)