예제 #1
0
 def test__poll_task_timeout(self):
     """What happens when a foreman task timesout?
     Assert that the task is still running.
     """
     with self.assertRaises(entity_mixins.TaskTimedOutError):
         with mock.patch.object(client, 'get') as get:
             get.return_value.json.return_value = {'state': 'running', 'result': 'pending'}
             entity_mixins._poll_task(gen_integer(), self.cfg, timeout=1)
예제 #2
0
    def test__poll_task_failure(self):
        """What happens when a foreman task completes but does not succeed?

        Assert that a :class:`nailgun.entity_mixins.TaskFailedError` exception
        is raised.

        """
        for state in ('paused', 'stopped'):
            with self.subTest(state):
                with mock.patch.object(client, 'get') as get:
                    get.return_value.json.return_value = {'state': state, 'result': 'not success'}
                    with self.assertRaises(entity_mixins.TaskFailedError):
                        entity_mixins._poll_task(gen_integer(), self.cfg)
예제 #3
0
    def test__poll_task_failure(self):
        """What happens when a foreman task completes but does not succeed?

        Assert that a :class:`nailgun.entity_mixins.TaskFailedError` exception
        is raised.

        """
        for state in ('paused', 'stopped'):
            with self.subTest(state):
                with mock.patch.object(client, 'get') as get:
                    get.return_value.json.return_value = {
                        'state': state,
                        'result': 'not success'
                    }
                    with self.assertRaises(entity_mixins.TaskFailedError):
                        # pylint:disable=protected-access
                        entity_mixins._poll_task(gen_integer(), self.cfg)
예제 #4
0
    def test__poll_task_failed_task(self):
        """Test what happens when an asynchronous task completes and fails.

        Assert that a :class:`nailgun.entity_mixins.TaskFailedError` exception
        is raised.

        """
        get_return = mock.Mock()
        get_return.json.return_value = {
            'state': 'not running',
            'result': 'not success',
            'humanized': {'errors': 'bogus error'},
        }
        with mock.patch.object(client, 'get') as client_get:
            client_get.return_value = get_return
            with self.assertRaises(entity_mixins.TaskFailedError):
                # pylint:disable=protected-access
                entity_mixins._poll_task(gen_integer(), self.server_config)
예제 #5
0
    def test__poll_task_failed_task(self):
        """Test what happens when an asynchronous task completes and fails.

        Assert that a :class:`nailgun.entity_mixins.TaskFailedError` exception
        is raised.

        """
        get_return = mock.Mock()
        get_return.json.return_value = {
            "state": "not running",
            "result": "not success",
            "humanized": {"errors": "bogus error"},
        }
        with mock.patch.object(client, "get") as client_get:
            client_get.return_value = get_return
            with self.assertRaises(entity_mixins.TaskFailedError):
                # pylint:disable=protected-access
                entity_mixins._poll_task(gen_integer(), config.ServerConfig("bogus url"))
예제 #6
0
    def test__poll_task_success(self):
        """What happens when a foreman task completes and does succeed?

        Assert that the server's response is returned.

        """
        for state in ('paused', 'stopped'):
            with self.subTest(state):
                with mock.patch.object(client, 'get') as get:
                    get.return_value.json.return_value = {'state': state, 'result': 'success'}
                    self.assertEqual(
                        get.return_value.json.return_value,
                        entity_mixins._poll_task(gen_integer(), self.cfg),
                    )
예제 #7
0
    def test__poll_task_success(self):
        """What happens when a foreman task completes and does succeed?

        Assert that the server's response is returned.

        """
        for state in ('paused', 'stopped'):
            with self.subTest(state):
                with mock.patch.object(client, 'get') as get:
                    get.return_value.json.return_value = {
                        'state': state,
                        'result': 'success'
                    }
                    self.assertEqual(
                        get.return_value.json.return_value,
                        # pylint:disable=protected-access
                        entity_mixins._poll_task(gen_integer(), self.cfg),
                    )