Skip to content

Commit 0389e66

Browse files
authored
Merge pull request #865 from orf/retrieve-environment
feat: add methods to retrieve an individual project environment
2 parents 99a9415 + 29de40e commit 0389e66

File tree

3 files changed

+35
-1
lines changed

3 files changed

+35
-1
lines changed

docs/gl_objects/environments.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@ Create an environment for a project::
2424

2525
environment = project.environments.create({'name': 'production'})
2626

27+
Retrieve a specific environment for a project::
28+
29+
environment = project.environments.get(112)
30+
2731
Update an environment for a project::
2832

2933
environment.external_url = 'http://foo.bar.com'

gitlab/tests/test_gitlab.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -556,6 +556,36 @@ def resp_get_project(url, request):
556556
self.assertEqual(data.name, "name")
557557
self.assertEqual(data.id, 1)
558558

559+
def test_project_environments(self):
560+
@urlmatch(
561+
scheme="http", netloc="localhost", path="/api/v4/projects/1$", method="get"
562+
)
563+
def resp_get_project(url, request):
564+
headers = {"content-type": "application/json"}
565+
content = '{"name": "name", "id": 1}'.encode("utf-8")
566+
return response(200, content, headers, None, 5, request)
567+
568+
@urlmatch(
569+
scheme="http",
570+
netloc="localhost",
571+
path="/api/v4/projects/1/environments/1",
572+
method="get",
573+
)
574+
def resp_get_environment(url, request):
575+
headers = {"content-type": "application/json"}
576+
content = '{"name": "environment_name", "id": 1, "last_deployment": "sometime"}'.encode(
577+
"utf-8"
578+
)
579+
return response(200, content, headers, None, 5, request)
580+
581+
with HTTMock(resp_get_project, resp_get_environment):
582+
project = self.gl.projects.get(1)
583+
environment = project.environments.get(1)
584+
self.assertIsInstance(environment, ProjectEnvironment)
585+
self.assertEqual(environment.id, 1)
586+
self.assertEqual(environment.last_deployment, "sometime")
587+
self.assertEqual(environment.name, "environment_name")
588+
559589
def test_groups(self):
560590
@urlmatch(
561591
scheme="http", netloc="localhost", path="/api/v4/groups/1", method="get"

gitlab/v4/objects.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1944,7 +1944,7 @@ def stop(self, **kwargs):
19441944

19451945

19461946
class ProjectEnvironmentManager(
1947-
ListMixin, CreateMixin, UpdateMixin, DeleteMixin, RESTManager
1947+
RetrieveMixin, CreateMixin, UpdateMixin, DeleteMixin, RESTManager
19481948
):
19491949
_path = "/projects/%(project_id)s/environments"
19501950
_obj_cls = ProjectEnvironment

0 commit comments

Comments
 (0)