|
29 | 29 | from gitlab import exceptions as exc
|
30 | 30 | from gitlab.client import _sanitize
|
31 | 31 | from gitlab.types import GitlabList
|
32 |
| -from gitlab.v4.objects import (CurrentUser, Group, Hook, Project, |
33 |
| - ProjectAdditionalStatistics, ProjectEnvironment, |
34 |
| - ProjectIssuesStatistics, Todo, User, UserStatus) |
| 32 | +from gitlab.v4.objects import ( |
| 33 | + CurrentUser, |
| 34 | + Group, |
| 35 | + Hook, |
| 36 | + Project, |
| 37 | + ProjectAdditionalStatistics, |
| 38 | + ProjectEnvironment, |
| 39 | + ProjectIssuesStatistics, |
| 40 | + Todo, |
| 41 | + User, |
| 42 | + UserStatus, |
| 43 | +) |
35 | 44 |
|
36 | 45 | sync_gitlab = Gitlab("http://localhost", private_token="private_token", api_version=4)
|
37 | 46 | async_gitlab = AsyncGitlab(
|
|
48 | 57 | """
|
49 | 58 |
|
50 | 59 |
|
51 |
| -class TestSanitize(unittest.TestCase): |
| 60 | +class TestSanitize: |
52 | 61 | def test_do_nothing(self):
|
53 |
| - assert 1, _sanitize(1)) |
54 |
| - assert 1.5, _sanitize(1.5)) |
55 |
| - assert "foo", _sanitize("foo")) |
| 62 | + assert 1 == _sanitize(1) |
| 63 | + assert 1.5 == _sanitize(1.5) |
| 64 | + assert "foo" == _sanitize("foo") |
56 | 65 |
|
57 | 66 | def test_slash(self):
|
58 |
| - assert "foo%2Fbar", _sanitize("foo/bar")) |
| 67 | + assert "foo%2Fbar" == _sanitize("foo/bar") |
59 | 68 |
|
60 | 69 | def test_dict(self):
|
61 | 70 | source = {"url": "foo/bar", "id": 1}
|
62 | 71 | expected = {"url": "foo%2Fbar", "id": 1}
|
63 |
| - assert expected, _sanitize(source)) |
| 72 | + assert expected == _sanitize(source) |
64 | 73 |
|
65 | 74 |
|
66 | 75 | @pytest.mark.parametrize(
|
@@ -100,49 +109,51 @@ def test_invalid_auth_args(self, gitlab_class):
|
100 | 109 | )
|
101 | 110 |
|
102 | 111 | def test_private_token_auth(self, gitlab_class):
|
103 |
| - gl = gitlab_class("http://localhost", private_token="private_token", api_version="4") |
104 |
| - assert gl.private_token, "private_token") |
105 |
| - assert gl.oauth_token, None) |
106 |
| - assert gl.job_token, None) |
107 |
| - assert gl.client.auth, None) |
108 |
| - self.assertNotIn("Authorization", gl.headers) |
109 |
| - assert gl.headers["PRIVATE-TOKEN"], "private_token") |
110 |
| - self.assertNotIn("JOB-TOKEN", gl.headers) |
111 |
| - |
112 |
| - def test_oauth_token_auth(self): |
| 112 | + gl = gitlab_class( |
| 113 | + "http://localhost", private_token="private_token", api_version="4" |
| 114 | + ) |
| 115 | + assert gl.private_token == "private_token" |
| 116 | + assert gl.oauth_token is None |
| 117 | + assert gl.job_token is None |
| 118 | + assert gl.client.auth is None |
| 119 | + assert "Authorization" not in gl.headers |
| 120 | + assert gl.headers["PRIVATE-TOKEN"] == "private_token" |
| 121 | + assert "JOB-TOKEN" not in gl.headers |
| 122 | + |
| 123 | + def test_oauth_token_auth(self, gitlab_class): |
113 | 124 | gl = Gitlab("http://localhost", oauth_token="oauth_token", api_version="4")
|
114 |
| - assert gl.private_token, None) |
115 |
| - assert gl.oauth_token, "oauth_token") |
116 |
| - assert gl.job_token, None) |
117 |
| - assert gl.client.auth, None) |
118 |
| - assert gl.headers["Authorization"], "Bearer oauth_token") |
119 |
| - self.assertNotIn("PRIVATE-TOKEN", gl.headers) |
120 |
| - self.assertNotIn("JOB-TOKEN", gl.headers) |
121 |
| - |
122 |
| - def test_job_token_auth(self): |
| 125 | + assert gl.private_token is None |
| 126 | + assert gl.oauth_token == "oauth_token" |
| 127 | + assert gl.job_token is None |
| 128 | + assert gl.client.auth is None |
| 129 | + assert gl.headers["Authorization"] == "Bearer oauth_token" |
| 130 | + assert "PRIVATE-TOKEN" not in gl.headers |
| 131 | + assert "JOB-TOKEN" not in gl.headers |
| 132 | + |
| 133 | + def test_job_token_auth(self, gitlab_class): |
123 | 134 | gl = Gitlab("http://localhost", job_token="CI_JOB_TOKEN", api_version="4")
|
124 |
| - assert gl.private_token, None) |
125 |
| - assert gl.oauth_token, None) |
126 |
| - assert gl.job_token, "CI_JOB_TOKEN") |
127 |
| - assert gl.client.auth, None) |
128 |
| - self.assertNotIn("Authorization", gl.headers) |
129 |
| - self.assertNotIn("PRIVATE-TOKEN", gl.headers) |
130 |
| - assert gl.headers["JOB-TOKEN"], "CI_JOB_TOKEN") |
131 |
| - |
132 |
| - def test_http_auth(self): |
| 135 | + assert gl.private_token is None |
| 136 | + assert gl.oauth_token is None |
| 137 | + assert gl.job_token == "CI_JOB_TOKEN" |
| 138 | + assert gl.client.auth is None |
| 139 | + assert "Authorization" not in gl.headers |
| 140 | + assert "PRIVATE-TOKEN" not in gl.headers |
| 141 | + assert gl.headers["JOB-TOKEN"] == "CI_JOB_TOKEN" |
| 142 | + |
| 143 | + def test_http_auth(self, gitlab_class): |
133 | 144 | gl = Gitlab(
|
134 | 145 | "http://localhost",
|
135 | 146 | private_token="private_token",
|
136 | 147 | http_username="foo",
|
137 | 148 | http_password="bar",
|
138 | 149 | api_version="4",
|
139 | 150 | )
|
140 |
| - assert gl.private_token== "private_token" |
| 151 | + assert gl.private_token == "private_token" |
141 | 152 | assert gl.oauth_token is None
|
142 |
| - assert gl.job_token is None |
| 153 | + assert gl.job_token is None |
143 | 154 | assert isinstance(gl.client.auth, httpx.auth.BasicAuth)
|
144 |
| - assert gl.headers["PRIVATE-TOKEN"], "private_token") |
145 |
| - self.assertNotIn("Authorization", gl.headers) |
| 155 | + assert gl.headers["PRIVATE-TOKEN"] == "private_token" |
| 156 | + assert "Authorization" not in gl.headers |
146 | 157 |
|
147 | 158 |
|
148 | 159 | @pytest.mark.parametrize(
|
|
0 commit comments