Skip to content

Commit

Permalink
Fixes #8016 - API connection moved to context (#468)
Browse files Browse the repository at this point in the history
(cherry picked from commit c3aaa66)
  • Loading branch information
Tomas Strachota authored and John Mitsch committed Dec 13, 2016
1 parent 08c3fee commit 6b4db6d
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 10 deletions.
14 changes: 12 additions & 2 deletions lib/hammer_cli_katello/commands.rb
Original file line number Diff line number Diff line change
@@ -1,15 +1,25 @@
module HammerCLIKatello
RESOURCE_NAME_MAPPING = {}.freeze

def self.api_connection
if HammerCLI.context[:api_connection]
HammerCLI.context[:api_connection].get("foreman")
else
HammerCLI::Connection.get("foreman").api
end
end

module ResolverCommons
def self.included(base)
base.extend(ClassMethods)
end

module ClassMethods
def resolver
api = HammerCLI::Connection.get("foreman").api
HammerCLIKatello::IdResolver.new(api, HammerCLIKatello::Searchables.new)
HammerCLIKatello::IdResolver.new(
HammerCLIKatello.api_connection,
HammerCLIKatello::Searchables.new
)
end

def searchables
Expand Down
3 changes: 1 addition & 2 deletions lib/hammer_cli_katello/host_collection.rb
Original file line number Diff line number Diff line change
Expand Up @@ -172,13 +172,12 @@ def request_params
end

def resolver
api = HammerCLI::Connection.get("foreman").api
custom_resolver = Class.new(HammerCLIKatello::IdResolver) do
def hosts_bulk_action_id(options)
host_collection_id(options)
end
end
custom_resolver.new(api, HammerCLIKatello::Searchables.new)
custom_resolver.new(HammerCLIKatello.api_connection, HammerCLIKatello::Searchables.new)
end
end

Expand Down
21 changes: 15 additions & 6 deletions test/test_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,23 @@
require 'minitest/spec'
require 'mocha/setup'
require 'hammer_cli'
require 'hammer_cli_foreman/commands'

KATELLO_VERSION = Gem::Version.new(ENV['TEST_API_VERSION'] || '3.2')

HammerCLIForeman.stubs(:resource_config).returns(
:apidoc_cache_dir => 'test/data/' + KATELLO_VERSION.to_s,
:apidoc_cache_name => 'foreman_api',
:dry_run => true
)
if HammerCLI.context[:api_connection]
HammerCLI.context[:api_connection].create('foreman') do
HammerCLI::Apipie::ApiConnection.new(
:apidoc_cache_dir => 'test/data/' + KATELLO_VERSION.to_s,
:apidoc_cache_name => 'foreman_api',
:dry_run => true
)
end
else
HammerCLIForeman.stubs(:resource_config).returns(
:apidoc_cache_dir => 'test/data/' + KATELLO_VERSION.to_s,
:apidoc_cache_name => 'foreman_api',
:dry_run => true
)
end

require 'hammer_cli_katello'

0 comments on commit 6b4db6d

Please sign in to comment.