Skip to content

Commit 078f892

Browse files
committed
Fixing broken rh-cloud tests in develop
1 parent 082f9d2 commit 078f892

8 files changed

+49
-54
lines changed

test/controllers/insights_cloud/api/machine_telemetries_controller_test.rb

+6-16
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33

44
module InsightsCloud::Api
55
class MachineTelemetriesControllerTest < ActionController::TestCase
6+
include KatelloCVEHelper
7+
68
setup do
79
FactoryBot.create(:common_parameter, name: InsightsCloud.enable_client_param, key_type: 'boolean', value: true)
810
end
@@ -122,29 +124,17 @@ class MachineTelemetriesControllerTest < ActionController::TestCase
122124
setup do
123125
UpstreamOnlySettingsTestHelper.set_if_available('allow_multiple_content_views')
124126
User.current = User.find_by(login: 'secret_admin')
125-
126-
@env = FactoryBot.create(:katello_k_t_environment)
127-
@env2 = FactoryBot.create(:katello_k_t_environment, organization: @env.organization)
127+
env = FactoryBot.create(:katello_k_t_environment)
128+
env2 = FactoryBot.create(:katello_k_t_environment, organization: env.organization)
128129

129130
@host = FactoryBot.create(
130131
:host,
131132
:with_subscription,
132133
:with_content,
133134
:with_hostgroup,
134135
:with_parameter,
135-
content_view_environments: [
136-
FactoryBot.create(
137-
:katello_content_view_environment,
138-
content_view: FactoryBot.create(:katello_content_view, organization: @env.organization),
139-
lifecycle_environment: @env
140-
),
141-
FactoryBot.create(
142-
:katello_content_view_environment,
143-
content_view: FactoryBot.create(:katello_content_view, organization: @env.organization),
144-
lifecycle_environment: @env2
145-
),
146-
],
147-
organization: @env.organization
136+
content_view_environments: [make_cve(lifecycle_environment: env), make_cve(lifecycle_environment: env2)],
137+
organization: env.organization
148138
)
149139

150140
@host.subscription_facet.pools << FactoryBot.create(:katello_pool, account_number: '5678', cp_id: 1)

test/jobs/inventory_full_sync_test.rb

+6-5
Original file line numberDiff line numberDiff line change
@@ -4,22 +4,23 @@
44
class InventoryFullSyncTest < ActiveSupport::TestCase
55
include ForemanTasks::TestHelpers::WithInThreadExecutor
66
include MockCerts
7+
include KatelloCVEHelper
78

89
setup do
910
User.current = User.find_by(login: 'secret_admin')
1011

1112
InventorySync::Async::InventoryFullSync.any_instance.stubs(:plan_self_host_sync)
1213
Organization.any_instance.stubs(:manifest_expired?).returns(false)
1314

14-
env = FactoryBot.create(:katello_k_t_environment)
15-
cv = env.content_views << FactoryBot.create(:katello_content_view, organization: env.organization)
15+
cve = make_cve
16+
env = cve.lifecycle_environment
1617

1718
# this host would pass our plugin queries, so it could be uploaded to the cloud.
1819
@host1 = FactoryBot.create(
1920
:host,
2021
:with_subscription,
2122
:with_content,
22-
content_view: cv.first,
23+
content_view: cve.content_view,
2324
lifecycle_environment: env,
2425
organization: env.organization
2526
)
@@ -33,7 +34,7 @@ class InventoryFullSyncTest < ActiveSupport::TestCase
3334
:host,
3435
:with_subscription,
3536
:with_content,
36-
content_view: cv.first,
37+
content_view: cve.content_view,
3738
lifecycle_environment: env,
3839
organization: env.organization
3940
)
@@ -46,7 +47,7 @@ class InventoryFullSyncTest < ActiveSupport::TestCase
4647
:host,
4748
:with_subscription,
4849
:with_content,
49-
content_view: cv.first,
50+
content_view: cve.content_view,
5051
lifecycle_environment: env,
5152
organization: env.organization
5253
)

test/jobs/inventory_hosts_sync_test.rb

+6-6
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,19 @@
44
class InventoryHostsSyncTest < ActiveSupport::TestCase
55
include ForemanTasks::TestHelpers::WithInThreadExecutor
66
include MockCerts
7+
include KatelloCVEHelper
78

89
setup do
910
User.current = User.find_by(login: 'secret_admin')
10-
11-
env = FactoryBot.create(:katello_k_t_environment)
12-
cv = env.content_views << FactoryBot.create(:katello_content_view, organization: env.organization)
13-
11+
cve = make_cve
12+
env = cve.lifecycle_environment
13+
cv = cve.content_view
1414
# this host would pass our plugin queries, so it could be uploaded to the cloud.
1515
@host1 = FactoryBot.create(
1616
:host,
1717
:with_subscription,
1818
:with_content,
19-
content_view: cv.first,
19+
content_view: cv,
2020
lifecycle_environment: env,
2121
organization: env.organization
2222
)
@@ -30,7 +30,7 @@ class InventoryHostsSyncTest < ActiveSupport::TestCase
3030
:host,
3131
:with_subscription,
3232
:with_content,
33-
content_view: cv.first,
33+
content_view: cv,
3434
lifecycle_environment: env,
3535
organization: env.organization
3636
)

test/test_plugin_helper.rb

+14
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,20 @@ module CandlepinIsolation
118118
end
119119
end
120120

121+
module KatelloCVEHelper
122+
def make_cve(lifecycle_environment: nil, content_view: nil)
123+
env = lifecycle_environment || FactoryBot.create(:katello_k_t_environment)
124+
content_view ||= FactoryBot.create(:katello_content_view, organization: env.organization)
125+
cvv = ::Katello::ContentViewVersion.create!(:major => 2, :content_view => content_view)
126+
FactoryBot.create(
127+
:katello_content_view_environment,
128+
content_view_version: cvv,
129+
content_view: content_view,
130+
lifecycle_environment: env
131+
)
132+
end
133+
end
134+
121135
module UpstreamOnlySettingsTestHelper
122136
def self.set_if_available(setting_name, value: true)
123137
Setting[setting_name] = value

test/unit/archived_report_generator_test.rb

+4-4
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,18 @@
22

33
class ArchivedReportGeneratorTest < ActiveSupport::TestCase
44
include MockForemanHostname
5+
include KatelloCVEHelper
56

67
setup do
78
User.current = User.find_by(login: 'secret_admin')
8-
9-
env = FactoryBot.create(:katello_k_t_environment)
10-
cv = env.content_views << FactoryBot.create(:katello_content_view, organization: env.organization)
9+
cve = make_cve
10+
env = cve.lifecycle_environment
1111

1212
@host = FactoryBot.create(
1313
:host,
1414
:with_subscription,
1515
:with_content,
16-
content_view: cv.first,
16+
content_view: cve.content_view,
1717
lifecycle_environment: env,
1818
organization: env.organization
1919
)

test/unit/services/foreman_rh_cloud/branch_info_test.rb

+7-6
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,22 @@
11
require 'test_plugin_helper'
22

33
class BranchInfoTest < ActiveSupport::TestCase
4+
include KatelloCVEHelper
5+
46
setup do
57
User.current = User.find_by(login: 'secret_admin')
68

7-
@env = FactoryBot.create(:katello_k_t_environment)
8-
cv = @env.content_views << FactoryBot.create(:katello_content_view, organization: @env.organization)
9-
9+
cve = make_cve
10+
env = cve.lifecycle_environment
1011
@host = FactoryBot.create(
1112
:host,
1213
:with_subscription,
1314
:with_content,
1415
:with_hostgroup,
1516
:with_parameter,
16-
content_view: cv.first,
17-
lifecycle_environment: @env,
18-
organization: @env.organization
17+
content_view: cve.content_view,
18+
lifecycle_environment: env,
19+
organization: env.organization
1920
)
2021

2122
@host.subscription_facet.pools << FactoryBot.create(:katello_pool, account_number: '5678', cp_id: 1)

test/unit/slice_generator_test.rb

+4-5
Original file line numberDiff line numberDiff line change
@@ -3,21 +3,20 @@
33
class SliceGeneratorTest < ActiveSupport::TestCase
44
include KatelloLocationFix
55
include CandlepinIsolation
6+
include KatelloCVEHelper
67

78
setup do
89
User.current = User.find_by(login: 'secret_admin')
9-
10-
env = FactoryBot.create(:katello_k_t_environment)
11-
cv = env.content_views << FactoryBot.create(:katello_content_view, organization: env.organization)
12-
10+
cve = make_cve
11+
env = cve.lifecycle_environment
1312
location = FactoryBot.create(:location)
1413

1514
@host = FactoryBot.create(
1615
:host,
1716
:redhat,
1817
:with_subscription,
1918
:with_content,
20-
content_view: cv.first,
19+
content_view: cve.content_view,
2120
lifecycle_environment: env,
2221
organization: env.organization,
2322
location: location

test/unit/tags_generator_test.rb

+2-12
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
class TagsGeneratorTest < ActiveSupport::TestCase
44
include KatelloLocationFix
55
include CandlepinIsolation
6+
include KatelloCVEHelper
67

78
setup do
89
UpstreamOnlySettingsTestHelper.set_if_available('allow_multiple_content_views')
@@ -25,18 +26,7 @@ class TagsGeneratorTest < ActiveSupport::TestCase
2526
organization: env.organization,
2627
location: @location2,
2728
hostgroup: @hostgroup2,
28-
content_view_environments: [
29-
FactoryBot.create(
30-
:katello_content_view_environment,
31-
content_view: FactoryBot.create(:katello_content_view, organization: env.organization),
32-
lifecycle_environment: env
33-
),
34-
FactoryBot.create(
35-
:katello_content_view_environment,
36-
content_view: FactoryBot.create(:katello_content_view, organization: env.organization),
37-
lifecycle_environment: env2
38-
),
39-
]
29+
content_view_environments: [make_cve(lifecycle_environment: env), make_cve(lifecycle_environment: env2)]
4030
)
4131

4232
@host.organization.pools << FactoryBot.create(:katello_pool, account_number: '1234', cp_id: 1)

0 commit comments

Comments
 (0)