Ejemplo n.º 1
0
    def test_api_sessions(self):
        from core.db.models import Session
        session = Session(self.platform, "session1",
                          self.desired_caps["desiredCapabilities"])
        session.created = session.modified = datetime.now()

        with patch('flask.current_app.sessions.active',
                   Mock(return_value=[session])):
            response = self.vmmaster_client.get('/api/sessions')
        body = json.loads(response.data)
        self.assertEqual(200, response.status_code)

        sessions = body['result']['sessions']
        self.assertEqual(1, len(sessions))
        self.assertEqual(self.platform, session.platform)
        self.assertEqual(200, body['metacode'])

        session.failed()
Ejemplo n.º 2
0
    def test_api_stop_session(self):
        from core.db.models import Session
        session = Session("some_platform")
        session.failed = Mock()

        with patch('flask.current_app.sessions.get_session',
                   Mock(return_value=session)):
            response = self.vmmaster_client.get("/api/session/{}/stop".format(
                session.id))
        body = json.loads(response.data)
        self.assertEqual(200, body['metacode'])

        session.failed.assert_any_call(
            reason=constants.SESSION_CLOSE_REASON_API_CALL)