Skip to content

Commit

Permalink
Fixes #27466 - Allow Hammer to update cv version descriptions (#675)
Browse files Browse the repository at this point in the history
  • Loading branch information
chris1984 authored and akofink committed Aug 14, 2019
1 parent 49a9360 commit 8c1c3a7
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 0 deletions.
15 changes: 15 additions & 0 deletions lib/hammer_cli_katello/content_view_version.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ class ListCommand < HammerCLIKatello::ListCommand
field :id, _("ID")
field :name, _("Name")
field :version, _("Version")
field :description, _("Description")
field :environments, _("Lifecycle Environments"), Fields::List
end

Expand Down Expand Up @@ -159,6 +160,20 @@ class DeleteCommand < HammerCLIKatello::DeleteCommand
extend_with(HammerCLIKatello::CommandExtensions::LifecycleEnvironment.new)
end

class UpdateCommand < HammerCLIKatello::UpdateCommand
action :update
command_name "update"

success_message _("Content view version updated.")
failure_message _("Could not update the content view version")

build_options do |o|
o.expand(:all).including(:environments, :content_views, :organizations)
end

extend_with(HammerCLIKatello::CommandExtensions::LifecycleEnvironment.new)
end

class IncrementalUpdate < HammerCLIKatello::Command
include HammerCLIForemanTasks::Async

Expand Down
48 changes: 48 additions & 0 deletions test/functional/content_view/version/update_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
require_relative '../../test_helper'
require 'hammer_cli_katello/content_view_version'

module HammerCLIKatello
describe ContentViewVersion::UpdateCommand do
include OrganizationHelpers
it 'allows minimal options' do
ex = api_expects(:content_view_versions, :update).with_params('description' => 'pizza')
ex.returns('id' => '2', 'description' => 'pizza')

result = run_cmd(%w(content-view version update --id 2 --description pizza))
assert_equal(result.exit_code, 0)
end
end

describe 'content view options' do
it 'allows content view id with one version' do
ex = api_expects(:content_view_versions, :index)
ex.returns('id' => '1', 'content_view' => [{'id' => '2'}])

ex = api_expects(:content_view_versions, :update).with_params('description' => 'pizza')
ex.returns('id' => '1', 'description' => 'pizza', 'content_view' => [{'id' => '2'}])

result = run_cmd(%w(content-view version update --description pizza --content-view-id 2))
assert_equal(result.exit_code, 0)
end

it 'allows content view id with multiple versions' do
ex = api_expects(:content_view_versions, :index)
ex.returns('id' => '2', 'content_view' => [{'id' => '3'}])

ex = api_expects(:content_view_versions, :update).with_params('description' => 'pizza')
ex.returns('id' => '2', 'description' => 'pizza', 'content_view' => [{'id' => '3'}])

result = run_cmd(%w(content-view version update --description pizza
--content-view-id 3 --version 2))
assert_equal(result.exit_code, 0)
end

it 'blocks update without description' do
ex = api_expects(:content_view_versions, :index)
ex.returns('id' => '1', 'content_view' => [{'id' => '2'}])

result = run_cmd(%w(content-view version update --content-view-id 2))
assert_equal(result.exit_code, 64)
end
end
end

0 comments on commit 8c1c3a7

Please sign in to comment.