feat(api): add support for latest pipeline · python-gitlab/python-gitlab@e841c81

@@ -39,6 +39,62 @@

3939

"web_url": "https://example.com/foo/bar/pipelines/46",

4040

}

414142+

pipeline_latest = {

43+

"id": 47,

44+

"project_id": 1,

45+

"status": "pending",

46+

"ref": "main",

47+

"sha": "a91957a858320c0e17f3a0eca7cfacbff50ea29a",

48+

"before_sha": "a91957a858320c0e17f3a0eca7cfacbff50ea29a",

49+

"tag": False,

50+

"yaml_errors": None,

51+

"user": {

52+

"name": "Administrator",

53+

"username": "root",

54+

"id": 1,

55+

"state": "active",

56+

"avatar_url": "http://www.gravatar.com/avatar/e64c7d89f26bd1972efa854d13d7dd61?s=80&d=identicon",

57+

"web_url": "http://localhost:3000/root",

58+

},

59+

"created_at": "2016-08-11T11:28:34.085Z",

60+

"updated_at": "2016-08-11T11:32:35.169Z",

61+

"started_at": None,

62+

"finished_at": "2016-08-11T11:32:35.145Z",

63+

"committed_at": None,

64+

"duration": None,

65+

"queued_duration": 0.010,

66+

"coverage": None,

67+

"web_url": "https://example.com/foo/bar/pipelines/46",

68+

}

69+70+

pipeline_latest_other_ref = {

71+

"id": 48,

72+

"project_id": 1,

73+

"status": "pending",

74+

"ref": "feature-ref",

75+

"sha": "a91957a858320c0e17f3a0eca7cfacbff50ea29a",

76+

"before_sha": "a91957a858320c0e17f3a0eca7cfacbff50ea29a",

77+

"tag": False,

78+

"yaml_errors": None,

79+

"user": {

80+

"name": "Administrator",

81+

"username": "root",

82+

"id": 1,

83+

"state": "active",

84+

"avatar_url": "http://www.gravatar.com/avatar/e64c7d89f26bd1972efa854d13d7dd61?s=80&d=identicon",

85+

"web_url": "http://localhost:3000/root",

86+

},

87+

"created_at": "2016-08-11T11:28:34.085Z",

88+

"updated_at": "2016-08-11T11:32:35.169Z",

89+

"started_at": None,

90+

"finished_at": "2016-08-11T11:32:35.145Z",

91+

"committed_at": None,

92+

"duration": None,

93+

"queued_duration": 0.010,

94+

"coverage": None,

95+

"web_url": "https://example.com/foo/bar/pipelines/46",

96+

}

97+42984399

test_report_content = {

44100

"total_time": 5,

@@ -162,10 +218,37 @@ def resp_get_pipeline_test_report_summary():

162218

yield rsps

163219164220221+

@pytest.fixture

222+

def resp_get_latest():

223+

with responses.RequestsMock() as rsps:

224+

rsps.add(

225+

method=responses.GET,

226+

url="http://localhost/api/v4/projects/1/pipelines/latest",

227+

json=pipeline_latest,

228+

content_type="application/json",

229+

status=200,

230+

)

231+

yield rsps

232+233+234+

@pytest.fixture

235+

def resp_get_latest_other_ref():

236+

with responses.RequestsMock() as rsps:

237+

rsps.add(

238+

method=responses.GET,

239+

url="http://localhost/api/v4/projects/1/pipelines/latest",

240+

json=pipeline_latest_other_ref,

241+

content_type="application/json",

242+

status=200,

243+

)

244+

yield rsps

245+246+165247

def test_get_project_pipeline(project, resp_get_pipeline):

166248

pipeline = project.pipelines.get(1)

167249

assert isinstance(pipeline, ProjectPipeline)

168250

assert pipeline.ref == "main"

251+

assert pipeline.id == 46

169252170253171254

def test_cancel_project_pipeline(project, resp_cancel_pipeline):

@@ -198,3 +281,17 @@ def test_get_project_pipeline_test_report_summary(

198281

assert isinstance(test_report_summary, ProjectPipelineTestReportSummary)

199282

assert test_report_summary.total["count"] == 3363

200283

assert test_report_summary.test_suites[0]["name"] == "test"

284+285+286+

def test_latest_pipeline(project, resp_get_latest):

287+

pipeline = project.pipelines.latest()

288+

assert isinstance(pipeline, ProjectPipeline)

289+

assert pipeline.ref == "main"

290+

assert pipeline.id == 47

291+292+293+

def test_latest_pipeline_other_ref(project, resp_get_latest_other_ref):

294+

pipeline = project.pipelines.latest(ref="feature-ref")

295+

assert isinstance(pipeline, ProjectPipeline)

296+

assert pipeline.ref == "feature-ref"

297+

assert pipeline.id == 48