def test_sends_correct_request_and_returns_when_resource_is_finished(self):
        self.conn.send_get_request.return_value = self.status_with(
            {'finished': True})
        a = Analysis('ID', self.conn)

        a.wait_until_finished()

        self.assert_get_request_was_sent_with('/ID/status')
    def test_sends_correct_request_and_returns_when_resource_is_finished(self):
        self.conn.send_get_request.return_value = self.status_with({
            'finished': True
        })
        a = Analysis('ID', self.conn)

        a.wait_until_finished()

        self.assert_get_request_was_sent_with('/ID/status')
    def test_does_not_raise_exception_when_on_failure_is_none(self):
        self.conn.send_get_request.return_value = self.status_with({
            'finished': True,
            'failed': True,
            'error': 'error message'
        })
        a = Analysis('ID', self.conn)

        a.wait_until_finished(on_failure=None)
    def test_does_not_raise_exception_when_on_failure_is_none(self):
        self.conn.send_get_request.return_value = self.status_with({
            'finished': True,
            'failed': True,
            'error': 'error message'
        })
        a = Analysis('ID', self.conn)

        a.wait_until_finished(on_failure=None)
    def test_raises_exception_by_default_when_resource_failed(self):
        self.conn.send_get_request.return_value = self.status_with({
            'finished': True,
            'failed': True,
            'error': 'error message'
        })
        a = Analysis('ID', self.conn)

        with self.assertRaises(AnalysisFailedError):
            a.wait_until_finished()
    def test_raises_exception_by_default_when_resource_failed(self):
        self.conn.send_get_request.return_value = self.status_with({
            'finished': True,
            'failed': True,
            'error': 'error message'
        })
        a = Analysis('ID', self.conn)

        with self.assertRaises(AnalysisFailedError):
            a.wait_until_finished()
    def test_calls_on_failure_when_it_is_callable(self):
        self.conn.send_get_request.return_value = self.status_with({
            'finished': True,
            'succeeded': False,
            'failed': True,
            'error': 'error message'
        })
        a = Analysis('ID', self.conn)
        on_failure = mock.Mock()

        a.wait_until_finished(on_failure=on_failure)

        on_failure.assert_called_once_with('error message')
    def test_waits_until_analysis_finishes(self):
        self.conn.send_get_request.side_effect = [
            self.status_with({
                'finished': False,
                'succeeded': False
            }), self.status_with({
                'finished': True,
                'succeeded': True
            })
        ]
        a = Analysis('ID', self.conn)

        a.wait_until_finished()
    def test_calls_on_failure_when_it_is_callable(self):
        self.conn.send_get_request.return_value = self.status_with({
            'finished': True,
            'succeeded': False,
            'failed': True,
            'error': 'error message'
        })
        a = Analysis('ID', self.conn)
        on_failure = mock.Mock()

        a.wait_until_finished(on_failure=on_failure)

        on_failure.assert_called_once_with('error message')
    def test_waits_until_analysis_finishes(self):
        self.conn.send_get_request.side_effect = [
            self.status_with({
                'finished': False,
                'succeeded': False
            }), self.status_with({
                'finished': True,
                'succeeded': True
            })
        ]
        a = Analysis('ID', self.conn)

        a.wait_until_finished()