Skip to content

Commit

Permalink
Fixed data json dumping first.
Browse files Browse the repository at this point in the history
  • Loading branch information
Knucklessg1 committed May 7, 2024
1 parent 7dc6850 commit d703873
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 13 deletions.
34 changes: 23 additions & 11 deletions gitlab_api/gitlab_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand All @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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()}")
Expand Down Expand Up @@ -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
4 changes: 2 additions & 2 deletions test/test_gitlab_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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__":
Expand Down

0 comments on commit d703873

Please sign in to comment.