return {'status_code': 200,
'headers': {'content-type': 'application/json'},
'content': json.dumps({'iid': 'mr_id',
- 'author': {'id': 2001},
+ 'author': {'username': 'ReviewerX', 'id': 2001},
'created_at': 'Oct 29, 2017 2:37am',
'merge_status': 'can_be_merged',
'state': 'opened',
return {'status_code': 200,
'headers': {'content-type': 'application/json'},
'content': json.dumps({'iid': 'mr_id',
- 'author': {'id': 2001},
+ 'author': {'username': 'ReviewerX', 'id': 2001},
'created_at': 'Oct 29, 2017 2:37am',
'merge_status': 'can_be_merged',
'state': 'opened',
return {'status_code': 200,
'headers': {'content-type': 'application/json'},
'content': json.dumps({'iid': 'mr_id',
- 'author': {'id': 2001},
+ 'author': {'username': 'ReviewerX', 'id': 2001},
'created_at': 'Oct 29, 2017 2:37am',
'merge_status': 'can_be_merged',
'state': 'opened',
return {'status_code': 200,
'headers': {'content-type': 'application/json'},
'content': json.dumps({'iid': 'mr_id',
- 'author': {'id': 2001},
+ 'author': {'username': 'ReviewerX', 'id': 2001},
'created_at': 'Oct 29, 2017 2:37am',
'merge_status': 'can_be_merged',
'state': 'opened',
return {'status_code': 200,
'headers': {'content-type': 'application/json'},
'content': json.dumps({'iid': 'mr_id',
- 'author': {'id': 2001},
+ 'author': {'username': 'ReviewerX', 'id': 2001},
'created_at': 'Oct 29, 2017 2:37am',
'merge_status': 'merge_conflicts',
'state': 'opened',
return {'status_code': 200,
'headers': {'content-type': 'application/json'},
'content': json.dumps([{'iid': 'mr_id',
- 'author': {'id': 2001},
+ 'author': {'username': 'ReviewerX', 'id': 2001},
'created_at': 'Oct 29, 2017 2:37am',
'merge_status': 'can_be_merged',
'state': 'opened',
assert '1 open MR was found in the repo.' in pm
def test_gitlab_hook(self, margebot):
- request = json.dumps({'object_kind': 'merge_request',
+ request = json.dumps({'event_type': 'merge_request',
'object_attributes': {
'state': 'opened',
'work_in_progress': '',
margebot.push_message('!reviews')
assert 'Hi there ! author_id username has opened a new MR: \"title\"\nurl/merge_requests/iid' in margebot.pop_message()
+ def test_gitlab_hook_never_close(self, margebot):
+ request = json.dumps({'event_type': 'merge_request',
+ 'object_attributes': {
+ 'state': 'opened',
+ 'work_in_progress': '',
+ 'title': 'title',
+ 'author_id': 'author_id',
+ 'target_project_id': 'project_id',
+ 'id': 'id',
+ 'iid': 'iid'},
+ 'project': {
+ 'homepage': 'url'},
+ 'labels': [{'title': 'never-close'}]})
+ with HTTMock(mock_users_get_author_id):
+ margebot.push_message("!webhook test /margebot/room1,room2 " + request)
+ assert 'Status code : 200' in margebot.pop_message()
+ margebot.push_message('!reviews')
+ assert 'Hi gbin: I found no open MRs for you.' in margebot.pop_message()
+
+ def test_gitlab_hook_never_abandoned(self, margebot):
+ request = json.dumps({'event_type': 'merge_request',
+ 'object_attributes': {
+ 'state': 'opened',
+ 'work_in_progress': '',
+ 'title': 'title',
+ 'author_id': 'author_id',
+ 'target_project_id': 'project_id',
+ 'id': 'id',
+ 'iid': 'iid'},
+ 'project': {
+ 'homepage': 'url'},
+ 'labels': [{'title': 'abandoned'}]})
+ with HTTMock(mock_users_get_author_id):
+ margebot.push_message("!webhook test /margebot/room1,room2 " + request)
+ assert 'Status code : 200' in margebot.pop_message()
+ margebot.push_message('!reviews')
+ assert 'Hi gbin: I found no open MRs for you.' in margebot.pop_message()
+
def test_gitlab_hook_wip(self, margebot):
- request = json.dumps({'object_kind': 'merge_request',
+ request = json.dumps({'event_type': 'merge_request',
'object_attributes': {
'state': 'opened',
'work_in_progress': 'true',
assert 'Hi there ! author_id username has opened a new WIP MR: \"title\"\nurl/merge_requests/iid' in margebot.pop_message()
def test_gitlab_hook_unexpected_user(self, margebot):
- request = json.dumps({'object_kind': 'merge_request',
+ request = json.dumps({'event_type': 'merge_request',
'object_attributes': {
'state': 'opened',
'work_in_progress': '',
margebot.push_message('!reviews')
assert 'Hi there ! (missing) has opened a new MR: \"title\"\nurl/merge_requests/iid' in margebot.pop_message()
- def test_gitlab_hook_unexpected_object_kind(self, margebot, caplog):
- request = json.dumps({'object_kind': 'not_merge_request',
+ def test_gitlab_hook_unexpected_event_type(self, margebot, caplog):
+ request = json.dumps({'event_type': 'not_merge_request',
'object_attributes': {
'state': 'opened',
'work_in_progress': '',
margebot.pop_message()
margebot.push_message('!reviews')
assert 'Hi gbin: I found no open MRs for you.' in margebot.pop_message()
- assert 'unexpecting object_kind: not_merge_request' in caplog.text # Has to be at end of method
+ assert 'unexpecting event_type: not_merge_request' in caplog.text # Has to be at end of method
def test_nothing_to_review(self, margebot):
with HTTMock(mock_users_search_gbin):