Ejemplo n.º 1
0
    def test_get_job_statuses(self):
        job = JobStatusConfig(id=1,
                              uuid=uuid.uuid4().hex,
                              job=1,
                              created_at=datetime.datetime.now(),
                              status='Running').to_dict()
        httpretty.register_uri(httpretty.GET,
                               BaseApiHandler.build_url(
                                   self.api_config.base_url, '/', 'username',
                                   'project_name', 'jobs', 1, 'statuses'),
                               body=json.dumps({
                                   'results': [job],
                                   'count': 1,
                                   'next': None
                               }),
                               content_type='application/json',
                               status=200)

        # Schema response
        response = self.api_handler.get_statuses('username', 'project_name', 1)
        assert len(response['results']) == 1
        assert isinstance(response['results'][0], JobStatusConfig)

        # Raw response
        self.set_raw_response()
        response = self.api_handler.get_statuses('username', 'project_name', 1)
        assert len(response['results']) == 1
        assert isinstance(response['results'][0], Mapping)
Ejemplo n.º 2
0
    def test_create_job_status(self):
        job = JobStatusConfig(id=1,
                              uuid=uuid.uuid4().hex,
                              job=1,
                              created_at=datetime.datetime.now(),
                              status='Running').to_dict()
        httpretty.register_uri(httpretty.POST,
                               BaseApiHandler.build_url(
                                   self.api_config.base_url, '/', 'username',
                                   'project_name', 'jobs', 1, 'statuses'),
                               body=json.dumps(job),
                               content_type='application/json',
                               status=200)

        # Schema response
        response = self.api_handler.create_status('username',
                                                  'project_name',
                                                  1,
                                                  status='running')
        assert response.to_dict() == job

        # Raw response
        self.set_raw_response()
        response = self.api_handler.create_status('username',
                                                  'project_name',
                                                  1,
                                                  traceback='traceback',
                                                  status='failed')
        assert response == job

        # Async
        self.assert_async_call(api_handler_call=lambda: self.api_handler.
                               create_status('username',
                                             'project_name',
                                             1,
                                             traceback='traceback',
                                             status='running',
                                             background=True),
                               method='post')