|
1 | 1 | import re |
2 | 2 | from pytest_httpserver import HTTPServer |
3 | 3 | from pytest import LogCaptureFixture, raises |
4 | | -from modules.git_clients import GitClientFactory |
| 4 | +from modules.git_clients import GitClientFactory, GitClient, check_input, check_input_empty |
5 | 5 | from tests.test_utils import get_url_root, expect_request |
6 | 6 | from requests import exceptions |
| 7 | +from github import GithubException |
| 8 | +from gitlab import GitlabError |
| 9 | + |
| 10 | + |
| 11 | +def test_interface(): |
| 12 | + client = GitClient() |
| 13 | + client.get_login_or_token() |
| 14 | + client.get_password() |
| 15 | + client.get_url() |
| 16 | + client.get_repos('org') |
| 17 | + client.has_repo('org', 'repo') |
| 18 | + client.get_branches('org', 'repo') |
| 19 | + client.get_tags('org', 'repo') |
| 20 | + client.get_repo_description('org', 'repo') |
| 21 | + client.get_repo_clone_url('org', 'repo') |
| 22 | + client.create_repo('org', 'repo') |
| 23 | + client.create_repo('org', 'repo', 'description') |
| 24 | + |
| 25 | + |
| 26 | +def test_check_inputs(): |
| 27 | + with raises(ValueError, match='not empty'): |
| 28 | + check_input_empty('value', 'not empty') |
| 29 | + with raises(ValueError, match='empty'): |
| 30 | + check_input('', 'empty') |
| 31 | + with raises(ValueError, match='empty'): |
| 32 | + check_input(None, 'empty') # noqa: python:S5655 |
7 | 33 |
|
8 | 34 |
|
9 | 35 | def test_type_undefined(caplog: LogCaptureFixture): |
@@ -77,6 +103,21 @@ def test_github_empty_branches_tags(httpserver: HTTPServer, caplog: LogCaptureFi |
77 | 103 | assert 0 == len(github.get_tags('spring-projects', 'spring-petclinic')) |
78 | 104 |
|
79 | 105 |
|
| 106 | +def test_github_errors_has_repo(httpserver: HTTPServer, caplog: LogCaptureFixture): |
| 107 | + expect_request(httpserver, 'github', '/users/spring-projects') |
| 108 | + httpserver.expect_request('/repos/spring-projects/spring-petclinic').respond_with_data(status=442) |
| 109 | + github = GitClientFactory.create_client(get_url_root(httpserver), 'github', 'ghu_xxxx') |
| 110 | + with raises(GithubException, match='442'): |
| 111 | + github.has_repo('spring-projects', 'spring-petclinic') |
| 112 | + |
| 113 | + |
| 114 | +def test_github_errors_create_repo(httpserver: HTTPServer, caplog: LogCaptureFixture): |
| 115 | + httpserver.expect_request('/orgs/spring-projects').respond_with_data(status=442) |
| 116 | + github = GitClientFactory.create_client(get_url_root(httpserver), 'github', 'ghu_xxxx') |
| 117 | + with raises(GithubException, match='442'): |
| 118 | + github.create_repo('spring-projects', 'spring-petclinic', 'fake') |
| 119 | + |
| 120 | + |
80 | 121 | def test_gitea_proxy(httpserver: HTTPServer, caplog: LogCaptureFixture): |
81 | 122 | gitea = GitClientFactory.create_client('https://fake.url.dev', 'gitea', 'foo', 'bar', proxy=get_url_root(httpserver)) |
82 | 123 |
|
@@ -259,6 +300,13 @@ def test_bitbucket_empty_branches_tags(httpserver: HTTPServer, caplog: LogCaptur |
259 | 300 | assert 0 == len(bitbucket.get_tags('MyOrg', 'spring-ai-examples')) |
260 | 301 |
|
261 | 302 |
|
| 303 | +def test_bitbucket_bad_clone_url_http(httpserver: HTTPServer, caplog: LogCaptureFixture): |
| 304 | + expect_request(httpserver, 'bitbucket', '/rest/api/1.0/projects/MyOrg/repos/spring-ai-examples-no-clone-url-http') |
| 305 | + bitbucket = GitClientFactory.create_client(get_url_root(httpserver), 'bitbucket', 'fake_token') |
| 306 | + with raises(ValueError, match='Cannot not found http clone link'): |
| 307 | + bitbucket.get_repo_clone_url('MyOrg', 'spring-ai-examples-no-clone-url-http') |
| 308 | + |
| 309 | + |
262 | 310 | def test_gitlab_proxy(httpserver: HTTPServer, caplog: LogCaptureFixture): |
263 | 311 | gitlab = GitClientFactory.create_client('https://fake.url.dev', 'gitlab', 'fake_token', proxy=get_url_root(httpserver)) |
264 | 312 |
|
@@ -327,6 +375,13 @@ def test_gitlab_empty_branches_tags(httpserver: HTTPServer, caplog: LogCaptureFi |
327 | 375 | assert 0 == len(gitlab.get_tags('axel3rd', 'spring-petclinic')) |
328 | 376 |
|
329 | 377 |
|
| 378 | +def test_gitlab_errors_has_repo(httpserver: HTTPServer, caplog: LogCaptureFixture): |
| 379 | + httpserver.expect_request('/api/v4/projects/axel3rd/spring-petclinic').respond_with_data(status=442) |
| 380 | + gitlab = GitClientFactory.create_client(get_url_root(httpserver), 'gitlab', 'glpat-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx') |
| 381 | + with raises(GitlabError, match='442'): |
| 382 | + gitlab.has_repo('axel3rd', 'spring-petclinic') |
| 383 | + |
| 384 | + |
330 | 385 | def test_gerrit_proxy(httpserver: HTTPServer, caplog: LogCaptureFixture): |
331 | 386 | gerrit = GitClientFactory.create_client('https://fake.url.dev', 'gerrit', 'foo', 'bar', proxy=get_url_root(httpserver)) |
332 | 387 |
|
|
0 commit comments