Exemple #1
0
    def test_wait_for_check_prerequisite_nominal(self):
        resource_manager = base.ServiceResource(mock.Mock())

        with mock.patch.object(resource_manager, 'check_prerequisite') as m:
            m.side_effect = [False, False, True]
            resource_manager.wait_for_check_prerequisite(
                mock.Mock(is_set=mock.Mock(return_value=False)))

        self.assertEqual(3, m.call_count)
Exemple #2
0
    def test_should_delete(self):
        creds_manager = mock.Mock()
        resource_manager = base.ServiceResource(creds_manager)

        resource = mock.Mock(get=mock.Mock(side_effect=[None, None]))
        self.assertEqual(True, resource_manager.should_delete(resource))
        resource.get.call_args = [mock.call('project_id'),
                                  mock.call('tenant_id')]

        resource.get.side_effect = ["Foo", "Bar"]
        self.assertEqual(False, resource_manager.should_delete(resource))

        resource.get.side_effect = [42, resource_manager.cleanup_project_id]
        self.assertEqual(True, resource_manager.should_delete(resource))
Exemple #3
0
    def test_instantiate_nominal(self):
        creds_manager = mock.Mock()
        resource_manager = base.ServiceResource(creds_manager)

        self.assertEqual(resource_manager.cloud, creds_manager.cloud)
        self.assertEqual(resource_manager.options, creds_manager.options)
        self.assertEqual(resource_manager.cleanup_project_id,
                         creds_manager.project_id)

        self.assertEqual(12, resource_manager.order())
        self.assertEqual(True, resource_manager.check_prerequisite())

        self.assertRaises(NotImplementedError, resource_manager.delete, '')
        self.assertRaises(NotImplementedError, resource_manager.to_str, '')
        self.assertRaises(NotImplementedError, resource_manager.list)
Exemple #4
0
    def test_wait_for_check_prerequisite_runtimeerror(self,
                                                      mock_check_prerequisite,
                                                      mock_sleep):
        resource_manager = base.ServiceResource(mock.Mock())
        mock_exit = mock.Mock(is_set=mock.Mock(return_value=False))

        with mock.patch('time.time') as mock_time:
            mock_time.side_effect = generate_timeout_series(675)
            self.assertRaisesRegex(
                exceptions.TimeoutError, "^Timeout exceeded .*",
                resource_manager.wait_for_check_prerequisite, mock_exit)
        self.assertEqual(mock_check_prerequisite.call_args_list,
                         [mock.call()] * (2700 // 675 - 1))
        self.assertEqual(mock_sleep.call_args_list,
                         [mock.call(i) for i in (2, 4, 8)])

        mock_sleep.reset_mock()
        mock_check_prerequisite.reset_mock()
        mock_exit.is_set.return_value = True
        self.assertRaisesRegex(RuntimeError,
                               ".* exited because it was interrupted .*",
                               resource_manager.wait_for_check_prerequisite,
                               mock_exit)