Skip to content

Commit

Permalink
QE: Add tests for channels.appstreams API namespace (#9204)
Browse files Browse the repository at this point in the history
* QE: Add API support for channels.appstreams namespace

* QE: add test scenarios for channel.appstreams API namespace

* Rubocop fixes

* fix method call
  • Loading branch information
NamelessOne91 authored Sep 30, 2024
1 parent f6ddffd commit 5f6a2fc
Show file tree
Hide file tree
Showing 3 changed files with 81 additions and 2 deletions.
15 changes: 14 additions & 1 deletion testsuite/features/secondary/srv_channel_api.feature
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright (c) 2015-2022 SUSE LLC
# Copyright (c) 2015-2024 SUSE LLC
# Licensed under the terms of the MIT license.

@scope_api
Expand Down Expand Up @@ -37,3 +37,16 @@ Feature: API "channel" namespace and sub-namespaces

Scenario: Check last synchronization of a synced channel
Then channel "fake-child-channel-i586" should have attribute "yumrepo_last_sync" that is a date

@rhlike_minion
Scenario: Verify if a channel is modular via the API
When I verify channel "fake-base-channel-appstream" is modular via the API
And I verify channel "fake-rpm-suse-channel" is not modular via the API

@rhlike_minion
Scenario: List modular channels via the API
When channel "Fake-Base-Channel-AppStream" is present in the modular channels listed via the API

@rhlike_minion
Scenario: List available module streams for a given channel via the API
When "scorpio" module streams "2.0, 2.1" are available for channel "fake-base-channel-appstream" via the API
29 changes: 29 additions & 0 deletions testsuite/features/step_definitions/api_common.rb
Original file line number Diff line number Diff line change
Expand Up @@ -631,3 +631,32 @@
When(/^I delete profile and distribution using the API for "([^"]*)" kickstart tree$/) do |distro_name|
$api_test.kickstart.tree.delete_tree_and_profiles(distro_name)
end

When(/I verify channel "([^"]*)" is( not)? modular via the API/) do |channel_label, not_modular|
is_modular = $api_test.channel.appstreams.modular?(channel_label)
expected = not_modular.nil?

raise ScriptError "channel '#{channel_label}' is modular? Expected: #{expected} - got: #{is_modular}" unless is_modular == expected
end

When(/channel "([^"]*)" is( not)? present in the modular channels listed via the API/) do |channel, not_present|
modular_channels = $api_test.channel.appstreams.list_modular_channels
is_present = modular_channels.include?(channel)
expected = not_present.nil?

raise ScriptError "Expected #{modular_channels} to include '#{channel}'? #{expected} - got: #{is_present}" unless is_present == expected
end

When(/"([^"]*)" module streams "([^"]*)" are available for channel "([^"]*)" via the API/) do |module_name, streams, channel_label|
expected_streams = streams.split(',').map(&:strip)
available_streams = $api_test.channel.appstreams.list_module_streams(channel_label)

expected_streams.each do |expected_stream|
found =
available_streams.any? do |stream|
stream['module'] == module_name && stream['stream'] == expected_stream
end

raise ScriptError, "Stream '#{expected_stream}' for module '#{module_name}' not found in the available streams for channel '#{channel_label}'" unless found
end
end
39 changes: 38 additions & 1 deletion testsuite/features/support/namespaces/channel.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,10 @@ class NamespaceChannel
def initialize(api_test)
@test = api_test
@software = NamespaceChannelSoftware.new(api_test)
@appstreams = NamespaceChannelAppstreams.new(api_test)
end

attr_reader :software
attr_reader :software, :appstreams

# It returns the number of software channels in the system.
#
Expand Down Expand Up @@ -164,3 +165,39 @@ def list_system_channels(system_id)
channels.map { |channel| channel['name'] }
end
end

# channel.appstreams namespace
class NamespaceChannelAppstreams
# Initializes a new instance of the NamespaceChannelAppstreams class.
#
# @param api_test [Object] The test object that is passed to the initialize method.
def initialize(api_test)
@test = api_test
end

# Check if channel is modular.
#
# @param label [String] The label of the channel.
#
# @return [Boolean] Returns true if the channel is modular, false otherwise
def modular?(label)
@test.call('channel.appstreams.isModular', sessionKey: @test.token, channelLabel: label)
end

# List modular channels in users organization.
#
# @return [Array<String>] An array of modular channel names.
def list_modular_channels
channels = @test.call('channel.appstreams.listModular', sessionKey: @test.token)
channels.map { |channel| channel['name'] }
end

# List available module streams for a given channel.
#
# @param label [String] The label of the channel.
#
# @return [Array<Object>] An array of objects representing each stream details
def list_module_streams(label)
@test.call('channel.appstreams.listModuleStreams', sessionKey: @test.token, channelLabel: label)
end
end

0 comments on commit 5f6a2fc

Please sign in to comment.