Skip to content

Commit

Permalink
Merge 660690a into 6064689
Browse files Browse the repository at this point in the history
  • Loading branch information
robdennis committed Oct 2, 2018
2 parents 6064689 + 660690a commit 94c3715
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 2 deletions.
20 changes: 19 additions & 1 deletion ship_it/manifest.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ def get_args_and_flags(self):
cfg_args, cfg_flags = self.get_config_args_and_flags()
args.extend(cfg_args)
flags.extend(cfg_flags)
extra_args = self.get_extra_files_args()
args.extend(extra_args)
flags.extend(self.get_dependency_flags())
flags.extend(self.get_exclude_flags())

Expand All @@ -87,6 +89,23 @@ def get_config_args_and_flags(self):

return args, flags

def get_extra_files_args(self):
args = []
if not self.contents.get('extra_files'):
return args

for remote_path, local_path in self.contents['extra_files'].items():
remote_file = path.normpath(path.join(self.remote_virtualenv_path,
remote_path))
assert path.isabs(remote_file)
local_file = path.normpath(path.join(self.manifest_dir, local_path))
# We'll rely on fpm to error if it's a nonexistent path.
assert path.isabs(local_file)
args.append('{}={}/'.format(pipes.quote(local_file),
pipes.quote(path.dirname(remote_file))))
return args


def get_single_flags(self):

flags = {
Expand Down Expand Up @@ -180,4 +199,3 @@ def local_virtualenv_path(self):
@property
def remote_virtualenv_path(self):
return path.join(self.remote_package_path, self.virtualenv_name)

34 changes: 33 additions & 1 deletion tests/test_manifest.py
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,35 @@ def test_config(self, manifest, test_cfg, expected_args, expected_flags):
assert sorted(actual_args) == sorted(expected_args)
assert sorted(actual_flags) == sorted(expected_flags)

@pytest.mark.parametrize('test_extra_files, expected_args', [
# we don't have to have extra files
({}, []),
# relative path files
({'content/important.txt': 'src/important.txt'},
['/test_dir/src/important.txt=/opt/ship_it/content/']),
# relative path directories
({'content': 'content/'},
['/test_dir/content=/opt/ship_it/']),
# absolute path files
({'/etc/ship_it/important.txt': 'external/important.txt'},
['/test_dir/external/important.txt=/etc/ship_it/']),
# absolute path directores
({'/etc/ship_it/content': 'external/content/'},
['/test_dir/external/content=/etc/ship_it/']),
# more than one extra file
({'/etc/ship_it/important.txt': 'external/important.txt',
'content/important.txt': 'src/important.txt'},
['/test_dir/external/important.txt=/etc/ship_it/',
'/test_dir/src/important.txt=/opt/ship_it/content/']),
])
def test_extra_files(self, manifest, test_extra_files, expected_args):
"""
Test getting the right arguments from extra files/
"""
manifest.contents.update({'extra_files': test_extra_files})
actual_args = manifest.get_extra_files_args()
assert sorted(actual_args) == sorted(expected_args)

@pytest.mark.parametrize('dependency_type,value,expected', [
# you can specify nothing, and it's fine
('depends', [], []),
Expand Down Expand Up @@ -372,20 +401,23 @@ def test_remote_pkg_path_arg(self, mock_remote_pkg_path, manifest):
'group': 'root'}, 'root', 'root'),
])
@mock.patch('ship_it.manifest.Manifest.get_config_args_and_flags')
@mock.patch('ship_it.manifest.Manifest.get_extra_files_args')
@mock.patch('ship_it.manifest.Manifest.get_single_flags')
@mock.patch('ship_it.manifest.Manifest.get_dependency_flags')
@mock.patch('ship_it.manifest.Manifest.get_exclude_flags')
def test_get_overall_args(self, mock_excludes, mock_depends, mock_single,
mock_cfg, manifest, cfg_update, expected_user, expected_group):
mock_extra, mock_cfg, manifest, cfg_update, expected_user, expected_group):
# Return values must be set here, rather than in the decorator,
# to reset their state for each iteration.
mock_excludes.return_value = [('exclude', '**.pyc'), ('exclude', '**.pyo')]
mock_depends.return_value = [('depends', 'weird-dependency == 0.1')]
mock_single.return_value = [('single', 'flag')]
mock_cfg.return_value = (['cfg arg'], [('cfg', 'flag')])
mock_extra.return_value = ['extra=arg']

expected_args = [
'cfg arg',
'extra=arg',
'/test_dir/build/ship_it=/opt'
]
expected_flags = [
Expand Down

0 comments on commit 94c3715

Please sign in to comment.