How to use the aiounittest.futurized function in aiounittest

To help you get started, we’ve selected a few aiounittest examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github DreamLab / VmShepherd / tests / presets / test_gitrepo_driver.py View on Github external
async def test_reload(self):
        self.mock_os.path.join.side_effect = lambda a, b: (a + b)
        self.driver._clone_or_update = Mock(return_value=futurized(None))
        self.driver._assure_clone_dir_exists = Mock(return_value=True)
        self.driver._load_repo = Mock(return_value=futurized({}))
        await self.driver.list_presets()
        self.driver._load_repo.assert_has_calls([
            mock.call('paas', '/tmp/paas'), mock.call('db', '/tmp/db')
        ])
        self.assertEqual(self.driver._load_repo.call_count, 2)
github DreamLab / AsyncOpenStackClient / tests / test_client.py View on Github external
async def test_get_credentials(self):
        self.mock_sess.get_endpoint_url.return_value = 'http://glance.a2.iaas:9292/v2'

        client = Client('glance', ['some_res'], session=self.mock_sess)

        # this is not a good practice but the simplest one
        client.get_current_version_api_url = mock.Mock(return_value=futurized('http://blah'))

        await client.get_credentials()

        client.get_current_version_api_url.assert_not_called()
        self.mock_sess.get_endpoint_url.assert_called_once_with('glance')
        self.assertEqual(client.api_url, 'http://glance.a2.iaas:9292/v2/')
github DreamLab / VmShepherd / tests / test_rpc_api.py View on Github external
def setUp(self):
        super().setUp()
        mock_request = Mock()
        self.mock_preset_manager = Mock()
        mock_vm_launched_time = time.time()
        self.mock_preset_manager.get_vms.return_value = futurized([
            Vm('1243454353', 'C_DEV-app-dev',
               ['10.177.51.8'], mock_vm_launched_time, state=VmState.RUNNING),
            Vm('4535646466', 'C_DEV-app-dev',
               ['10.177.51.9'], mock_vm_launched_time, state=VmState.RUNNING),
            Vm('5465465643', 'C_DEV-app-dev',
               ['10.177.51.10'], mock_vm_launched_time, state=VmState.RUNNING)
        ])
        self.mock_preset_manager.count = 3
        self.mock_preset_manager.iaas.terminate_vm.return_value = futurized('ok')
        self.mock_preset_manager.iaas.get_vm.return_value = futurized(
            Vm('1243454353', 'C_DEV-app-dev',
               ['10.177.51.8'], mock_vm_launched_time, state=VmState.RUNNING)
        )
        mock_request.app.vmshepherd.preset_manager.get_preset.return_value = self.mock_preset_manager
        mock_request.app.vmshepherd.preset_manager.list_presets.return_value = futurized({"C_DEV-app-dev": []})
        mock_request.remote = ['10.177.51.8']
github DreamLab / AsyncOpenStackClient / tests / test_client.py View on Github external
def setUp(self):
        super().setUp()
        self.mock_sess = mock.Mock()
        self.mock_sess.authenticate.return_value = futurized(None)
        self.mock_sess.token = 'mock_token'
        self.mock_sess.get_endpoint_url.return_value = 'mock_url'
github DreamLab / VmShepherd / tests / presets / test_gitrepo_driver.py View on Github external
async def test_reload(self):
        self.mock_os.path.join.side_effect = lambda a, b: (a + b)
        self.driver._clone_or_update = Mock(return_value=futurized(None))
        self.driver._assure_clone_dir_exists = Mock(return_value=True)
        self.driver._load_repo = Mock(return_value=futurized({}))
        await self.driver.list_presets()
        self.driver._load_repo.assert_has_calls([
            mock.call('paas', '/tmp/paas'), mock.call('db', '/tmp/db')
        ])
        self.assertEqual(self.driver._load_repo.call_count, 2)
github DreamLab / VmShepherd / tests / test_rpc_api.py View on Github external
def setUp(self):
        super().setUp()
        mock_request = Mock()
        self.mock_preset_manager = Mock()
        mock_vm_launched_time = time.time()
        self.mock_preset_manager.get_vms.return_value = futurized([
            Vm('1243454353', 'C_DEV-app-dev',
               ['10.177.51.8'], mock_vm_launched_time, state=VmState.RUNNING),
            Vm('4535646466', 'C_DEV-app-dev',
               ['10.177.51.9'], mock_vm_launched_time, state=VmState.RUNNING),
            Vm('5465465643', 'C_DEV-app-dev',
               ['10.177.51.10'], mock_vm_launched_time, state=VmState.RUNNING)
        ])
        self.mock_preset_manager.count = 3
        self.mock_preset_manager.iaas.terminate_vm.return_value = futurized('ok')
        self.mock_preset_manager.iaas.get_vm.return_value = futurized(
            Vm('1243454353', 'C_DEV-app-dev',
               ['10.177.51.8'], mock_vm_launched_time, state=VmState.RUNNING)
        )
        mock_request.app.vmshepherd.preset_manager.get_preset.return_value = self.mock_preset_manager
        mock_request.app.vmshepherd.preset_manager.list_presets.return_value = futurized({"C_DEV-app-dev": []})
        mock_request.remote = ['10.177.51.8']
        self.rpcapi = RpcApi()
        self.rpcapi._request = mock_request
        self.mock_list_vms = {
            "1243454353": {
                "ip": "10.177.51.8",
                "state": "running",
                "created": datetime.datetime.fromtimestamp(mock_vm_launched_time)
            },
            "4535646466": {
                "ip": "10.177.51.9",
github DreamLab / VmShepherd / tests / test_rpc_api.py View on Github external
def setUp(self):
        super().setUp()
        mock_request = Mock()
        self.mock_preset_manager = Mock()
        mock_vm_launched_time = time.time()
        self.mock_preset_manager.get_vms.return_value = futurized([
            Vm('1243454353', 'C_DEV-app-dev',
               ['10.177.51.8'], mock_vm_launched_time, state=VmState.RUNNING),
            Vm('4535646466', 'C_DEV-app-dev',
               ['10.177.51.9'], mock_vm_launched_time, state=VmState.RUNNING),
            Vm('5465465643', 'C_DEV-app-dev',
               ['10.177.51.10'], mock_vm_launched_time, state=VmState.RUNNING)
        ])
        self.mock_preset_manager.count = 3
        self.mock_preset_manager.iaas.terminate_vm.return_value = futurized('ok')
        self.mock_preset_manager.iaas.get_vm.return_value = futurized(
            Vm('1243454353', 'C_DEV-app-dev',
               ['10.177.51.8'], mock_vm_launched_time, state=VmState.RUNNING)
        )
        mock_request.app.vmshepherd.preset_manager.get_preset.return_value = self.mock_preset_manager
        mock_request.app.vmshepherd.preset_manager.list_presets.return_value = futurized({"C_DEV-app-dev": []})
        mock_request.remote = ['10.177.51.8']
        self.rpcapi = RpcApi()
        self.rpcapi._request = mock_request
        self.mock_list_vms = {
            "1243454353": {
                "ip": "10.177.51.8",
                "state": "running",
                "created": datetime.datetime.fromtimestamp(mock_vm_launched_time)
            },
            "4535646466": {
github kwarunek / aiounittest / tests / test_futurized.py View on Github external
async def test_fail(self):
        mock_sleep = Mock(return_value=futurized(Exception('whatever')))
        patch('dummy_math.sleep', mock_sleep).start()
        with self.assertRaises(Exception) as e:
            await dummy_math.add(5, 6)
        mock_sleep.assert_called_once_with(666)
github DreamLab / VmShepherd / tests / presets / test_gitrepo_driver.py View on Github external
def setUp(self):
        self.mock_runtime = Mock()
        self.patch_os = patch('vmshepherd.presets.gitrepo_driver.os')
        self.mock_os = self.patch_os.start()

        self.mock_process = Mock()
        self.mock_process.communicate.return_value = futurized(('STDOUT', 'STDERR'))
        self.mock_process.returncode = 0
        self.mock_subprocess_exec = patch(
            'vmshepherd.presets.gitrepo_driver.asyncio.create_subprocess_exec',
            return_value=futurized(self.mock_process)
        ).start()

        self.config = {
            'repositories': {
                'paas': 'git://testrepm/paas.git',
                'db': 'git://stash/db.git',
            },
            'clone_dir': '/tmp/'
        }
        self.driver = gitrepo_driver.GitRepoDriver(self.config, self.mock_runtime, example_config['defaults'])
github kwarunek / aiounittest / tests / test_futurized.py View on Github external
async def test_add(self):
        mock_sleep = Mock(return_value=futurized('whatever'))
        patch('dummy_math.sleep', mock_sleep).start()
        ret = await dummy_math.add(5, 6)
        self.assertEqual(ret, 11)
        mock_sleep.assert_called_once_with(666)

aiounittest

Test asyncio code more easily.

MIT
Latest version published 3 years ago

Package Health Score

52 / 100
Full package analysis

Similar packages