# Path: tests/helpers.py
# class BaseTestCase(unittest.TestCase):
#     def shortDescription(self):
#         return None
# 
# class DatabaseMock(Mock):
#     active_sessions = {}
#     endpoints = {}
# 
#     def __init__(self, *args, **kwargs):
#         super(DatabaseMock, self).__init__(*args, **kwargs)
#         self.add = Mock(side_effect=set_primary_key)
# 
#     def get_active_sessions(self, provider_id=None):
#         return self.active_sessions.values()
# 
#     def get_session(self, session_id):
#         return self.active_sessions.get(str(session_id))
# 
#     def get_endpoint(self, endpoint):
#         pass
# 
#     def get_endpoints(self, *args, **kwargs):
#         return self.endpoints.values()
# 
#     @staticmethod
#     def get_last_session_step(session_id):
#         return Mock()
# 
#     def register_provider(self, name, url, platforms):
#         from core.db.models import Provider
#         return Provider(name, url, platforms)
# 
# def wait_for(condition, timeout=10):
#     start = time.time()
#     while not condition() and time.time() - start < timeout:
#         time.sleep(0.1)
# 
#     return condition()


from mock import patch, Mock
from tests.helpers import BaseTestCase, DatabaseMock, wait_for
        from core.config import setup_config
            from vmpool.artifact_collector import ArtifactCollector
# coding: utf-8



class TestVNCVideoHelper(BaseTestCase):
    def setUp(self):
        setup_config('data/config_openstack.py')

    def test_run_recorder(self):
        """
        - call session.run()
        - call session.succeed()

        Expected: vnc_recorder was started and stopped
        """
        with patch(
            'core.video.VNCVideoHelper._flvrec', Mock()
        ), patch(
            'core.video.VNCVideoHelper.start_recording', Mock()
        ) as start_rec_mock, patch(
            'core.video.VNCVideoHelper.stop', Mock()
        ) as stop_rec_mock, patch(
            'core.video.VNCVideoHelper.is_alive', Mock(return_value=True)
        ):

            session = Mock(endpoint=Mock(prefix="ondemand", ip='127.0.0.1'), closed=False)

# Path: tests/helpers.py
# class BaseTestCase(unittest.TestCase):
#     def shortDescription(self):
#         return None
# 
# class DatabaseMock(Mock):
#     active_sessions = {}
#     endpoints = {}
# 
#     def __init__(self, *args, **kwargs):
#         super(DatabaseMock, self).__init__(*args, **kwargs)
#         self.add = Mock(side_effect=set_primary_key)
# 
#     def get_active_sessions(self, provider_id=None):
#         return self.active_sessions.values()
# 
#     def get_session(self, session_id):
#         return self.active_sessions.get(str(session_id))
# 
#     def get_endpoint(self, endpoint):
#         pass
# 
#     def get_endpoints(self, *args, **kwargs):
#         return self.endpoints.values()
# 
#     @staticmethod
#     def get_last_session_step(session_id):
#         return Mock()
# 
#     def register_provider(self, name, url, platforms):
#         from core.db.models import Provider
#         return Provider(name, url, platforms)
# 
# def wait_for(condition, timeout=10):
#     start = time.time()
#     while not condition() and time.time() - start < timeout:
#         time.sleep(0.1)
# 
#     return condition()


# Path: tests/unit/test_vnc_recorder.py
from mock import patch, Mock
from tests.helpers import BaseTestCase, DatabaseMock, wait_for
        from core.config import setup_config
            from vmpool.artifact_collector import ArtifactCollector

# coding: utf-8



class TestVNCVideoHelper(BaseTestCase):
    def setUp(self):
        setup_config('data/config_openstack.py')

    def test_run_recorder(self):
        """
        - call session.run()
        - call session.succeed()

        Expected: vnc_recorder was started and stopped
        """
        with patch(
            'core.video.VNCVideoHelper._flvrec', Mock()
        ), patch(
            'core.video.VNCVideoHelper.start_recording', Mock()
        ) as start_rec_mock, patch(
            'core.video.VNCVideoHelper.stop', Mock()
        ) as stop_rec_mock, patch(
            'core.video.VNCVideoHelper.is_alive', Mock(return_value=True)
        ):

            session = Mock(endpoint=Mock(prefix="ondemand", ip='127.0.0.1'), closed=False)

            artifact_collector = ArtifactCollector(database=DatabaseMock())