+# HTTMock urlmatchers
+
+
+@urlmatch(path=r'/api/v4/users/author_id$')
+def mock_users_get_author_id(url, request):
+ return {'status_code': 200,
+ 'headers': {'content-type': 'application/json'},
+ 'content': json.dumps({'username': 'author_id username', 'id': 3001})}
+
+
+@urlmatch(path=r'/api/v4/users/[^/\?]+$')
+def mock_users_get_unexpected(url, request):
+ return {'status_code': 404}
+
+
+@urlmatch(path=r'/api/v4/users', query='username=gbin')
+def mock_users_search_gbin(url, request):
+ return {'status_code': 200,
+ 'headers': {'content-type': 'application/json'},
+ 'content': json.dumps([{'username': 'gbin', 'id': 3002}])}
+
+
+@urlmatch(path=r'^/api/v4/projects/[^/]+/hooks$')
+def mock_projects_hooks_list(url, request):
+ if request.method == "GET":
+ return {'status_code': 200,
+ 'headers': {'content-type': 'application/json'},
+ 'content': '[]'}
+ elif request.method == "POST":
+ return {'status_code': 200,
+ 'headers': {'content-type': 'application/json'},
+ 'content': json.dumps({"id": "hook_id",
+ "merge_requests_events": True,
+ "url": "url"})}
+ elif request.method == "PUT":
+ return {'status_code': 200,
+ 'headers': {'content-type': 'application/json'},
+ 'content': json.dumps({"id": "hook_id",
+ "merge_requests_events": True,
+ "url": "url"})}
+ else:
+ return {'status-code': 404}
+
+
+@urlmatch(path=r'^/api/v4/projects/[^/]+$')
+def mock_projects_get(url, request):
+ return {'status_code': 200,
+ 'headers': {'content-type': 'application/json'},
+ 'content': json.dumps({"id": "projectid"})}
+
+
+@urlmatch(path=r'^/api/v4/projects/[^/]+/merge_requests')
+def mock_projects_mergerequests_list_none(url, request):
+ return {'status_code': 200,
+ 'headers': {'content-type': 'application/json'},
+ 'content': '[]'}
+
+
+@urlmatch(path=r'^/api/v4/projects/[^/]+/merge_requests/[^/]+')
+def mock_projects_mergerequests_get_unreviewed_review(url, request):
+ return {'status_code': 200,
+ 'headers': {'content-type': 'application/json'},
+ 'content': json.dumps({'iid': 'mr_id',
+ 'author': {'id': 2001},
+ 'created_at': 'Oct 29, 2017 2:37am',
+ 'merge_status': 'can_be_merged',
+ 'state': 'opened',
+ 'upvotes': 0,
+ 'web_url': 'http://gitlab.example.com/sample/mr/2001',
+ 'work_in_progress': False})}
+
+
+@urlmatch(path=r'^/api/v4/projects/[^/]+/merge_requests/[^/]+')
+def mock_projects_mergerequests_get_wip_review(url, request):
+ return {'status_code': 200,
+ 'headers': {'content-type': 'application/json'},
+ 'content': json.dumps({'iid': 'mr_id',
+ 'author': {'id': 2001},
+ 'created_at': 'Oct 29, 2017 2:37am',
+ 'merge_status': 'can_be_merged',
+ 'state': 'opened',
+ 'upvotes': 0,
+ 'web_url': 'http://gitlab.example.com/sample/mr/2001',
+ 'work_in_progress': True})}
+
+
+@urlmatch(path=r'^/api/v4/projects/[^/]+/merge_requests/[^/]+')
+def mock_projects_mergerequests_get_waiting_review(url, request):
+ return {'status_code': 200,
+ 'headers': {'content-type': 'application/json'},
+ 'content': json.dumps({'iid': 'mr_id',
+ 'author': {'id': 2001},
+ 'created_at': 'Oct 29, 2017 2:37am',
+ 'merge_status': 'can_be_merged',
+ 'state': 'opened',
+ 'upvotes': 1,
+ 'web_url': 'http://gitlab.example.com/sample/mr/2001',
+ 'work_in_progress': False})}
+
+
+@urlmatch(path=r'/api/v4/projects/[^/]+/merge_requests/[^/]+/award_emoji')
+def mock_projects_mergerequests_awardemojis_list(url, request):
+ return {'status_code': 200,
+ 'headers': {'content-type': 'application/json'},
+ 'content': json.dumps([{'id': 'id',
+ 'name': 'thumbsup',
+ 'user': {'username': 'ReviewerX'}}])}
+
+
+@urlmatch(path=r'^/api/v4/projects/[^/]+/merge_requests/[^/]+')
+def mock_projects_mergerequests_get_mergable_review(url, request):
+ return {'status_code': 200,
+ 'headers': {'content-type': 'application/json'},
+ 'content': json.dumps({'iid': 'mr_id',
+ 'author': {'id': 2001},
+ 'created_at': 'Oct 29, 2017 2:37am',
+ 'merge_status': 'can_be_merged',
+ 'state': 'opened',
+ 'upvotes': 2,
+ 'web_url': 'http://gitlab.example.com/sample/mr/2001',
+ 'work_in_progress': False})}
+
+
+@urlmatch(path=r'^/api/v4/projects/[^/]+/merge_requests/[^/]+')
+def mock_projects_mergerequests_get_conflicted_review(url, request):
+ return {'status_code': 200,
+ 'headers': {'content-type': 'application/json'},
+ 'content': json.dumps({'iid': 'mr_id',
+ 'author': {'id': 2001},
+ 'created_at': 'Oct 29, 2017 2:37am',
+ 'merge_status': 'merge_conflicts',
+ 'state': 'opened',
+ 'upvotes': 2,
+ 'web_url': 'http://gitlab.example.com/sample/mr/2001',
+ 'work_in_progress': False})}
+
+
+@urlmatch(path=r'^/api/v4/projects/[^/]+/merge_requests$', query='state=opened')
+def mock_projects_mergerequests_list_unreviewed_review(url, request):
+ return {'status_code': 200,
+ 'headers': {'content-type': 'application/json'},
+ 'content': json.dumps([{'iid': 'mr_id',
+ 'author': {'id': 2001},
+ 'created_at': 'Oct 29, 2017 2:37am',
+ 'merge_status': 'can_be_merged',
+ 'state': 'opened',
+ 'upvotes': 0,
+ 'web_url': 'http://gitlab.example.com/sample/mr/2001',
+ 'work_in_progresso': False}])}
+
+
+@urlmatch(path=r'^/api/v4/projects/[^/]+/merge_requests', query='state=reopened')
+def mock_projects_mergerequests_list_reopened(url, request):
+ return {'status_code': 200,
+ 'headers': {'content-type': 'application/json'},
+ 'content': json.dumps([])}
+
+
+@urlmatch(path=r'^/api/v4/projects/[^/]+/hooks/[^/]+$')
+def mock_projects_hooks_get_already_watching(url, request):
+ return {'status_code': 200,
+ 'headers': {'content-type': 'application/json'},
+ 'content': json.dumps({'id': 'hook_id',
+ 'merge_requests_events': True,
+ 'url': 'https://webhook.errbot.com:3142/margebot/room1,room2,room3'})}
+
+
+@urlmatch(path=r'^/api/v4/projects/[^/]+/hooks$')
+def mock_projects_hooks_list_already_watching(url, request):
+ return {'status_code': 200,
+ 'headers': {'content-type': 'application/json'},
+ 'content': json.dumps([{'id': 'hook_id',
+ 'merge_requests_events': True,
+ 'url': 'https://webhook.errbot.com:3142/margebot/room1,room2,room3'}])}
+
+