|
| 1 | +#!/usr/bin/env python |
| 2 | + |
| 3 | +import os |
| 4 | +import sys |
| 5 | +import logging |
| 6 | + |
| 7 | +import pytest |
| 8 | + |
| 9 | +################################################################################# |
| 10 | +# Enable logging |
| 11 | + |
| 12 | +log = logging.getLogger('test.gitbucket') |
| 13 | + |
| 14 | +################################################################################# |
| 15 | + |
| 16 | +from tests.helpers import GitRepoTestCase |
| 17 | + |
| 18 | +from git_repo.services.service import gitbucket |
| 19 | +from git_repo.exceptions import ResourceExistsError, ResourceNotFoundError, ResourceError |
| 20 | + |
| 21 | + |
| 22 | +class Test_Gitbucket(GitRepoTestCase): |
| 23 | + log = log |
| 24 | + namespace = "user" |
| 25 | + |
| 26 | + @property |
| 27 | + def local_namespace(self): |
| 28 | + return 'user' |
| 29 | + |
| 30 | + def get_service(self): |
| 31 | + return gitbucket.GitbucketService(c={ |
| 32 | + '__name__': 'gitrepo "gitbucket-test"', |
| 33 | + 'fqdn': "localhost", |
| 34 | + 'port': "8080", |
| 35 | + 'scheme': "http", |
| 36 | + 'insecure': 'yes', |
| 37 | + 'token': os.environ['GITBUCKET_TOKEN'] |
| 38 | + }) |
| 39 | + |
| 40 | + def get_requests_session(self): |
| 41 | + return self.service.gh._session |
| 42 | + |
| 43 | + def test_00_fork(self): |
| 44 | + self.action_fork(local_namespace=self.local_namespace, |
| 45 | + remote_namespace='root', |
| 46 | + repository='repo') |
| 47 | + |
| 48 | + def test_01_create__new(self): |
| 49 | + self.action_create(namespace=self.local_namespace, |
| 50 | + repository='foobar') |
| 51 | + |
| 52 | + def test_01_create__already_exists(self): |
| 53 | + with pytest.raises(ResourceExistsError): |
| 54 | + self.action_create(namespace=self.local_namespace, |
| 55 | + repository='git-repo') |
| 56 | + |
| 57 | + def test_01_create_organization__new(self): |
| 58 | + self.action_create(namespace='group', |
| 59 | + repository='foobar') |
| 60 | + |
| 61 | + def test_01_create_organization__already_exists(self): |
| 62 | + with pytest.raises(ResourceExistsError): |
| 63 | + self.action_create(namespace='group', |
| 64 | + repository='git-repo') |
| 65 | + |
| 66 | + |
| 67 | + def test_02_delete(self): |
| 68 | + self.action_delete(namespace=self.local_namespace, |
| 69 | + repository='foobar') |
| 70 | + |
| 71 | + def test_03_delete_nouser(self): |
| 72 | + with pytest.raises(NotImplementedError): |
| 73 | + self.action_delete(repository='github3.py') |
| 74 | + |
| 75 | + def test_04_clone(self): |
| 76 | + self.action_clone(namespace='root', |
| 77 | + repository='repo') |
| 78 | + |
| 79 | + def test_05_add(self): |
| 80 | + self.action_add(namespace='root', |
| 81 | + repository='repo') |
| 82 | + |
| 83 | + def test_06_add__name(self): |
| 84 | + self.action_add(namespace='root', |
| 85 | + repository='repo', |
| 86 | + name='test0r') |
| 87 | + |
| 88 | + def test_07_add__alone(self): |
| 89 | + self.action_add(namespace='root', |
| 90 | + repository='repo', |
| 91 | + alone=True) |
| 92 | + |
| 93 | + def test_08_add__alone_name(self): |
| 94 | + self.action_add(namespace='root', |
| 95 | + repository='repo', |
| 96 | + name='test0r', |
| 97 | + alone=True) |
| 98 | + |
| 99 | + def test_09_add__default(self): |
| 100 | + self.action_add(namespace='root', |
| 101 | + repository='repo', |
| 102 | + tracking='gitbucket') |
| 103 | + |
| 104 | + def test_10_add__default_name(self): |
| 105 | + self.action_add(namespace='root', |
| 106 | + repository='repo', |
| 107 | + name='test0r', |
| 108 | + tracking='gitbucket') |
| 109 | + |
| 110 | + def test_11_add__alone_default(self): |
| 111 | + self.action_add(namespace='root', |
| 112 | + repository='repo', |
| 113 | + alone=True, |
| 114 | + tracking='gitbucket') |
| 115 | + |
| 116 | + def test_12_add__alone_default_name(self): |
| 117 | + self.action_add(namespace='root', |
| 118 | + repository='repo', |
| 119 | + alone=True, |
| 120 | + name='test0r', |
| 121 | + tracking='gitbucket') |
| 122 | + |
| 123 | + def test_13_gist_list(self): |
| 124 | + with pytest.raises(NotImplementedError): |
| 125 | + g_list = [] |
| 126 | + self.action_gist_list(gist_list_data=g_list) |
| 127 | + |
| 128 | + def test_14_gist_list_with_gist(self): |
| 129 | + with pytest.raises(NotImplementedError): |
| 130 | + g_list = [ |
| 131 | + "C 2542 i2c_scanner.c" |
| 132 | + ] |
| 133 | + self.action_gist_list(gist='10118958') |
| 134 | + |
| 135 | + def test_15_gist_list_with_bad_gist(self): |
| 136 | + with pytest.raises(NotImplementedError): |
| 137 | + self.action_gist_list(gist='42') |
| 138 | + |
| 139 | + def test_16_gist_clone_with_gist(self): |
| 140 | + with pytest.raises(NotImplementedError): |
| 141 | + self.action_gist_clone(gist='https://gist.github.com/10118958') |
| 142 | + |
| 143 | + def test_17_gist_fetch_with_gist(self): |
| 144 | + with pytest.raises(NotImplementedError): |
| 145 | + content = self.action_gist_fetch(gist='4170462', gist_file=None) |
| 146 | + assert content == '\n'.join([ |
| 147 | + 'diff --git a/platform/io.c b/platform/io.c', |
| 148 | + 'index 209666a..0a6c2cf 100644', |
| 149 | + '--- a/platform/io.c', |
| 150 | + '+++ b/platform/io.c', |
| 151 | + '@@ -24,6 +24,16 @@', |
| 152 | + ' #if defined(__FreeBSD__)', |
| 153 | + ' #define IO_BSD', |
| 154 | + ' #elif defined(__APPLE__)', |
| 155 | + '+size_t strnlen(const char *s, size_t maxlen) ', |
| 156 | + '+{ ', |
| 157 | + '+ size_t len; ', |
| 158 | + '+ ', |
| 159 | + '+ for (len = 0; len < maxlen; len++, s++) { ', |
| 160 | + '+ if (!*s) ', |
| 161 | + '+ break; ', |
| 162 | + '+ } ', |
| 163 | + '+ return (len); ', |
| 164 | + '+} ', |
| 165 | + ' #define IO_BSD', |
| 166 | + ' #define IO_USE_SELECT', |
| 167 | + ' #elif defined(WIN32)', |
| 168 | + ]) |
| 169 | + |
| 170 | + def test_18_gist_fetch_with_bad_gist(self): |
| 171 | + with pytest.raises(NotImplementedError): |
| 172 | + self.action_gist_fetch(gist='69', gist_file=None) |
| 173 | + |
| 174 | + def test_19_gist_fetch_with_gist_file(self): |
| 175 | + with pytest.raises(NotImplementedError): |
| 176 | + content = self.action_gist_fetch(gist='4170462', gist_file='freevpn0.029__platform__io.patch') |
| 177 | + assert content == '\n'.join([ |
| 178 | + 'diff --git a/platform/io.c b/platform/io.c', |
| 179 | + 'index 209666a..0a6c2cf 100644', |
| 180 | + '--- a/platform/io.c', |
| 181 | + '+++ b/platform/io.c', |
| 182 | + '@@ -24,6 +24,16 @@', |
| 183 | + ' #if defined(__FreeBSD__)', |
| 184 | + ' #define IO_BSD', |
| 185 | + ' #elif defined(__APPLE__)', |
| 186 | + '+size_t strnlen(const char *s, size_t maxlen) ', |
| 187 | + '+{ ', |
| 188 | + '+ size_t len; ', |
| 189 | + '+ ', |
| 190 | + '+ for (len = 0; len < maxlen; len++, s++) { ', |
| 191 | + '+ if (!*s) ', |
| 192 | + '+ break; ', |
| 193 | + '+ } ', |
| 194 | + '+ return (len); ', |
| 195 | + '+} ', |
| 196 | + ' #define IO_BSD', |
| 197 | + ' #define IO_USE_SELECT', |
| 198 | + ' #elif defined(WIN32)', |
| 199 | + ]) |
| 200 | + |
| 201 | + def test_20_gist_fetch_with_bad_gist_file(self): |
| 202 | + with pytest.raises(NotImplementedError): |
| 203 | + self.action_gist_fetch(gist='4170462', gist_file='failed') |
| 204 | + |
| 205 | + def test_21_gist_create_gist_file(self, datadir): |
| 206 | + with pytest.raises(NotImplementedError): |
| 207 | + test_file = str(datadir[ 'random-fortune-1.txt' ]) |
| 208 | + self.action_gist_create(description='this is a test.', |
| 209 | + gist_files=[ test_file ], |
| 210 | + secret=False) |
| 211 | + |
| 212 | + def test_22_gist_create_gist_file_list(self, datadir): |
| 213 | + with pytest.raises(NotImplementedError): |
| 214 | + test_files = [ |
| 215 | + str(datadir[ 'random-fortune-1.txt' ]), |
| 216 | + str(datadir[ 'random-fortune-2.txt' ]), |
| 217 | + str(datadir[ 'random-fortune-3.txt' ]), |
| 218 | + str(datadir[ 'random-fortune-4.txt' ]), |
| 219 | + ] |
| 220 | + self.action_gist_create(description='this is a test.', |
| 221 | + gist_files=test_files, |
| 222 | + secret=False) |
| 223 | + |
| 224 | + def test_23_gist_create_gist_dir(self, datadir): |
| 225 | + with pytest.raises(NotImplementedError): |
| 226 | + test_dir = [ |
| 227 | + str(datadir[ 'a_directory' ]), |
| 228 | + ] |
| 229 | + self.action_gist_create(description='this is a test.', |
| 230 | + gist_files=test_dir, |
| 231 | + secret=False) |
| 232 | + |
| 233 | + def test_24_gist_create_gist_file(self, datadir): |
| 234 | + with pytest.raises(NotImplementedError): |
| 235 | + test_file = str(datadir[ 'random-fortune-1.txt' ]) |
| 236 | + self.action_gist_create(description='this is a secret test.', |
| 237 | + gist_files=[ test_file ], |
| 238 | + secret=True) |
| 239 | + |
| 240 | + def test_25_gist_create_gist_file_list(self, datadir): |
| 241 | + with pytest.raises(NotImplementedError): |
| 242 | + test_files = [ |
| 243 | + str(datadir[ 'random-fortune-1.txt' ]), |
| 244 | + str(datadir[ 'random-fortune-2.txt' ]), |
| 245 | + str(datadir[ 'random-fortune-3.txt' ]), |
| 246 | + str(datadir[ 'random-fortune-4.txt' ]), |
| 247 | + ] |
| 248 | + self.action_gist_create(description='this is a secret test.', |
| 249 | + gist_files=test_files, |
| 250 | + secret=True) |
| 251 | + |
| 252 | + def test_26_gist_create_gist_dir(self, datadir): |
| 253 | + with pytest.raises(NotImplementedError): |
| 254 | + test_dir = [ |
| 255 | + str(datadir[ 'a_directory' ]), |
| 256 | + ] |
| 257 | + self.action_gist_create(description='this is a secret test.', |
| 258 | + gist_files=test_dir, |
| 259 | + secret=True) |
| 260 | + |
| 261 | + def test_27_gist_delete(self): |
| 262 | + with pytest.raises(NotImplementedError): |
| 263 | + self.action_gist_delete(gist='7dcc495dda5e684cba94940a01f60e95') |
| 264 | + |
| 265 | + def test_28_gist_delete__not_exist(self): |
| 266 | + with pytest.raises(NotImplementedError): |
| 267 | + self.action_gist_delete(gist='7dcc495dda5e684cba94940a01f60e95') |
| 268 | + |
| 269 | + def test_29_gist_create_gist__file_not_exist(self, datadir): |
| 270 | + with pytest.raises(NotImplementedError): |
| 271 | + test_dir = [ |
| 272 | + 'does_not_exists' |
| 273 | + ] |
| 274 | + self.action_gist_create(description='this is a secret test.', |
| 275 | + gist_files=test_dir, |
| 276 | + secret=False) |
| 277 | + |
| 278 | + @pytest.mark.skip |
| 279 | + def test_30_request_list(self): |
| 280 | + self.action_request_list( |
| 281 | + namespace='root', |
| 282 | + repository='repo', |
| 283 | + rq_list_data=[ |
| 284 | + '{}\t{:<60}\t{}', |
| 285 | + ('id', 'title', 'URL'), |
| 286 | + ('3', 'docs for fqdn > url', 'https://github.com/guyzmo/git-repo/pull/3'), |
| 287 | + ('2', 'prefer gitrepo.<target>.token > privatekey, docs', 'https://github.com/guyzmo/git-repo/pull/2'), |
| 288 | + ]) |
| 289 | + |
| 290 | + @pytest.mark.skip |
| 291 | + def test_31_request_fetch(self): |
| 292 | + self.action_request_fetch(namespace='root', |
| 293 | + repository='repo', |
| 294 | + request='1', |
| 295 | + remote_branch='pull', |
| 296 | + local_branch='requests/gitbucket') |
| 297 | + |
| 298 | + @pytest.mark.skip |
| 299 | + def test_31_request_fetch__bad_request(self): |
| 300 | + with pytest.raises(ResourceNotFoundError): |
| 301 | + self.action_request_fetch(namespace='guyzmo', |
| 302 | + repository='git-repo', |
| 303 | + request='1', |
| 304 | + remote_branch='pull', |
| 305 | + local_branch='requests/github', |
| 306 | + fail=True) |
| 307 | + |
| 308 | + @pytest.mark.skip |
| 309 | + def test_32_request_create(self): |
| 310 | + r = self.action_request_create(namespace=self.namespace, |
| 311 | + repository='test_create_requests', |
| 312 | + source_branch='pr-test', |
| 313 | + target_branch='master', |
| 314 | + title='PR test', |
| 315 | + description='PR description') |
| 316 | + assert r == { |
| 317 | + 'local': 'pr-test', |
| 318 | + 'ref': 1, |
| 319 | + 'remote': 'master', |
| 320 | + 'url': 'https://github.com/{}/test_create_requests/pull/1'.format(self.namespace), |
| 321 | + } |
| 322 | + |
| 323 | + @pytest.mark.skip |
| 324 | + def test_32_request_create__bad_branch(self): |
| 325 | + with pytest.raises(ResourceError): |
| 326 | + self.action_request_create(namespace=self.namespace, |
| 327 | + repository='test_create_requests', |
| 328 | + source_branch='does_not_exists', |
| 329 | + target_branch='master', |
| 330 | + title='PR test', |
| 331 | + description='PR description') |
| 332 | + |
| 333 | + @pytest.mark.skip |
| 334 | + def test_32_request_create__bad_repo(self): |
| 335 | + with pytest.raises(ResourceNotFoundError): |
| 336 | + r = self.action_request_create(namespace=self.namespace, |
| 337 | + repository='does_not_exists', |
| 338 | + source_branch='pr-test', |
| 339 | + target_branch='master', |
| 340 | + title='PR test', |
| 341 | + description='PR description') |
| 342 | + |
| 343 | + @pytest.mark.skip |
| 344 | + def test_32_request_create__guess_branch(self): |
| 345 | + r = self.action_request_create(namespace=self.namespace, |
| 346 | + repository='test_create_requests', |
| 347 | + source_branch=None, |
| 348 | + target_branch=None, |
| 349 | + title='PR test', |
| 350 | + description='PR description') |
| 351 | + |
| 352 | + def test_33_open(self): |
| 353 | + self.action_open(namespace='root', |
| 354 | + repository='repo') |
| 355 | + |
| 356 | + @pytest.mark.skip |
| 357 | + def test_34_list__short(self, caplog): |
| 358 | + projects = self.action_list(namespace='group') |
| 359 | + assert projects == ['{}', ('Total repositories: 1',), ['git-repo-test/git-repo']] |
| 360 | + assert 'GET https://api.github.com/users/git-repo-test/repos' in caplog.text |
| 361 | + |
| 362 | + @pytest.mark.skip |
| 363 | + def test_34_list__long(self, caplog): |
| 364 | + projects = self.action_list(namespace='git-repo-test', _long=True) |
| 365 | + assert projects == ['{}\t{}\t{}\t{}\t{}\t{}\t{}\t{}\t{}\t{:12}\t{}', |
| 366 | + ['Status', 'Commits', 'Reqs', 'Issues', 'Forks', 'Coders', 'Watch', 'Likes', 'Lang', 'Modif', 'Name'], |
| 367 | + ['F ', '92', '0', '0', '0', '1', '0', '0', 'Python', 'Mar 30 2016', 'git-repo-test/git-repo']] |
| 368 | + assert 'GET https://api.github.com/users/git-repo-test/repos' in caplog.text |
| 369 | + |
| 370 | + |
0 commit comments