@@ -100,13 +100,21 @@ def test_merge_request_merge(project):
100
100
mr .merge ()
101
101
102
102
103
- def test_merge_request_should_remove_source_branch (
104
- project : gitlab .v4 .objects .Project , wait_for_sidekiq
103
+ def merge_request_create_helper (
104
+ * ,
105
+ project : gitlab .v4 .objects .Project ,
106
+ source_branch : str ,
107
+ wait_for_sidekiq ,
108
+ branch_will_be_deleted : bool ,
109
+ ** kwargs ,
105
110
):
106
- """Test to ensure https://github.com/python-gitlab/python-gitlab/issues/1120
107
- is fixed"""
111
+ # Wait for processes to be done before we start...
112
+ # NOTE(jlvillal): Sometimes the CI would give a "500 Internal Server
113
+ # Error". Hoping that waiting until all other processes are done will help
114
+ # with that.
115
+ result = wait_for_sidekiq (timeout = 60 )
116
+ assert result is True , "sidekiq process should have terminated but did not"
108
117
109
- source_branch = "remove_source_branch"
110
118
project .branches .create ({"branch" : source_branch , "ref" : "master" })
111
119
112
120
# NOTE(jlvillal): Must create a commit in the new branch before we can
@@ -143,73 +151,63 @@ def test_merge_request_should_remove_source_branch(
143
151
# Ensure we can get the MR branch
144
152
project .branches .get (source_branch )
145
153
146
- mr .merge (should_remove_source_branch = True )
154
+ mr .merge (** kwargs )
147
155
148
156
result = wait_for_sidekiq (timeout = 60 )
149
157
assert result is True , "sidekiq process should have terminated but did not"
150
158
151
- # Ensure we can NOT get the MR branch
152
- with pytest .raises (gitlab .exceptions .GitlabGetError ):
153
- project .branches .get (source_branch )
159
+ # Wait until it is merged
160
+ mr_iid = mr .iid
161
+ for _ in range (60 ):
162
+ mr = project .mergerequests .get (mr_iid )
163
+ if mr .merged_at is not None :
164
+ break
165
+ time .sleep (0.5 )
166
+ assert mr .merged_at is not None
167
+ time .sleep (0.5 )
154
168
155
- mr = project .mergerequests .get (mr .iid )
156
- assert mr .merged_at is not None # Now is merged
169
+ if branch_will_be_deleted :
170
+ # Ensure we can NOT get the MR branch
171
+ with pytest .raises (gitlab .exceptions .GitlabGetError ):
172
+ project .branches .get (source_branch )
157
173
158
174
159
- def test_merge_request_large_commit_message (
175
+ def test_merge_request_should_remove_source_branch (
160
176
project : gitlab .v4 .objects .Project , wait_for_sidekiq
161
177
):
162
- """Test to ensure https://github.com/python-gitlab/python-gitlab/issues/1452
163
- is fixed"""
164
- source_branch = "large_commit_message"
165
- project . branches . create ({ "branch" : source_branch , "ref" : "master" })
178
+ """Test to ensure
179
+ https://github.com/python-gitlab/python-gitlab/issues/1120 is fixed.
180
+ Bug reported that they could not use 'should_remove_source_branch' in
181
+ mr.merge() call"""
166
182
167
- # NOTE(jlvillal): Must create a commit in the new branch before we can
168
- # create an MR that will work.
169
- project .files .create (
170
- {
171
- "file_path" : f"README.{ source_branch } " ,
172
- "branch" : source_branch ,
173
- "content" : "Initial content" ,
174
- "commit_message" : "New commit in new branch" ,
175
- }
176
- )
183
+ source_branch = "remove_source_branch"
177
184
178
- mr = project .mergerequests .create (
179
- {
180
- "source_branch" : source_branch ,
181
- "target_branch" : "master" ,
182
- "title" : "Large Commit Message" ,
183
- "remove_source_branch" : True ,
184
- }
185
+ merge_request_create_helper (
186
+ project = project ,
187
+ source_branch = source_branch ,
188
+ wait_for_sidekiq = wait_for_sidekiq ,
189
+ branch_will_be_deleted = True ,
190
+ should_remove_source_branch = True ,
185
191
)
186
192
187
- result = wait_for_sidekiq (timeout = 60 )
188
- assert result is True , "sidekiq process should have terminated but did not"
189
-
190
- mr_iid = mr .iid
191
- for _ in range (60 ):
192
- mr = project .mergerequests .get (mr_iid )
193
- if mr .merge_status != "checking" :
194
- break
195
- time .sleep (0.5 )
196
- assert mr .merge_status != "checking"
197
193
198
- # Ensure we can get the MR branch
199
- project .branches .get (source_branch )
200
-
201
- commit_message = "large_message\r \n " * 1_000
202
- assert len (commit_message ) > 10_000
203
- assert mr .merged_at is None # Not yet merged
204
-
205
- mr .merge (merge_commit_message = commit_message , should_remove_source_branch = True )
206
-
207
- result = wait_for_sidekiq (timeout = 60 )
208
- assert result is True , "sidekiq process should have terminated but did not"
194
+ def test_merge_request_large_commit_message (
195
+ project : gitlab .v4 .objects .Project , wait_for_sidekiq
196
+ ):
197
+ """Test to ensure https://github.com/python-gitlab/python-gitlab/issues/1452
198
+ is fixed.
199
+ Bug reported that very long 'merge_commit_message' in mr.merge() would
200
+ cause an error: 414 Request too large
201
+ """
202
+ source_branch = "large_commit_message"
209
203
210
- # Ensure we can NOT get the MR branch
211
- with pytest .raises (gitlab .exceptions .GitlabGetError ):
212
- project .branches .get (source_branch )
204
+ merge_commit_message = "large_message\r \n " * 1_000
205
+ assert len (merge_commit_message ) > 10_000
213
206
214
- mr = project .mergerequests .get (mr .iid )
215
- assert mr .merged_at is not None # Now is merged
207
+ merge_request_create_helper (
208
+ project = project ,
209
+ source_branch = source_branch ,
210
+ wait_for_sidekiq = wait_for_sidekiq ,
211
+ branch_will_be_deleted = False ,
212
+ merge_commit_message = merge_commit_message ,
213
+ )
0 commit comments