-
Notifications
You must be signed in to change notification settings - Fork 669
Switch mr.merge() to use post_data (was using query_data) #1465
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Switch mr.merge() to use post_data (was using query_data) #1465
Conversation
Codecov Report
@@ Coverage Diff @@
## master #1465 +/- ##
===========================================
+ Coverage 80.24% 90.86% +10.62%
===========================================
Files 73 73
Lines 4064 4027 -37
===========================================
+ Hits 3261 3659 +398
+ Misses 803 368 -435
Flags with carried forward coverage won't be shown. Click here to find out more.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @JohnVillalovos!
The folks at pyup
introduced that MR (see pyupio/pyup#384) so we should maybe check with them why that was done (/cc @ferhat-aram @rafaelpivato). I agree it should be in post data for POST/PUT though, I had the same doubts in the original issue as I couldn't reproduce the issue.
The fact they had issues with 405 Method Not Allowed and that you have a lot of wait_for_sidekiq
makes me think they were more likely hitting a race condition when applying the merge, but not sure why query data would work in that case.
@@ -95,3 +98,116 @@ def test_merge_request_merge(project): | |||
with pytest.raises(gitlab.GitlabMRClosedError): | |||
# Two merge attempts should raise GitlabMRClosedError | |||
mr.merge() | |||
|
|||
|
|||
def merge_request_create_helper( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This could be turned into a fixture factory in conftest.py
(scoped to functions) that we can then use in any other test as well. The convention seems to be to create a make_merge_request
fixture with an inner _make_merge_request
function.
https://docs.pytest.org/en/6.2.x/fixture.html#factories-as-fixtures
Although not sure all of the logic should then stay in that fixture, the asserts would belong in the test itself 🤔
We have something similar here
python-gitlab/tools/functional/conftest.py
Lines 68 to 78 in 1508eb7
@pytest.fixture(scope="session") | |
def check_is_alive(): | |
""" | |
Return a healthcheck function fixture for the GitLab container spinup. | |
""" | |
def _check(container): | |
logs = ["docker", "logs", container] | |
return "gitlab Reconfigured!" in check_output(logs).decode() | |
return _check |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry @JohnVillalovos actually I think we can go ahead with this, since the previous PR broke behavior for other people and POST is the documented approach by GitLab. If it doesn't work with POST then it should be addressed upstream in GitLab. Maybe if we can just have that helper as a fixture it'd be nice :) |
Okay. Can we do that later? Though I'm not sure I totally understand the benefit of making it a fixture as only two functions use it and both of those are in the same file. I can do it, but I won't have time to do it until tomorrow at the earliest. Sorry work is a bit busy today... |
For example in the CLI functional tests, we're relying on test order because we don't have fixtures to create a merge request from a new branch: python-gitlab/tools/functional/cli/test_cli_v4.py Lines 189 to 224 in 1508eb7
There are other potential tests we currently don't do because it's not convenient (merge request deployments, merge request <resource a/b/c>) and things like this would really help. But it's a wider issue for all functional tests so definitely can wait. Also no rush of course, my comment was only that we don't wait for feedback that I initially suggested :) |
@nejch That makes a lot of sense. Thanks for the explanation! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! Should be much more reusable later with the fixture. Just a tiny comment.
Going to switch to putting parameters from in the query string to having them in the 'data' body section. Add a functional test to make sure that we don't break anything. #1120
MR #1121 changed mr.merge() to use 'query_data'. This appears to have been wrong. From the Gitlab docs they state it should be sent in a payload body https://docs.gitlab.com/ee/api/README.html#request-payload since mr.merge() is a PUT request. > Request Payload > API Requests can use parameters sent as query strings or as a > payload body. GET requests usually send a query string, while PUT > or POST requests usually send the payload body Fixes: #1452 Related to: #1120
Add a helper function to have less code duplication in the functional testing.
Added a pytest.fixture for merge_request(). Use this fixture in tools/functional/api/test_merge_requests.py
MR #1121 changed
mr.merge() to use 'query_data'. This appears to have been wrong.
From the Gitlab docs they state it should be sent in a payload body
https://docs.gitlab.com/ee/api/README.html#request-payload since
mr.merge() is a PUT request.