diff --git a/src/centpkg/api/lookaside.py b/src/centpkg/api/lookaside.py new file mode 100644 index 0000000..dab5283 --- /dev/null +++ b/src/centpkg/api/lookaside.py @@ -0,0 +1,27 @@ +# Copyright (c) 2020 - Red Hat Inc. +# +# This program is free software; you can redistribute it and/or modify it +# under the terms of the GNU General Public License as published by the +# Free Software Foundation; either version 2 of the License, or (at your +# option) any later version. See http://www.gnu.org/copyleft/gpl.html for +# the full text of the license. + + +"""Interact with the Fedora lookaside cache + +We need to override the pyrpkg.lookasidecache module to handle our custom +download path. +""" + + +from pyrpkg.lookaside import CGILookasideCache + + +class CentOSLookasideCache(CGILookasideCache): + """ + Centos pkg cache rpkg subclass. + """ + def __init__(self, *args, **kwargs): + super(CentOSLookasideCache, self).__init__(*args, **kwargs) + self.download_path = ('%(name)s/%(branch)s/%(hash)s') + diff --git a/src/centpkg/cli/__init__.py b/src/centpkg/cli/__init__.py index 4c8761b..d60c342 100644 --- a/src/centpkg/cli/__init__.py +++ b/src/centpkg/cli/__init__.py @@ -9,7 +9,7 @@ import pyrpkg # import pyrpkg.cli import centpkg.api.cli -from . import lookaside +from ..api import lookaside class Commands(pyrpkg.Commands): diff --git a/src/centpkg/cli/lookaside.py b/src/centpkg/cli/lookaside.py deleted file mode 100644 index 576b290..0000000 --- a/src/centpkg/cli/lookaside.py +++ /dev/null @@ -1,26 +0,0 @@ -# Copyright (c) 2020 - Red Hat Inc. -# -# This program is free software; you can redistribute it and/or modify it -# under the terms of the GNU General Public License as published by the -# Free Software Foundation; either version 2 of the License, or (at your -# option) any later version. See http://www.gnu.org/copyleft/gpl.html for -# the full text of the license. - - -"""Interact with the Fedora lookaside cache - -We need to override the pyrpkg.lookasidecache module to handle our custom -download path. -""" - - -from pyrpkg.lookaside import CGILookasideCache - - -class CentOSLookasideCache(CGILookasideCache): - """ - Centos pkg cache rpkg subclass. - """ - def __init__(self, *args, **kwargs): - super(CentOSLookasideCache, self).__init__(*args, **kwargs) - self.download_path = ('%(name)s/%(branch)s/%(hash)s') diff --git a/tests/conftest.py b/tests/conftest.py index f39ab84..5f415c9 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -1,6 +1,13 @@ import sys import os +import pytest + cwd = os.path.dirname(os.path.realpath(__file__)) sys.path.append(f'{cwd}/../src/') + + +@pytest.fixture +def fixtures_dir(): + return f'{cwd}/fixtures' diff --git a/tests/fixtures/centpkg.conf b/tests/fixtures/centpkg.conf new file mode 100644 index 0000000..853b63f --- /dev/null +++ b/tests/fixtures/centpkg.conf @@ -0,0 +1,13 @@ +[centpkg] +lookaside = https://git.stg.centos.org/sources +lookasidehash = sha1 +lookaside_cgi = https://git.stg.centos.org/sources/upload.cgi +lookaside_request_params = branch +distgit_namespaced = True +distgit_namespaces = rpms +gitbaseurl = https://%(user)s@git.stg.centos.org/%(repo)s.git +anongiturl = https://git.stg.centos.org/%(repo)s +branchre = .+\d$|.+\d-.+|master$ +kojiprofile = cbs +build_client = cbs +clone_config = \ No newline at end of file diff --git a/tests/test_api_cli.py b/tests/test_api_cli.py new file mode 100644 index 0000000..3fe0045 --- /dev/null +++ b/tests/test_api_cli.py @@ -0,0 +1,11 @@ +import configparser +from centpkg.api import cli + + +def test_cli_name(fixtures_dir): + config = configparser.ConfigParser() + config.read(f'{fixtures_dir}/centpkg.conf') + + assert cli.CentPkgCli(config).name == 'centpkg' + assert cli.CentPkgCli(config, name='foobar').name == 'foobar' + diff --git a/tests/test_api_lookaside.py b/tests/test_api_lookaside.py new file mode 100644 index 0000000..fa259d6 --- /dev/null +++ b/tests/test_api_lookaside.py @@ -0,0 +1,15 @@ +import configparser +from centpkg.api import lookaside + + +def test_lookaside_download_url(fixtures_dir): + config = configparser.ConfigParser() + config.read(f'{fixtures_dir}/centpkg.conf') + section = config.sections()[0] + _lookaside = lookaside.CentOSLookasideCache('md5', + config[section]['lookaside'], + config[section]['lookaside_cgi']) + + expected = f'{ config[section]["lookaside"]}/name/dev/hash' + actual = _lookaside.get_download_url('name', 'fname', 'hash', branch='dev') + assert expected == actual