Example #1
0
 def _request(self, path, ok_status, data=None, headers=None, method=None):
     try:
         return Response._from_request(self.server.request(
             self._join_path(path),
             data=data,
             headers=headers,
             method=method,
         ),
                                       ok_status=ok_status)
     except HTTPError as exc:
         return Response._from_http_error(exc)
Example #2
0
 def _request(self, path, ok_status, data=None, headers=None):
     try:
         return Response._from_request(
             self.server.request(
                 self._join_path(path),
                 data=data,
                 headers=headers
             ),
             ok_status=ok_status
         )
     except HTTPError as exc:
         return Response._from_http_error(exc)
Example #3
0
    def _pipeline(self, result='Unknown', job_state='Scheduled', scheduled_minutes_back=20):
        scheduled_date = time.time() - (60 * (scheduled_minutes_back or 20))

        return Response._from_json({
            'stages': [
                {
                    'scheduled': True,
                    'jobs': [
                        {
                            'id': 1,
                            'state': job_state,
                            'result': result,
                            'scheduled_date': scheduled_date * 1000,
                            'name': 'defaultJob'
                        }
                    ],
                    'name': 'defaultStage',
                    'can_run': False,
                    'operate_permission': True,
                    'approval_type': 'success',
                    'counter': '1',
                    'approved_by': 'changes',
                    'result': result,
                    'rerun_of_counter': None,
                    'id': 1
                }
            ],
            'result': result
        })
Example #4
0
    def test_normal_content_type(self):
        response = Response(
            status_code=200,
            body='hello',
            headers={'content-type': 'application/json; charset=utf8'})

        assert response.content_type == 'application/json'
Example #5
0
    def _retrigger(self, response):
        self._unlock()

        if self.retrigger_type == 'pipeline':
            return self.pipeline.trigger()
        else:
            self.pipeline.server.add_logged_in_session(response)
            return Response._from_request(
                self.pipeline.server.post(
                    'go/run/{pipeline}/{counter}/{stage}'.format(
                        pipeline=self.pipeline.name,
                        counter=self.counter,
                        stage=self.stage,
                    ), ))
    def _retrigger(self, response):
        self._unlock()

        if self.retrigger_type == 'pipeline':
            return self.pipeline.trigger()
        else:
            self.pipeline.server.add_logged_in_session(response)
            return Response._from_request(self.pipeline.server.post(
                'go/run/{pipeline}/{counter}/{stage}'.format(
                    pipeline=self.pipeline.name,
                    counter=self.counter,
                    stage=self.stage,
                ),
            ))
Example #7
0
    def _pipeline(self,
                  result='Unknown',
                  job_state='Scheduled',
                  scheduled_minutes_back=20):
        scheduled_date = time.time() - (60 * (scheduled_minutes_back or 20))

        return Response._from_json({
            'stages': [{
                'scheduled':
                True,
                'jobs': [{
                    'id': 1,
                    'state': job_state,
                    'result': result,
                    'scheduled_date': scheduled_date * 1000,
                    'name': 'defaultJob'
                }],
                'name':
                'defaultStage',
                'can_run':
                False,
                'operate_permission':
                True,
                'approval_type':
                'success',
                'counter':
                '1',
                'approved_by':
                'changes',
                'result':
                result,
                'rerun_of_counter':
                None,
                'id':
                1
            }],
            'result':
            result
        })
Example #8
0
    def instance(self, counter=None):
        """Returns all the information regarding a specific pipeline run

        See the `Go pipeline instance documentation`__ for examples.

        .. __: http://api.go.cd/current/#get-pipeline-instance

        Args:
          counter (int): The pipeline instance to fetch.
            If falsey returns the latest pipeline instance from :meth:`history`.

        Returns:
          Response: :class:`gocd.api.response.Response` object
        """
        if not counter:
            history = self.history()
            if not history:
                return history
            else:
                return Response._from_json(history['pipelines'][0])

        return self._get('/instance/{counter:d}'.format(counter=counter))
Example #9
0
    def instance(self, counter=None):
        """Returns all the information regarding a specific pipeline run

        See the `Go pipeline instance documentation`__ for examples.

        .. __: http://api.go.cd/current/#get-pipeline-instance

        Args:
          counter (int): The pipeline instance to fetch.
            If falsey returns the latest pipeline instance from :meth:`history`.

        Returns:
          Response: :class:`gocd.api.response.Response` object
        """
        if not counter:
            history = self.history()
            if not history:
                return history
            else:
                return Response._from_json(history['pipelines'][0])

        return self._get('/instance/{counter:d}'.format(counter=counter))
Example #10
0
    def test_no_instances_of_pipeline_run_yet_and_ran_after_is_set(self):
        cmd = self._check('Never-Run',
                          Response._from_json({}),
                          ran_after='18:00')

        self._assert_critical_run_after(cmd)
Example #11
0
    def test_no_instances_of_pipeline_run_yet_and_ran_after_is_none(self):
        cmd = self._check('Never-Run', Response._from_json({}))

        assert cmd.run()['output'].startswith('OK: No scheduled runs')
Example #12
0
    def test_no_instances_of_pipeline_run_yet_and_ran_after_is_set(self):
        cmd = self._check('Never-Run', Response._from_json({}), ran_after='18:00')

        self._assert_critical_run_after(cmd)
Example #13
0
    def test_no_instances_of_pipeline_run_yet_and_ran_after_is_none(self):
        cmd = self._check('Never-Run', Response._from_json({}))

        assert cmd.run()['output'].startswith('OK: No scheduled runs')
Example #14
0
    def test_no_content_type(self):
        response = Response(status_code=200, body='hello', headers={})

        assert not response.content_type