1# -*- coding: utf-8 -*- 2 3# Copyright: (c) 2019, Guillaume Martinez (lunik@tiwabbit.fr) 4# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) 5 6from __future__ import absolute_import 7 8import sys 9 10from httmock import response # noqa 11from httmock import urlmatch # noqa 12 13from units.compat import unittest 14 15from gitlab import Gitlab 16 17 18class FakeAnsibleModule(object): 19 def __init__(self): 20 self.check_mode = False 21 22 def fail_json(self, **args): 23 pass 24 25 def exit_json(self, **args): 26 pass 27 28 29class GitlabModuleTestCase(unittest.TestCase): 30 def setUp(self): 31 unitest_python_version_check_requirement(self) 32 33 self.mock_module = FakeAnsibleModule() 34 35 self.gitlab_instance = Gitlab("http://localhost", private_token="private_token", api_version=4) 36 37 38# Python 2.7+ is needed for python-gitlab 39GITLAB_MINIMUM_PYTHON_VERSION = (2, 7) 40 41 42# Verify if the current Python version is higher than GITLAB_MINIMUM_PYTHON_VERSION 43def python_version_match_requirement(): 44 return sys.version_info >= GITLAB_MINIMUM_PYTHON_VERSION 45 46 47# Skip unittest test case if python version don't match requirement 48def unitest_python_version_check_requirement(unittest_testcase): 49 if not python_version_match_requirement(): 50 unittest_testcase.skipTest("Python %s+ is needed for python-gitlab" % ",".join(map(str, GITLAB_MINIMUM_PYTHON_VERSION))) 51 52 53''' 54USER API 55''' 56 57 58@urlmatch(scheme="http", netloc="localhost", path="/api/v4/users", method="get") 59def resp_find_user(url, request): 60 headers = {'content-type': 'application/json'} 61 content = ('[{"id": 1, "username": "john_smith", "name": "John Smith", "state": "active",' 62 '"avatar_url": "http://localhost:3000/uploads/user/avatar/1/cd8.jpeg",' 63 '"web_url": "http://localhost:3000/john_smith"}, {"id": 2,' 64 '"username": "jack_smith", "name": "Jack Smith", "state": "blocked",' 65 '"avatar_url": "http://gravatar.com/../e32131cd8.jpeg",' 66 '"web_url": "http://localhost:3000/jack_smith"}]') 67 content = content.encode("utf-8") 68 return response(200, content, headers, None, 5, request) 69 70 71@urlmatch(scheme="http", netloc="localhost", path="/api/v4/users", method="post") 72def resp_create_user(url, request): 73 headers = {'content-type': 'application/json'} 74 content = ('{"id": 1, "username": "john_smith", "name": "John Smith", "state": "active",' 75 '"avatar_url": "http://localhost:3000/uploads/user/avatar/1/cd8.jpeg",' 76 '"web_url": "http://localhost:3000/john_smith","created_at": "2012-05-23T08:00:58Z",' 77 '"bio": null, "location": null, "public_email": "john@example.com", "skype": "",' 78 '"linkedin": "", "twitter": "", "website_url": "", "organization": ""}') 79 content = content.encode("utf-8") 80 return response(201, content, headers, None, 5, request) 81 82 83@urlmatch(scheme="http", netloc="localhost", path="/api/v4/users/1", method="get") 84def resp_get_user(url, request): 85 headers = {'content-type': 'application/json'} 86 content = ('{"id": 1, "username": "john_smith", "name": "John Smith",' 87 '"state": "active",' 88 '"avatar_url": "http://localhost:3000/uploads/user/avatar/1/cd8.jpeg",' 89 '"web_url": "http://localhost:3000/john_smith",' 90 '"created_at": "2012-05-23T08:00:58Z", "bio": null, "location": null,' 91 '"public_email": "john@example.com", "skype": "", "linkedin": "",' 92 '"twitter": "", "website_url": "", "organization": "", "is_admin": false}') 93 content = content.encode("utf-8") 94 return response(200, content, headers, None, 5, request) 95 96 97@urlmatch(scheme="http", netloc="localhost", path="/api/v4/users/1", method="get") 98def resp_get_missing_user(url, request): 99 headers = {'content-type': 'application/json'} 100 content = ('{}') 101 content = content.encode("utf-8") 102 return response(404, content, headers, None, 5, request) 103 104 105@urlmatch(scheme="http", netloc="localhost", path="/api/v4/users/1", method="delete") 106def resp_delete_user(url, request): 107 headers = {'content-type': 'application/json'} 108 content = ('{}') 109 content = content.encode("utf-8") 110 return response(204, content, headers, None, 5, request) 111 112 113@urlmatch(scheme="http", netloc="localhost", path="/api/v4/users/1", method="delete") 114def resp_delete_missing_user(url, request): 115 headers = {'content-type': 'application/json'} 116 content = ('{}') 117 content = content.encode("utf-8") 118 return response(404, content, headers, None, 5, request) 119 120 121''' 122USER SSHKEY API 123''' 124 125 126@urlmatch(scheme="http", netloc="localhost", path="/api/v4/users/1/keys", method="get") 127def resp_get_user_keys(url, request): 128 headers = {'content-type': 'application/json'} 129 content = ('[{"id": 1, "title": "Public key",' 130 '"key": "ssh-rsa AAAAB3NzaC1yc2EAAAABJQAAAIEAiPWx6WM4lhHNedGfBpPJNPpZ7yKu+dnn1SJejgt4596' 131 'k6YjzGGphH2TUxwKzxcKDKKezwkpfnxPkSMkuEspGRt/aZZ9wa++Oi7Qkr8prgHc4soW6NUlfDzpvZK2H5E7eQa' 132 'SeP3SAwGmQKUFHCddNaP0L+hM7zhFNzjFvpaMgJw0=",' 133 '"created_at": "2014-08-01T14:47:39.080Z"},{"id": 3,' 134 '"title": "Another Public key",' 135 '"key": "ssh-rsa AAAAB3NzaC1yc2EAAAABJQAAAIEAiPWx6WM4lhHNedGfBpPJNPpZ7yKu+dnn1SJejgt4596' 136 'k6YjzGGphH2TUxwKzxcKDKKezwkpfnxPkSMkuEspGRt/aZZ9wa++Oi7Qkr8prgHc4soW6NUlfDzpvZK2H5E7eQaS' 137 'eP3SAwGmQKUFHCddNaP0L+hM7zhFNzjFvpaMgJw0=",' 138 '"created_at": "2014-08-01T14:47:39.080Z"}]') 139 content = content.encode("utf-8") 140 return response(200, content, headers, None, 5, request) 141 142 143@urlmatch(scheme="http", netloc="localhost", path="/api/v4/users/1/keys", method="post") 144def resp_create_user_keys(url, request): 145 headers = {'content-type': 'application/json'} 146 content = ('{"id": 1, "title": "Private key",' 147 '"key": "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDA1YotVDm2mAyk2tPt4E7AHm01sS6JZmcUdRuSuA5z' 148 'szUJzYPPUSRAX3BCgTqLqYx//UuVncK7YqLVSbbwjKR2Ez5lISgCnVfLVEXzwhv+xawxKWmI7hJ5S0tOv6MJ+Ixy' 149 'Ta4xcKwJTwB86z22n9fVOQeJTR2dSOH1WJrf0PvRk+KVNY2jTiGHTi9AIjLnyD/jWRpOgtdfkLRc8EzAWrWlgNmH' 150 '2WOKBw6za0az6XoG75obUdFVdW3qcD0xc809OHLi7FDf+E7U4wiZJCFuUizMeXyuK/SkaE1aee4Qp5R4dxTR4TP9' 151 'M1XAYkf+kF0W9srZ+mhF069XD/zhUPJsvwEF",' 152 '"created_at": "2014-08-01T14:47:39.080Z"}') 153 content = content.encode("utf-8") 154 return response(201, content, headers, None, 5, request) 155 156 157''' 158GROUP API 159''' 160 161 162@urlmatch(scheme="http", netloc="localhost", path="/api/v4/groups", method="get") 163def resp_find_group(url, request): 164 headers = {'content-type': 'application/json'} 165 content = ('[{"id": 1, "name": "Foobar Group", "path": "foo-bar",' 166 '"description": "An interesting group", "visibility": "public",' 167 '"lfs_enabled": true, "avatar_url": "http://localhost:3000/uploads/group/avatar/1/foo.jpg",' 168 '"web_url": "http://localhost:3000/groups/foo-bar", "request_access_enabled": false,' 169 '"full_name": "Foobar Group", "full_path": "foo-bar",' 170 '"file_template_project_id": 1, "parent_id": null, "projects": []}, {"id": 2, "name": "BarFoo Group", "path": "bar-foor",' 171 '"description": "An interesting group", "visibility": "public",' 172 '"lfs_enabled": true, "avatar_url": "http://localhost:3000/uploads/group/avatar/2/bar.jpg",' 173 '"web_url": "http://localhost:3000/groups/bar-foo", "request_access_enabled": false,' 174 '"full_name": "BarFoo Group", "full_path": "bar-foo",' 175 '"file_template_project_id": 1, "parent_id": null, "projects": []}]') 176 content = content.encode("utf-8") 177 return response(200, content, headers, None, 5, request) 178 179 180@urlmatch(scheme="http", netloc="localhost", path="/api/v4/groups/1", method="get") 181def resp_get_group(url, request): 182 headers = {'content-type': 'application/json'} 183 content = ('{"id": 1, "name": "Foobar Group", "path": "foo-bar",' 184 '"description": "An interesting group", "visibility": "public",' 185 '"lfs_enabled": true, "avatar_url": "http://localhost:3000/uploads/group/avatar/1/foo.jpg",' 186 '"web_url": "http://localhost:3000/groups/foo-bar", "request_access_enabled": false,' 187 '"full_name": "Foobar Group", "full_path": "foo-bar",' 188 '"file_template_project_id": 1, "parent_id": null, "projects": [{"id": 1,"description": null, "default_branch": "master",' 189 '"ssh_url_to_repo": "git@example.com:diaspora/diaspora-client.git",' 190 '"http_url_to_repo": "http://example.com/diaspora/diaspora-client.git",' 191 '"web_url": "http://example.com/diaspora/diaspora-client",' 192 '"readme_url": "http://example.com/diaspora/diaspora-client/blob/master/README.md",' 193 '"tag_list": ["example","disapora client"],"name": "Diaspora Client",' 194 '"name_with_namespace": "Diaspora / Diaspora Client","path": "diaspora-client",' 195 '"path_with_namespace": "diaspora/diaspora-client","created_at": "2013-09-30T13:46:02Z",' 196 '"last_activity_at": "2013-09-30T13:46:02Z","forks_count": 0,' 197 '"avatar_url": "http://example.com/uploads/project/avatar/4/uploads/avatar.png",' 198 '"star_count": 0}]}') 199 content = content.encode("utf-8") 200 return response(200, content, headers, None, 5, request) 201 202 203@urlmatch(scheme="http", netloc="localhost", path="/api/v4/groups/1", method="get") 204def resp_get_missing_group(url, request): 205 headers = {'content-type': 'application/json'} 206 content = ('{}') 207 content = content.encode("utf-8") 208 return response(404, content, headers, None, 5, request) 209 210 211@urlmatch(scheme="http", netloc="localhost", path="/api/v4/groups", method="post") 212def resp_create_group(url, request): 213 headers = {'content-type': 'application/json'} 214 content = ('{"id": 1, "name": "Foobar Group", "path": "foo-bar",' 215 '"description": "An interesting group", "visibility": "public",' 216 '"lfs_enabled": true, "avatar_url": "http://localhost:3000/uploads/group/avatar/1/foo.jpg",' 217 '"web_url": "http://localhost:3000/groups/foo-bar", "request_access_enabled": false,' 218 '"full_name": "Foobar Group", "full_path": "foo-bar",' 219 '"file_template_project_id": 1, "parent_id": null}') 220 content = content.encode("utf-8") 221 return response(200, content, headers, None, 5, request) 222 223 224@urlmatch(scheme="http", netloc="localhost", path="/api/v4/groups", method="post") 225def resp_create_subgroup(url, request): 226 headers = {'content-type': 'application/json'} 227 content = ('{"id": 2, "name": "BarFoo Group", "path": "bar-foor",' 228 '"description": "An interesting group", "visibility": "public",' 229 '"lfs_enabled": true, "avatar_url": "http://localhost:3000/uploads/group/avatar/2/bar.jpg",' 230 '"web_url": "http://localhost:3000/groups/foo-bar/bar-foo", "request_access_enabled": false,' 231 '"full_name": "BarFoo Group", "full_path": "foo-bar/bar-foo",' 232 '"file_template_project_id": 1, "parent_id": 1}') 233 content = content.encode("utf-8") 234 return response(200, content, headers, None, 5, request) 235 236 237@urlmatch(scheme="http", netloc="localhost", path="/api/v4/users/1", method="delete") 238def resp_delete_group(url, request): 239 headers = {'content-type': 'application/json'} 240 content = ('{}') 241 content = content.encode("utf-8") 242 return response(204, content, headers, None, 5, request) 243 244 245''' 246GROUP MEMBER API 247''' 248 249 250@urlmatch(scheme="http", netloc="localhost", path="/api/v4/groups/1/members/1", method="get") 251def resp_get_member(url, request): 252 headers = {'content-type': 'application/json'} 253 content = ('{"id": 1, "username": "raymond_smith", "name": "Raymond Smith", "state": "active",' 254 '"avatar_url": "https://www.gravatar.com/avatar/c2525a7f58ae3776070e44c106c48e15?s=80&d=identicon",' 255 '"web_url": "http://192.168.1.8:3000/root", "expires_at": "2012-10-22T14:13:35Z", "access_level": 30}') 256 content = content.encode("utf-8") 257 return response(200, content, headers, None, 5, request) 258 259 260@urlmatch(scheme="http", netloc="localhost", path="/api/v4/groups/1/members", method="get") 261def resp_find_member(url, request): 262 headers = {'content-type': 'application/json'} 263 content = ('[{"id": 1, "username": "raymond_smith", "name": "Raymond Smith", "state": "active",' 264 '"avatar_url": "https://www.gravatar.com/avatar/c2525a7f58ae3776070e44c106c48e15?s=80&d=identicon",' 265 '"web_url": "http://192.168.1.8:3000/root", "expires_at": "2012-10-22T14:13:35Z", "access_level": 30},{' 266 '"id": 2, "username": "john_doe", "name": "John Doe","state": "active",' 267 '"avatar_url": "https://www.gravatar.com/avatar/c2525a7f58ae3776070e44c106c48e15?s=80&d=identicon",' 268 '"web_url": "http://192.168.1.8:3000/root","expires_at": "2012-10-22T14:13:35Z",' 269 '"access_level": 30}]') 270 content = content.encode("utf-8") 271 return response(200, content, headers, None, 5, request) 272 273 274@urlmatch(scheme="http", netloc="localhost", path="/api/v4/groups/1/members", method="post") 275def resp_add_member(url, request): 276 headers = {'content-type': 'application/json'} 277 content = ('{"id": 1, "username": "raymond_smith", "name": "Raymond Smith",' 278 '"state": "active",' 279 '"avatar_url": "https://www.gravatar.com/avatar/c2525a7f58ae3776070e44c106c48e15?s=80&d=identicon",' 280 '"web_url": "http://192.168.1.8:3000/root", "expires_at": "2012-10-22T14:13:35Z",' 281 '"access_level": 30}') 282 content = content.encode("utf-8") 283 return response(200, content, headers, None, 5, request) 284 285 286@urlmatch(scheme="http", netloc="localhost", path="/api/v4/groups/1/members/1", method="put") 287def resp_update_member(url, request): 288 headers = {'content-type': 'application/json'} 289 content = ('{"id": 1, "username": "raymond_smith", "name": "Raymond Smith",' 290 '"state": "active",' 291 '"avatar_url": "https://www.gravatar.com/avatar/c2525a7f58ae3776070e44c106c48e15?s=80&d=identicon",' 292 '"web_url": "http://192.168.1.8:3000/root", "expires_at": "2012-10-22T14:13:35Z",' 293 '"access_level": 10}') 294 content = content.encode("utf-8") 295 return response(200, content, headers, None, 5, request) 296 297 298''' 299DEPLOY KEY API 300''' 301 302 303@urlmatch(scheme="http", netloc="localhost", path="/api/v4/projects/1/deploy_keys", method="get") 304def resp_find_project_deploy_key(url, request): 305 headers = {'content-type': 'application/json'} 306 content = ('[{"id": 1,"title": "Public key",' 307 '"key": "ssh-rsa AAAAB3NzaC1yc2EAAAABJQAAAIEAiPWx6WM4lhHNedGfBpPJNPpZ7yKu+dnn1SJejgt4596k6YjzGGphH2TUxwKzxc' 308 'KDKKezwkpfnxPkSMkuEspGRt/aZZ9wa++Oi7Qkr8prgHc4soW6NUlfDzpvZK2H5E7eQaSeP3SAwGmQKUFHCddNaP0L+hM7zhFNzjFvpaMgJw0=",' 309 '"created_at": "2013-10-02T10:12:29Z"},{"id": 3,"title": "Another Public key",' 310 '"key": "ssh-rsa AAAAB3NzaC1yc2EAAAABJQAAAIEAiPWx6WM4lhHNedGfBpPJNPpZ7yKu+dnn1SJejgt4596k6YjzGGphH2TUxwKzxc' 311 'KDKKezwkpfnxPkSMkuEspGRt/aZZ9wa++Oi7Qkr8prgHc4soW6NUlfDzpvZK2H5E7eQaSeP3SAwGmQKUFHCddNaP0L+hM7zhFNzjFvpaMgJw0=",' 312 '"created_at": "2013-10-02T11:12:29Z"}]') 313 content = content.encode("utf-8") 314 return response(200, content, headers, None, 5, request) 315 316 317@urlmatch(scheme="http", netloc="localhost", path="/api/v4/projects/1/deploy_keys/1", method="get") 318def resp_get_project_deploy_key(url, request): 319 headers = {'content-type': 'application/json'} 320 content = ('{"id": 1,"title": "Public key",' 321 '"key": "ssh-rsa AAAAB3NzaC1yc2EAAAABJQAAAIEAiPWx6WM4lhHNedGfBpPJNPpZ7yKu+dnn1SJejgt4596k6YjzGGphH2TUxwKzxc' 322 'KDKKezwkpfnxPkSMkuEspGRt/aZZ9wa++Oi7Qkr8prgHc4soW6NUlfDzpvZK2H5E7eQaSeP3SAwGmQKUFHCddNaP0L+hM7zhFNzjFvpaMgJw0=",' 323 '"created_at": "2013-10-02T10:12:29Z"}') 324 content = content.encode("utf-8") 325 return response(200, content, headers, None, 5, request) 326 327 328@urlmatch(scheme="http", netloc="localhost", path="/api/v4/projects/1/deploy_keys", method="post") 329def resp_create_project_deploy_key(url, request): 330 headers = {'content-type': 'application/json'} 331 content = ('{"id": 1,"title": "Public key",' 332 '"key": "ssh-rsa AAAAB3NzaC1yc2EAAAABJQAAAIEAiPWx6WM4lhHNedGfBpPJNPpZ7yKu+dnn1SJejgt4596k6YjzGGphH2TUxwKzxc' 333 'KDKKezwkpfnxPkSMkuEspGRt/aZZ9wa++Oi7Qkr8prgHc4soW6NUlfDzpvZK2H5E7eQaSeP3SAwGmQKUFHCddNaP0L+hM7zhFNzjFvpaMgJw0=",' 334 '"created_at": "2013-10-02T10:12:29Z"}') 335 content = content.encode("utf-8") 336 return response(201, content, headers, None, 5, request) 337 338 339@urlmatch(scheme="http", netloc="localhost", path="/api/v4/projects/1/deploy_keys/1", method="delete") 340def resp_delete_project_deploy_key(url, request): 341 headers = {'content-type': 'application/json'} 342 content = ('{}') 343 content = content.encode("utf-8") 344 return response(204, content, headers, None, 5, request) 345 346 347''' 348PROJECT API 349''' 350 351 352@urlmatch(scheme="http", netloc="localhost", path="/api/v4/projects", method="get") 353def resp_find_project(url, request): 354 headers = {'content-type': 'application/json'} 355 content = ('[{"id": 1,"description": null, "default_branch": "master",' 356 '"ssh_url_to_repo": "git@example.com:diaspora/diaspora-client.git",' 357 '"http_url_to_repo": "http://example.com/diaspora/diaspora-client.git",' 358 '"web_url": "http://example.com/diaspora/diaspora-client",' 359 '"readme_url": "http://example.com/diaspora/diaspora-client/blob/master/README.md",' 360 '"tag_list": ["example","disapora client"],"name": "Diaspora Client",' 361 '"name_with_namespace": "Diaspora / Diaspora Client","path": "diaspora-client",' 362 '"path_with_namespace": "diaspora/diaspora-client","created_at": "2013-09-30T13:46:02Z",' 363 '"last_activity_at": "2013-09-30T13:46:02Z","forks_count": 0,' 364 '"avatar_url": "http://example.com/uploads/project/avatar/4/uploads/avatar.png",' 365 '"star_count": 0}]') 366 content = content.encode("utf-8") 367 return response(200, content, headers, None, 5, request) 368 369 370@urlmatch(scheme="http", netloc="localhost", path="/api/v4/projects/1", method="get") 371def resp_get_project(url, request): 372 headers = {'content-type': 'application/json'} 373 content = ('{"id": 1,"description": null, "default_branch": "master",' 374 '"ssh_url_to_repo": "git@example.com:diaspora/diaspora-client.git",' 375 '"http_url_to_repo": "http://example.com/diaspora/diaspora-client.git",' 376 '"web_url": "http://example.com/diaspora/diaspora-client",' 377 '"readme_url": "http://example.com/diaspora/diaspora-client/blob/master/README.md",' 378 '"tag_list": ["example","disapora client"],"name": "Diaspora Client",' 379 '"name_with_namespace": "Diaspora / Diaspora Client","path": "diaspora-client",' 380 '"path_with_namespace": "diaspora/diaspora-client","created_at": "2013-09-30T13:46:02Z",' 381 '"last_activity_at": "2013-09-30T13:46:02Z","forks_count": 0,' 382 '"avatar_url": "http://example.com/uploads/project/avatar/4/uploads/avatar.png",' 383 '"star_count": 0}') 384 content = content.encode("utf-8") 385 return response(200, content, headers, None, 5, request) 386 387 388@urlmatch(scheme="http", netloc="localhost", path="/api/v4/projects/foo-bar%2Fdiaspora-client", method="get") 389def resp_get_project_by_name(url, request): 390 headers = {'content-type': 'application/json'} 391 content = ('{"id": 1,"description": null, "default_branch": "master",' 392 '"ssh_url_to_repo": "git@example.com:diaspora/diaspora-client.git",' 393 '"http_url_to_repo": "http://example.com/diaspora/diaspora-client.git",' 394 '"web_url": "http://example.com/diaspora/diaspora-client",' 395 '"readme_url": "http://example.com/diaspora/diaspora-client/blob/master/README.md",' 396 '"tag_list": ["example","disapora client"],"name": "Diaspora Client",' 397 '"name_with_namespace": "Diaspora / Diaspora Client","path": "diaspora-client",' 398 '"path_with_namespace": "diaspora/diaspora-client","created_at": "2013-09-30T13:46:02Z",' 399 '"last_activity_at": "2013-09-30T13:46:02Z","forks_count": 0,' 400 '"avatar_url": "http://example.com/uploads/project/avatar/4/uploads/avatar.png",' 401 '"star_count": 0}') 402 content = content.encode("utf-8") 403 return response(200, content, headers, None, 5, request) 404 405 406@urlmatch(scheme="http", netloc="localhost", path="/api/v4/groups/1/projects", method="get") 407def resp_find_group_project(url, request): 408 headers = {'content-type': 'application/json'} 409 content = ('[{"id": 1,"description": null, "default_branch": "master",' 410 '"ssh_url_to_repo": "git@example.com:diaspora/diaspora-client.git",' 411 '"http_url_to_repo": "http://example.com/diaspora/diaspora-client.git",' 412 '"web_url": "http://example.com/diaspora/diaspora-client",' 413 '"readme_url": "http://example.com/diaspora/diaspora-client/blob/master/README.md",' 414 '"tag_list": ["example","disapora client"],"name": "Diaspora Client",' 415 '"name_with_namespace": "Diaspora / Diaspora Client","path": "diaspora-client",' 416 '"path_with_namespace": "diaspora/diaspora-client","created_at": "2013-09-30T13:46:02Z",' 417 '"last_activity_at": "2013-09-30T13:46:02Z","forks_count": 0,' 418 '"avatar_url": "http://example.com/uploads/project/avatar/4/uploads/avatar.png",' 419 '"star_count": 0}]') 420 content = content.encode("utf-8") 421 return response(200, content, headers, None, 5, request) 422 423 424@urlmatch(scheme="http", netloc="localhost", path="/api/v4/groups/1/projects/1", method="get") 425def resp_get_group_project(url, request): 426 headers = {'content-type': 'application/json'} 427 content = ('{"id": 1,"description": null, "default_branch": "master",' 428 '"ssh_url_to_repo": "git@example.com:diaspora/diaspora-client.git",' 429 '"http_url_to_repo": "http://example.com/diaspora/diaspora-client.git",' 430 '"web_url": "http://example.com/diaspora/diaspora-client",' 431 '"readme_url": "http://example.com/diaspora/diaspora-client/blob/master/README.md",' 432 '"tag_list": ["example","disapora client"],"name": "Diaspora Client",' 433 '"name_with_namespace": "Diaspora / Diaspora Client","path": "diaspora-client",' 434 '"path_with_namespace": "diaspora/diaspora-client","created_at": "2013-09-30T13:46:02Z",' 435 '"last_activity_at": "2013-09-30T13:46:02Z","forks_count": 0,' 436 '"avatar_url": "http://example.com/uploads/project/avatar/4/uploads/avatar.png",' 437 '"star_count": 0}') 438 content = content.encode("utf-8") 439 return response(200, content, headers, None, 5, request) 440 441 442@urlmatch(scheme="http", netloc="localhost", path="/api/v4/projects", method="post") 443def resp_create_project(url, request): 444 headers = {'content-type': 'application/json'} 445 content = ('{"id": 1,"description": null, "default_branch": "master",' 446 '"ssh_url_to_repo": "git@example.com:diaspora/diaspora-client.git",' 447 '"http_url_to_repo": "http://example.com/diaspora/diaspora-client.git",' 448 '"web_url": "http://example.com/diaspora/diaspora-client",' 449 '"readme_url": "http://example.com/diaspora/diaspora-client/blob/master/README.md",' 450 '"tag_list": ["example","disapora client"],"name": "Diaspora Client",' 451 '"name_with_namespace": "Diaspora / Diaspora Client","path": "diaspora-client",' 452 '"path_with_namespace": "diaspora/diaspora-client","created_at": "2013-09-30T13:46:02Z",' 453 '"last_activity_at": "2013-09-30T13:46:02Z","forks_count": 0,' 454 '"avatar_url": "http://example.com/uploads/project/avatar/4/uploads/avatar.png",' 455 '"star_count": 0}') 456 content = content.encode("utf-8") 457 return response(201, content, headers, None, 5, request) 458 459 460@urlmatch(scheme="http", netloc="localhost", path="/api/v4/projects/1", method="delete") 461def resp_delete_project(url, request): 462 headers = {'content-type': 'application/json'} 463 content = ('{}') 464 content = content.encode("utf-8") 465 466 return response(204, content, headers, None, 5, request) 467 468 469''' 470HOOK API 471''' 472 473 474@urlmatch(scheme="http", netloc="localhost", path="/api/v4/projects/1/hooks", method="get") 475def resp_find_project_hook(url, request): 476 headers = {'content-type': 'application/json'} 477 content = ('[{"id": 1,"url": "http://example.com/hook","project_id": 3,' 478 '"push_events": true,"push_events_branch_filter": "","issues_events": true,' 479 '"confidential_issues_events": true,"merge_requests_events": true,' 480 '"tag_push_events": true,"note_events": true,"job_events": true,' 481 '"pipeline_events": true,"wiki_page_events": true,"enable_ssl_verification": true,' 482 '"created_at": "2012-10-12T17:04:47Z"}]') 483 content = content.encode("utf-8") 484 return response(200, content, headers, None, 5, request) 485 486 487@urlmatch(scheme="http", netloc="localhost", path="/api/v4/projects/1/hooks/1", method="get") 488def resp_get_project_hook(url, request): 489 headers = {'content-type': 'application/json'} 490 content = ('{"id": 1,"url": "http://example.com/hook","project_id": 3,' 491 '"push_events": true,"push_events_branch_filter": "","issues_events": true,' 492 '"confidential_issues_events": true,"merge_requests_events": true,' 493 '"tag_push_events": true,"note_events": true,"job_events": true,' 494 '"pipeline_events": true,"wiki_page_events": true,"enable_ssl_verification": true,' 495 '"created_at": "2012-10-12T17:04:47Z"}') 496 content = content.encode("utf-8") 497 return response(200, content, headers, None, 5, request) 498 499 500@urlmatch(scheme="http", netloc="localhost", path="/api/v4/projects/1/hooks", method="post") 501def resp_create_project_hook(url, request): 502 headers = {'content-type': 'application/json'} 503 content = ('{"id": 1,"url": "http://example.com/hook","project_id": 3,' 504 '"push_events": true,"push_events_branch_filter": "","issues_events": true,' 505 '"confidential_issues_events": true,"merge_requests_events": true,' 506 '"tag_push_events": true,"note_events": true,"job_events": true,' 507 '"pipeline_events": true,"wiki_page_events": true,"enable_ssl_verification": true,' 508 '"created_at": "2012-10-12T17:04:47Z"}') 509 content = content.encode("utf-8") 510 return response(201, content, headers, None, 5, request) 511 512 513@urlmatch(scheme="http", netloc="localhost", path="/api/v4/projects/1/hooks/1", method="delete") 514def resp_delete_project_hook(url, request): 515 headers = {'content-type': 'application/json'} 516 content = ('{}') 517 content = content.encode("utf-8") 518 return response(204, content, headers, None, 5, request) 519 520 521''' 522RUNNER API 523''' 524 525 526@urlmatch(scheme="http", netloc="localhost", path="/api/v4/runners/all", method="get") 527def resp_find_runners_all(url, request): 528 headers = {'content-type': 'application/json'} 529 content = ('[{"active": true,"description": "test-1-20150125","id": 1,' 530 '"is_shared": false,"ip_address": "127.0.0.1","name": null,' 531 '"online": true,"status": "online"},{"active": true,' 532 '"description": "test-2-20150125","id": 2,"ip_address": "127.0.0.1",' 533 '"is_shared": false,"name": null,"online": false,"status": "offline"}]') 534 content = content.encode("utf-8") 535 return response(200, content, headers, None, 5, request) 536 537 538@urlmatch(scheme="http", netloc="localhost", path="/api/v4/runners", method="get") 539def resp_find_runners_list(url, request): 540 headers = {'content-type': 'application/json', 541 "X-Page": 1, 542 "X-Next-Page": 2, 543 "X-Per-Page": 1, 544 "X-Total-Pages": 1, 545 "X-Total": 2} 546 content = ('[{"active": true,"description": "test-1-20150125","id": 1,' 547 '"is_shared": false,"ip_address": "127.0.0.1","name": null,' 548 '"online": true,"status": "online"},{"active": true,' 549 '"description": "test-2-20150125","id": 2,"ip_address": "127.0.0.1",' 550 '"is_shared": false,"name": null,"online": false,"status": "offline"}]') 551 content = content.encode("utf-8") 552 return response(200, content, headers, None, 5, request) 553 554 555@urlmatch(scheme="http", netloc="localhost", path="/api/v4/runners/1", method="get") 556def resp_get_runner(url, request): 557 headers = {'content-type': 'application/json'} 558 content = ('{"active": true,"description": "test-1-20150125","id": 1,' 559 '"is_shared": false,"ip_address": "127.0.0.1","name": null,' 560 '"online": true,"status": "online"}') 561 content = content.encode("utf-8") 562 return response(200, content, headers, None, 5, request) 563 564 565@urlmatch(scheme="http", netloc="localhost", path="/api/v4/runners", method="post") 566def resp_create_runner(url, request): 567 headers = {'content-type': 'application/json'} 568 content = ('{"active": true,"description": "test-1-20150125","id": 1,' 569 '"is_shared": false,"ip_address": "127.0.0.1","name": null,' 570 '"online": true,"status": "online"}') 571 content = content.encode("utf-8") 572 return response(201, content, headers, None, 5, request) 573 574 575@urlmatch(scheme="http", netloc="localhost", path="/api/v4/runners/1", method="delete") 576def resp_delete_runner(url, request): 577 headers = {'content-type': 'application/json'} 578 content = ('{}') 579 content = content.encode("utf-8") 580 return response(204, content, headers, None, 5, request) 581