Commit 22b928d6 authored by xarx00's avatar xarx00
Browse files

Merge remote-tracking branch 'upstream/master' into PR-bugfix-734

parents 2501b70a 6bd19027
Loading
Loading
Loading
Loading
+9 −9
Original line number Diff line number Diff line
@@ -165,8 +165,8 @@ class Gitlab(object):
        """The API version used (4 only)."""
        return self._api_version

    @staticmethod
    def from_config(gitlab_id=None, config_files=None):
    @classmethod
    def from_config(cls, gitlab_id=None, config_files=None):
        """Create a Gitlab connection from configuration files.

        Args:
@@ -181,7 +181,7 @@ class Gitlab(object):
        """
        config = gitlab.config.GitlabConfigParser(gitlab_id=gitlab_id,
                                                  config_files=config_files)
        return Gitlab(config.url, private_token=config.private_token,
        return cls(config.url, private_token=config.private_token,
                   oauth_token=config.oauth_token,
                   ssl_verify=config.ssl_verify, timeout=config.timeout,
                   http_username=config.http_username,
+4 −4
Original line number Diff line number Diff line
@@ -133,12 +133,9 @@ def _parse_value(v):
def main():
    if "--version" in sys.argv:
        print(gitlab.__version__)
        exit(0)
        sys.exit(0)

    parser = _get_base_parser(add_help=False)
    if "--help" in sys.argv or "-h" in sys.argv:
        parser.print_help()
        exit(0)

    # This first parsing step is used to find the gitlab config to use, and
    # load the propermodule (v3 or v4) accordingly. At that point we don't have
@@ -150,6 +147,9 @@ def main():
            options.config_file
        )
    except gitlab.config.ConfigError as e:
        if "--help" in sys.argv or "-h" in sys.argv:
            parser.print_help()
            sys.exit(0)
        sys.exit(e)
    cli_module = importlib.import_module('gitlab.v%s.cli' % config.api_version)

+32 −0
Original line number Diff line number Diff line
@@ -18,7 +18,9 @@

from __future__ import print_function

import os
import pickle
import tempfile
try:
    import unittest
except ImportError:
@@ -34,6 +36,17 @@ from gitlab import * # noqa
from gitlab.v4.objects import *  # noqa


valid_config = b"""[global]
default = one
ssl_verify = true
timeout = 2

[one]
url = http://one.url
private_token = ABCDEF
"""


class TestSanitize(unittest.TestCase):
    def test_do_nothing(self):
        self.assertEqual(1, gitlab._sanitize(1))
@@ -536,3 +549,22 @@ class TestGitlab(unittest.TestCase):
            self.assertEqual(type(user), User)
            self.assertEqual(user.name, "name")
            self.assertEqual(user.id, 1)

    def _default_config(self):
        fd, temp_path = tempfile.mkstemp()
        os.write(fd, valid_config)
        os.close(fd)
        return temp_path

    def test_from_config(self):
        config_path = self._default_config()
        gitlab.Gitlab.from_config('one', [config_path])
        os.unlink(config_path)

    def test_subclass_from_config(self):
        class MyGitlab(gitlab.Gitlab):
            pass
        config_path = self._default_config()
        gl = MyGitlab.from_config('one', [config_path])
        self.assertEqual(type(gl).__name__, 'MyGitlab')
        os.unlink(config_path)