From d703873490e8cbfdcb6de2f5d90f5367174850d1 Mon Sep 17 00:00:00 2001 From: knucklessg1 Date: Tue, 7 May 2024 16:13:38 -0500 Subject: [PATCH] Fixed data json dumping first. --- gitlab_api/gitlab_api.py | 34 +++++++++++++++++++++++----------- test/test_gitlab_api.py | 4 ++-- 2 files changed, 25 insertions(+), 13 deletions(-) diff --git a/gitlab_api/gitlab_api.py b/gitlab_api/gitlab_api.py index 3bb8bca..e688a7a 100644 --- a/gitlab_api/gitlab_api.py +++ b/gitlab_api/gitlab_api.py @@ -278,7 +278,9 @@ def cherry_pick_commit(self, **kwargs): try: response = self._session.post(url=f'{self.url}/projects/{commit.project_id}' f'/repository/commits/{commit.commit_hash}/cherry_pick', - headers=self.headers, data=commit.data, verify=self.verify) + headers=self.headers, + data=json.dumps(commit.data, indent=2), + verify=self.verify) except ValidationError as e: raise ParameterError(f"Invalid parameters: {e.errors()}") return response @@ -301,7 +303,9 @@ def create_commit(self, **kwargs): try: response = self._session.post(url=f'{self.url}/projects/{commit.project_id}' f'/repository/commits', - headers=self.headers, data=commit.data, verify=self.verify) + headers=self.headers, + data=json.dumps(commit.data, indent=2), + verify=self.verify) except ValidationError as e: raise ParameterError(f"Invalid parameters: {e.errors()}") return response @@ -324,7 +328,9 @@ def revert_commit(self, **kwargs): try: response = self._session.post(url=f'{self.url}/projects/{commit.project_id}' f'/repository/commits/{commit.commit_hash}/revert', - headers=self.headers, data=commit.data, verify=self.verify) + headers=self.headers, + data=json.dumps(commit.data, indent=2), + verify=self.verify) except ValidationError as e: raise ParameterError(f"Invalid parameters: {e.errors()}") return response @@ -393,7 +399,9 @@ def create_commit_comment(self, **kwargs): try: response = self._session.post(url=f'{self.url}/projects/{commit.project_id}' f'/repository/commits/{commit.commit_hash}/comments', - headers=self.headers, data=commit.data, verify=self.verify) + headers=self.headers, + data=json.dumps(commit.data, indent=2), + verify=self.verify) except ValidationError as e: raise ParameterError(f"Invalid parameters: {e.errors()}") return response @@ -462,7 +470,9 @@ def post_build_status_to_commit(self, **kwargs): try: response = self._session.post(url=f'{self.url}/projects/{commit.project_id}' f'/statuses/{commit.commit_hash}/', - headers=self.headers, data=commit.data, verify=self.verify) + headers=self.headers, + data=json.dumps(commit.data, indent=2), + verify=self.verify) except ValidationError as e: raise ParameterError(f"Invalid parameters: {e.errors()}") return response @@ -1071,7 +1081,7 @@ def run_project_job(self, **kwargs): raise MissingParameterError try: response = self._session.post(url=f'{self.url}/projects/{job.project_id}/jobs/{job.job_id}/play', - headers=self.headers, data=job.data, verify=self.verify) + headers=self.headers, data=json.dumps(job.data, indent=2), verify=self.verify) except ValidationError as e: raise ParameterError(f"Invalid parameters: {e.errors()}") return response @@ -1345,7 +1355,7 @@ def create_project_level_rule(self, **kwargs): try: response = self._session.post(url=f'{self.url}/projects/{merge_rule.project_id}/approval_rules', headers=self.headers, - data=merge_rule.data, + data=json.dumps(merge_rule.data, indent=2), verify=self.verify) except ValidationError as e: @@ -1370,7 +1380,8 @@ def update_project_level_rule(self, **kwargs): try: response = self._session.put(url=f'{self.url}/projects/{merge_rule.project_id}' f'/approval_rules/{merge_rule.approval_rule_id}', - headers=self.headers, data=merge_rule.data, verify=self.verify) + headers=self.headers, data=json.dumps(merge_rule.data, indent=2), + verify=self.verify) except ValidationError as e: raise ParameterError(f"Invalid parameters: {e.errors()}") return response @@ -1393,7 +1404,8 @@ def delete_project_level_rule(self, **kwargs): try: response = self._session.put(url=f'{self.url}/projects/{merge_rule.project_id}' f'/approval_rules/{merge_rule.approval_rule_id}', - headers=self.headers, data=merge_rule.data, verify=self.verify) + headers=self.headers, data=json.dumps(merge_rule.data, indent=2), + verify=self.verify) except ValidationError as e: raise ParameterError(f"Invalid parameters: {e.errors()}") return response @@ -2640,7 +2652,7 @@ def register_new_runner(self, **kwargs): try: response = self._session.put(url=f'{self.url}/runners', headers=self.headers, - data=runner.data, + data=json.dumps(runner.data, indent=2), verify=self.verify) except ValidationError as e: raise ParameterError(f"Invalid parameters: {e.errors()}") @@ -3030,7 +3042,7 @@ def upload_wiki_page_attachment(self, **kwargs): response = self._session.put(url=f'{self.url}/projects/{wiki.project_id}/wikis/attachments', headers=headers, verify=self.verify, - data=data) + data=json.dumps(data, indent=2)) except ValidationError as e: raise ParameterError(f"Invalid parameters: {e.errors()}") return response diff --git a/test/test_gitlab_api.py b/test/test_gitlab_api.py index 97337ec..56e871e 100644 --- a/test/test_gitlab_api.py +++ b/test/test_gitlab_api.py @@ -57,7 +57,7 @@ def test_create_project_rule(): # Create branch project = 79 response = client.create_project_level_rule(project_id=project, name="Test_Rule", approvals_required=9) - assert response.status_code == 201 or response.status_code == 400 + assert response.status_code == 201 @pytest.mark.skipif( @@ -68,7 +68,7 @@ def test_get_project_rules(): # Create branch project = 79 response = client.get_project_level_rules(project_id=project) - assert response.status_code == 200 or response.status_code == 404 + assert response.status_code == 200 if __name__ == "__main__":