| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -165,8 +165,8 @@ def api_version(self): | |||
| 165 | 165 | """The API version used (4 only).""" | |
| 166 | 166 | return self._api_version | |
| 167 | 167 | ||
| 168 | - @staticmethod | ||
| 169 | - def from_config(gitlab_id=None, config_files=None): | ||
| 168 | + @classmethod | ||
| 169 | + def from_config(cls, gitlab_id=None, config_files=None): | ||
| 170 | 170 | """Create a Gitlab connection from configuration files. | |
| 171 | 171 | ||
| 172 | 172 | Args: | |
@@ -181,13 +181,13 @@ def from_config(gitlab_id=None, config_files=None): | |||
| 181 | 181 | """ | |
| 182 | 182 | config = gitlab.config.GitlabConfigParser(gitlab_id=gitlab_id, | |
| 183 | 183 | config_files=config_files) | |
| 184 | - return Gitlab(config.url, private_token=config.private_token, | ||
| 185 | - oauth_token=config.oauth_token, | ||
| 186 | - ssl_verify=config.ssl_verify, timeout=config.timeout, | ||
| 187 | - http_username=config.http_username, | ||
| 188 | - http_password=config.http_password, | ||
| 189 | - api_version=config.api_version, | ||
| 190 | - per_page=config.per_page) | ||
| 184 | + return cls(config.url, private_token=config.private_token, | ||
| 185 | + oauth_token=config.oauth_token, | ||
| 186 | + ssl_verify=config.ssl_verify, timeout=config.timeout, | ||
| 187 | + http_username=config.http_username, | ||
| 188 | + http_password=config.http_password, | ||
| 189 | + api_version=config.api_version, | ||
| 190 | + per_page=config.per_page) | ||
| 191 | 191 | ||
| 192 | 192 | def auth(self): | |
| 193 | 193 | """Performs an authentication. | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -18,7 +18,9 @@ | |||
| 18 | 18 | ||
| 19 | 19 | from __future__ import print_function | |
| 20 | 20 | ||
| 21 | + import os | ||
| 21 | 22 | import pickle | |
| 23 | + import tempfile | ||
| 22 | 24 | try: | |
| 23 | 25 | import unittest | |
| 24 | 26 | except ImportError: | |
@@ -34,6 +36,17 @@ | |||
| 34 | 36 | from gitlab.v4.objects import * # noqa | |
| 35 | 37 | ||
| 36 | 38 | ||
| 39 | + valid_config = b"""[global] | ||
| 40 | + default = one | ||
| 41 | + ssl_verify = true | ||
| 42 | + timeout = 2 | ||
| 43 | + | ||
| 44 | + [one] | ||
| 45 | + url = http://one.url | ||
| 46 | + private_token = ABCDEF | ||
| 47 | + """ | ||
| 48 | + | ||
| 49 | + | ||
| 37 | 50 | class TestSanitize(unittest.TestCase): | |
| 38 | 51 | def test_do_nothing(self): | |
| 39 | 52 | self.assertEqual(1, gitlab._sanitize(1)) | |
@@ -536,3 +549,22 @@ def resp_get_user(url, request): | |||
| 536 | 549 | self.assertEqual(type(user), User) | |
| 537 | 550 | self.assertEqual(user.name, "name") | |
| 538 | 551 | self.assertEqual(user.id, 1) | |
| 552 | + | ||
| 553 | + def _default_config(self): | ||
| 554 | + fd, temp_path = tempfile.mkstemp() | ||
| 555 | + os.write(fd, valid_config) | ||
| 556 | + os.close(fd) | ||
| 557 | + return temp_path | ||
| 558 | + | ||
| 559 | + def test_from_config(self): | ||
| 560 | + config_path = self._default_config() | ||
| 561 | + gitlab.Gitlab.from_config('one', [config_path]) | ||
| 562 | + os.unlink(config_path) | ||
| 563 | + | ||
| 564 | + def test_subclass_from_config(self): | ||
| 565 | + class MyGitlab(gitlab.Gitlab): | ||
| 566 | + pass | ||
| 567 | + config_path = self._default_config() | ||
| 568 | + gl = MyGitlab.from_config('one', [config_path]) | ||
| 569 | + self.assertEqual(type(gl).__name__, 'MyGitlab') | ||
| 570 | + os.unlink(config_path) | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments