| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -23,3 +23,19 @@ List deployments for a project:: | |||
| 23 | 23 | Get a single deployment:: | |
| 24 | 24 | ||
| 25 | 25 | deployment = project.deployments.get(deployment_id) | |
| 26 | + | ||
| 27 | + Create a new deployment:: | ||
| 28 | + | ||
| 29 | + deployment = project.deployments.create({ | ||
| 30 | + "environment": "Test", | ||
| 31 | + "sha": "1agf4gs", | ||
| 32 | + "ref": "master", | ||
| 33 | + "tag": False, | ||
| 34 | + "status": "created", | ||
| 35 | + }) | ||
| 36 | + | ||
| 37 | + Update a deployment:: | ||
| 38 | + | ||
| 39 | + deployment = project.deployments.get(42) | ||
| 40 | + deployment.status = "failed" | ||
| 41 | + deployment.save() | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -651,6 +651,50 @@ def resp_mark_all_as_done(url, request): | |||
| 651 | 651 | with HTTMock(resp_mark_all_as_done): | |
| 652 | 652 | self.gl.todos.mark_all_as_done() | |
| 653 | 653 | ||
| 654 | + def test_deployment(self): | ||
| 655 | + content = '{"id": 42, "status": "success", "ref": "master"}' | ||
| 656 | + json_content = json.loads(content) | ||
| 657 | + | ||
| 658 | + @urlmatch( | ||
| 659 | + scheme="http", | ||
| 660 | + netloc="localhost", | ||
| 661 | + path="/api/v4/projects/1/deployments", | ||
| 662 | + method="post", | ||
| 663 | + ) | ||
| 664 | + def resp_deployment_create(url, request): | ||
| 665 | + headers = {"content-type": "application/json"} | ||
| 666 | + return response(200, json_content, headers, None, 5, request) | ||
| 667 | + | ||
| 668 | + @urlmatch( | ||
| 669 | + scheme="http", | ||
| 670 | + netloc="localhost", | ||
| 671 | + path="/api/v4/projects/1/deployments/42", | ||
| 672 | + method="put", | ||
| 673 | + ) | ||
| 674 | + def resp_deployment_update(url, request): | ||
| 675 | + headers = {"content-type": "application/json"} | ||
| 676 | + return response(200, json_content, headers, None, 5, request) | ||
| 677 | + | ||
| 678 | + with HTTMock(resp_deployment_create): | ||
| 679 | + deployment = self.gl.projects.get(1, lazy=True).deployments.create( | ||
| 680 | + { | ||
| 681 | + "environment": "Test", | ||
| 682 | + "sha": "1agf4gs", | ||
| 683 | + "ref": "master", | ||
| 684 | + "tag": False, | ||
| 685 | + "status": "created", | ||
| 686 | + } | ||
| 687 | + ) | ||
| 688 | + self.assertEqual(deployment.id, 42) | ||
| 689 | + self.assertEqual(deployment.status, "success") | ||
| 690 | + self.assertEqual(deployment.ref, "master") | ||
| 691 | + | ||
| 692 | + with HTTMock(resp_deployment_update): | ||
| 693 | + json_content["status"] = "failed" | ||
| 694 | + deployment.status = "failed" | ||
| 695 | + deployment.save() | ||
| 696 | + self.assertEqual(deployment.status, "failed") | ||
| 697 | + | ||
| 654 | 698 | def test_update_submodule(self): | |
| 655 | 699 | @urlmatch( | |
| 656 | 700 | scheme="http", netloc="localhost", path="/api/v4/projects/1$", method="get" | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -3735,15 +3735,16 @@ def set_approvers(self, approver_ids=None, approver_group_ids=None, **kwargs): | |||
| 3735 | 3735 | self.gitlab.http_put(path, post_data=data, **kwargs) | |
| 3736 | 3736 | ||
| 3737 | 3737 | ||
| 3738 | - class ProjectDeployment(RESTObject): | ||
| 3738 | + class ProjectDeployment(RESTObject, SaveMixin): | ||
| 3739 | 3739 | pass | |
| 3740 | 3740 | ||
| 3741 | 3741 | ||
| 3742 | - class ProjectDeploymentManager(RetrieveMixin, RESTManager): | ||
| 3742 | + class ProjectDeploymentManager(RetrieveMixin, CreateMixin, UpdateMixin, RESTManager): | ||
| 3743 | 3743 | _path = "/projects/%(project_id)s/deployments" | |
| 3744 | 3744 | _obj_cls = ProjectDeployment | |
| 3745 | 3745 | _from_parent_attrs = {"project_id": "id"} | |
| 3746 | 3746 | _list_filters = ("order_by", "sort") | |
| 3747 | + _create_attrs = (("sha", "ref", "tag", "status", "environment"), tuple()) | ||
| 3747 | 3748 | ||
| 3748 | 3749 | ||
| 3749 | 3750 | class ProjectProtectedBranch(ObjectDeleteMixin, RESTObject): | |
| Back | FazBrowse Home | New Git URL |
0 commit comments