Skip to content

Commit

Permalink
Refactor RepoInfo to use default values
Browse files Browse the repository at this point in the history
Signed-off-by: Luiz Carvalho <lucarval@redhat.com>
  • Loading branch information
lcarva committed Jul 31, 2017
1 parent c4294af commit 3aa2d45
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 7 deletions.
10 changes: 9 additions & 1 deletion osbs/repo_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,15 @@
logger = logging.getLogger(__name__)


RepoInfo = namedtuple('RepoInfo', 'dockerfile_parser, configuration, additional_tags')
class RepoInfo(object):
"""
Aggregator for different aspects of the repository.
"""

def __init__(self, dockerfile_parser=None, configuration=None, additional_tags=None):
self.dockerfile_parser = dockerfile_parser
self.configuration = configuration or RepoConfiguration()
self.additional_tags = additional_tags or AdditionalTagsConfig()


class RepoConfiguration(object):
Expand Down
4 changes: 2 additions & 2 deletions tests/build_/test_arrangements.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
ORCHESTRATOR_INNER_TEMPLATE,
WORKER_INNER_TEMPLATE)
from osbs import utils
from osbs.repo_utils import RepoInfo, RepoConfiguration, AdditionalTagsConfig
from osbs.repo_utils import RepoInfo
from tests.constants import (TEST_GIT_URI,
TEST_GIT_REF,
TEST_GIT_BRANCH,
Expand Down Expand Up @@ -46,7 +46,7 @@ class MockParser(object):
(flexmock(utils)
.should_receive('get_repo_info')
.with_args(TEST_GIT_URI, TEST_GIT_REF, git_branch=TEST_GIT_BRANCH)
.and_return(RepoInfo(MockParser(), RepoConfiguration(), AdditionalTagsConfig())))
.and_return(RepoInfo(MockParser())))

# Trick create_orchestrator_build into return the *request* JSON
flexmock(OSBS, _create_build_config_and_build=request_as_response)
Expand Down
2 changes: 1 addition & 1 deletion tests/build_/test_build_request.py
Original file line number Diff line number Diff line change
Expand Up @@ -1766,7 +1766,7 @@ class MockDfParser(object):
.should_receive('is_autorebuild_enabled')
.and_return(autorebuild_enabled))

repo_info = RepoInfo(MockDfParser(), RepoConfiguration(), AdditionalTagsConfig())
repo_info = RepoInfo(MockDfParser())

build_request_kwargs = get_sample_prod_params()
base_image = build_request_kwargs['base_image']
Expand Down
4 changes: 2 additions & 2 deletions tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
ORCHESTRATOR_CUSTOMIZE_CONF,
BUILD_TYPE_WORKER, BUILD_TYPE_ORCHESTRATOR)
from osbs import utils
from osbs.repo_utils import RepoInfo, RepoConfiguration, AdditionalTagsConfig
from osbs.repo_utils import RepoInfo

from tests.constants import (TEST_ARCH, TEST_BUILD, TEST_COMPONENT, TEST_GIT_BRANCH, TEST_GIT_REF,
TEST_GIT_URI, TEST_TARGET, TEST_USER, INPUTS_PATH,
Expand Down Expand Up @@ -87,7 +87,7 @@ class TestOSBS(object):

def mock_repo_info(self, mock_df_parser=None):
mock_df_parser = mock_df_parser or MockDfParser()
return RepoInfo(mock_df_parser, RepoConfiguration(), AdditionalTagsConfig())
return RepoInfo(mock_df_parser)

def test_osbsapi_wrapper(self):
"""
Expand Down
22 changes: 21 additions & 1 deletion tests/test_repo_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,34 @@
of the BSD license. See the LICENSE file for details.
"""

from flexmock import flexmock
from osbs.constants import REPO_CONFIG_FILE, ADDITIONAL_TAGS_FILE
from osbs.repo_utils import RepoConfiguration, AdditionalTagsConfig
from osbs.repo_utils import RepoInfo, RepoConfiguration, AdditionalTagsConfig
from textwrap import dedent

import os
import pytest


class TestRepoInfo(object):

def test_default_params(self):
repo_info = RepoInfo()
assert repo_info.dockerfile_parser is None
assert isinstance(repo_info.configuration, RepoConfiguration)
assert isinstance(repo_info.additional_tags, AdditionalTagsConfig)

def test_explicit_params(self):
df_parser = flexmock()
configuration = RepoConfiguration()
tags_config = AdditionalTagsConfig()

repo_info = RepoInfo(df_parser, configuration, tags_config)
assert repo_info.dockerfile_parser is df_parser
assert repo_info.configuration is configuration
assert repo_info.additional_tags is tags_config


class TestRepoConfiguration(object):

def test_default_values(self):
Expand Down

0 comments on commit 3aa2d45

Please sign in to comment.