Skip to content

Conversation

@gformisa
Copy link
Contributor

  • Delete override to allow katello api to use search: {name: 'foo'}
  • Now katello api use search from Foreman super class

@gformisa gformisa force-pushed the fix_14307 branch 2 times, most recently from 23a605f to 2012259 Compare November 15, 2025 16:24
 * Delete override to allow katello api to use search: {name: 'foo'}
 * Now katello api use search from Foreman super class
@gformisa
Copy link
Contributor Author

The tests are failing, below one example about error:

HammerCLIKatello::FileCommand::InfoCommand::resolves ID from file name::content view version::content view name, and organization#test_0002_name [vendor/bundle/ruby/2.7.0/gems/apipie-bindings-0.7.1/lib/apipie_bindings/api.rb:185]:
unexpected invocation: #<AnyInstance:ApipieBindings::API>.call_action(<Action file_units:index>, {:search => "name = \"foo\"", :per_page => 1000, :page => 1}, {}, {:fake_response => nil})
unsatisfied expectations:
- expected exactly once, invoked never: 
  #<AnyInstance:ApipieBindings::API>.call_action(:file_units, :show, *any_argument)
  expected params to include: {
    "id": 1
  }

The test expects something like this:
Katello format

call_action(:file_units, :index, {
  "name": "foo",                    # ← Parametro diretto
  "content_view_version_id": "2"
})

But from my change now is receiving the correct form support, from foreman:

call_action(:file_units, :index, {
  :search => "name = \"foo\"",      # ← Parametro search!
  :per_page => 1000,
  :page => 1
})

@ianballou
Copy link
Member

I think the key to fixing the tests is to compare:

#<AnyInstance:ApipieBindings::API>.call_action(<Action file_units:index>, {:search => "name = \"foo\"", :per_page => 1000, :page => 1}, {}, {:fake_response => nil})

vs

#<AnyInstance:ApipieBindings::API>.call_action(:file_units, :show, *any_argument)

The test helpers likely need updates, or perhaps the methods they use within. For example, for products:

@ianballou
Copy link
Member

To fix the test API expectations that are looking for the old style parameters, it looks like these files need updating:

[vagrant@centos9-hammer-devel hammer-cli-katello]$ grep -nr "{'name' => name, 'organization_id' => org_id}"
test/functional/lifecycle_environment/lifecycle_environment_helpers.rb:8:                          params: {'name' => name, 'organization_id' => org_id},
test/functional/product/product_helpers.rb:8:    expect_generic_product_search({'name' => name, 'organization_id' => org_id}, 'id' => id)
test/functional/content_view/content_view_helpers.rb:7:    expect_generic_content_view_search(params: {'name' => name, 'organization_id' => org_id},

The arguments passed into expect_generic_product_search should match what hammer is actually sending to the fake API in the tests (i.e. the unexpected parameters failing the test).

To fix the undefined method test errors, we need to do one of the following:

  1. Delete the tests since create_search_options is being used directly from Foreman, or,
  2. Update the tests to use create_search_options instead of the overrides that you removed.

alias_method :create_search_options, :create_search_options_with_katello_api
# alias_method :create_search_options_without_katello_api, :create_search_options
# alias_method :create_search_options, :create_search_options_with_katello_api
def create_search_options(options, resource, mode = nil)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This method can likely be removed. Calling it with super alone is just calling the parent, which means the wrapper should be unnecessary.

module SearchOptionsCreators
include HammerCLIKatello::ForemanSearchOptionsCreators

#include HammerCLIKatello::ForemanSearchOptionsCreators
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the only place where HammerCLIKatello::ForemanSearchOptionsCreators is included, so perhaps the entire HammerCLIKatello::ForemanSearchOptionsCreators can be deleted.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants