foreman_scc_manager 1.8.2 → 1.8.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (43) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +5 -0
  3. data/app/controllers/api/v2/scc_accounts_controller.rb +9 -7
  4. data/app/controllers/scc_accounts_controller.rb +30 -4
  5. data/app/lib/actions/scc_manager/subscribe_product.rb +26 -13
  6. data/app/lib/actions/scc_manager/sync.rb +5 -5
  7. data/app/lib/actions/scc_manager/sync_products.rb +10 -11
  8. data/app/lib/actions/scc_manager/sync_repositories.rb +9 -11
  9. data/app/lib/scc_manager.rb +2 -2
  10. data/app/models/scc_account.rb +70 -11
  11. data/app/models/scc_product.rb +20 -2
  12. data/app/models/scc_repository.rb +11 -9
  13. data/app/views/scc_accounts/_form.html.erb +6 -0
  14. data/app/views/scc_accounts/index.html.erb +4 -3
  15. data/app/views/scc_accounts/show.html.erb +13 -4
  16. data/db/migrate/20200520281300_fix_scc_permissions.rb +22 -0
  17. data/db/migrate/20201119084201_add_gpg_key_to_scc_account.rb +6 -0
  18. data/db/migrate/20210205082733_add_subscription_valid_to_scc_products_and_repos.rb +6 -0
  19. data/db/migrate/20210210104407_add_root_repository_id_to_scc_repository.rb +6 -0
  20. data/db/migrate/20210224095050_connect_katello_root_repository_to_scc_repository.rb +17 -0
  21. data/lib/foreman_scc_manager/engine.rb +36 -25
  22. data/lib/foreman_scc_manager/version.rb +1 -1
  23. data/lib/tasks/test.rake +1 -1
  24. data/locale/de/LC_MESSAGES/foreman_scc_manager.mo +0 -0
  25. data/locale/de/foreman_scc_manager.edit.po +574 -0
  26. data/locale/de/foreman_scc_manager.po +40 -21
  27. data/locale/de/foreman_scc_manager.po.time_stamp +0 -0
  28. data/locale/en/foreman_scc_manager.edit.po +566 -0
  29. data/locale/en/foreman_scc_manager.po +21 -3
  30. data/locale/en/foreman_scc_manager.po.time_stamp +0 -0
  31. data/locale/foreman_scc_manager.pot +65 -38
  32. data/test/controllers/api/v2/scc_accounts_test.rb +9 -3
  33. data/test/controllers/scc_accounts_controller_test.rb +104 -0
  34. data/test/controllers/scc_accounts_controller_test2.rb +51 -0
  35. data/test/fixtures/models/scc_extendings.yml +6 -0
  36. data/test/fixtures/models/scc_products.yml +30 -2
  37. data/test/fixtures/models/scc_repositories.yml +29 -0
  38. data/test/models/scc_account_test.rb +70 -0
  39. data/test/models/scc_product_test.rb +69 -1
  40. data/test/support/fixtures_support.rb +3 -2
  41. data/test/test_controller_helper.rb +15 -0
  42. data/test/test_plugin_helper.rb +9 -0
  43. metadata +33 -14
@@ -0,0 +1,6 @@
1
+ # create a couple of products as scc_extensions
2
+ <% 1.upto(10) do |i| %>
3
+ p_extending_<%= i %>:
4
+ scc_product_id: 4
5
+ scc_extension_id: <%= 4 + i %>
6
+ <% end %>
@@ -7,8 +7,9 @@ one:
7
7
  version: 1
8
8
  arch: x86_128
9
9
  friendly_name: number one
10
- description: lorem ipsum dolor sit amet
10
+ description: "<p> lorem ipsum dolor sit amet </p>"
11
11
  product_type: base
12
+ subscription_valid: nil
12
13
 
13
14
  two:
14
15
  scc_account_id: test_account1
@@ -17,5 +18,32 @@ two:
17
18
  version: 2
18
19
  arch: x86_128
19
20
  friendly_name: number two
20
- description: lorem ipsum dolor sit amet
21
+ description: "<p> lorem ipsum dolor sit amet </p><p> lorem lorem lorem </p>"
21
22
  product_type: extras
23
+ subscription_valid: true
24
+
25
+ three:
26
+ scc_account_id: test_account1
27
+ scc_id: 333
28
+ name: three
29
+ version: 3
30
+ arch: x86_128
31
+ friendly_name: number three
32
+ description: lorem ipsum dolor sit amet
33
+ product_type: base
34
+ subscription_valid: nil
35
+
36
+ # create a couple of products as scc_extensions
37
+ <% 1.upto(10) do |i| %>
38
+ p_extension_<%= i %>:
39
+ scc_account_id: test_account1
40
+ scc_id: <%= i %>
41
+ name: p_ext_<%= i%>
42
+ version: 3
43
+ arch: x86_128
44
+ friendly_name: number <%= i%>
45
+ description: lorem ipsum dolor sit amet
46
+ product_type: extension
47
+ subscription_valid: nil
48
+ <% end %>
49
+
@@ -0,0 +1,29 @@
1
+ # repositories for testing the empty repository filtering
2
+ <% 1.upto(8) do |i| %>
3
+ repo_<%= i %>:
4
+ id: <%= i %>
5
+ scc_account_id: 1
6
+ scc_id: <%= 63 + i %>
7
+ name: SLE10-Debuginfo-Updates_<%= i %>
8
+ distro_target: sles_<%= i %>
9
+ description: SLE10-Debuginfo-Updates for sles-10-ppc_<%= i %>
10
+ url: https://updates.suse.com/repo/example_<%= i %>
11
+ token: token_<%= i %>
12
+ autorefresh: true
13
+ installer_updates: false
14
+ <% end %>
15
+
16
+ repo_9:
17
+ id: 9
18
+ scc_account_id: 1
19
+ scc_id: 63
20
+ name: SLE10-Debuginfo-Updates_9
21
+ distro_target: sles_9
22
+ description: SLE10-Debuginfo-Updates for sles-10-ppc_9
23
+ url: https://updates.suse.com/repo/example_9
24
+ token: token_9
25
+ autorefresh: true
26
+ installer_updates: false
27
+
28
+
29
+
@@ -71,4 +71,74 @@ class SccAccountSearchTest < ActiveSupport::TestCase
71
71
  end
72
72
  end
73
73
 
74
+ class SccAccountUpdateProductsTest < ActiveSupport::TestCase
75
+ def setup
76
+ @account = scc_accounts(:one)
77
+ one = scc_products(:one)
78
+ @account.scc_products = SccProduct.where(name: 'one')
79
+ # generate test data, beware that hash names are not equal to SccProduct instance names
80
+ @product_data = { 'name' => one.name,
81
+ 'id' => one.scc_id,
82
+ 'version' => one.version,
83
+ 'arch' => one.arch,
84
+ 'repositories' => one.scc_repositories,
85
+ 'extensions' => one.scc_extensions,
86
+ 'product_type' => one.product_type,
87
+ 'description' => '<p> new unpretty description </p>',
88
+ 'friendly_name' => 'updated name' }
89
+ @product_array = []
90
+ @product_array.push @product_data
91
+
92
+ @test_product = SccProduct.new
93
+ @test_product.scc_id = @product_data['id']
94
+ @test_product.friendly_name = @product_data['friendly_name']
95
+ @test_product.description = @product_data['description']
96
+ end
97
+
98
+ test 'update scc product' do
99
+ @account.update_scc_products(@product_array)
100
+ @updated_product = @account.scc_products.where(friendly_name: 'updated name').first
101
+ assert_equal @test_product.pretty_name, @updated_product.name
102
+ assert_equal @test_product.pretty_name, @updated_product.pretty_name
103
+ assert_equal @test_product.pretty_description, @updated_product.description
104
+ assert_equal @test_product.pretty_description, @updated_product.pretty_description
105
+
106
+ assert @updated_product.subscription_valid
107
+ @invalid_products = @account.scc_products.where.not(scc_id: scc_products(:one).scc_id)
108
+ @invalid_products.each do |ip|
109
+ assert_not ip.subscription_valid
110
+ end
111
+ end
112
+ end
113
+
114
+ class SccAccountUpdateReposTest < ActiveSupport::TestCase
115
+ def setup
116
+ @account = scc_accounts(:one)
117
+ test_repo = scc_repositories(:repo_9)
118
+ @account.scc_repositories = SccProduct.where(name: 'repo_9')
119
+ # generate test data
120
+ @repo_data = { 'name' => test_repo.name,
121
+ 'id' => test_repo.scc_id,
122
+ 'distro_target' => test_repo.distro_target,
123
+ 'url' => test_repo.url,
124
+ 'enabled' => test_repo.enabled,
125
+ 'autorefresh' => test_repo.autorefresh,
126
+ 'installer_updates' => test_repo.installer_updates,
127
+ 'description' => '<p> new unpretty repo description </p>' }
128
+ @repo_array = []
129
+ @repo_array.push @repo_data
130
+
131
+ @test_repo = SccRepository.new
132
+ @test_repo.description = @repo_data['description']
133
+ @test_repo.name = @repo_data['name']
134
+ end
135
+
136
+ test 'update scc repository' do
137
+ @account.update_scc_repositories(@repo_array)
138
+ @updated_repo = @account.scc_repositories.where(name: @test_repo.pretty_name).first
139
+ assert_equal @test_repo.pretty_name, @updated_repo.name
140
+ assert_equal @test_repo.pretty_name, @updated_repo.pretty_name
141
+ end
142
+ end
143
+
74
144
  # FIXME: test cascaded delete
@@ -3,6 +3,8 @@ require 'test_plugin_helper'
3
3
  class SccProductCreateTest < ActiveSupport::TestCase
4
4
  def setup
5
5
  @product = scc_products(:one)
6
+ @product_with_ugly_description = scc_products(:two)
7
+ @product_with_normal_description = scc_products(:three)
6
8
  end
7
9
 
8
10
  test 'create' do
@@ -13,11 +15,26 @@ class SccProductCreateTest < ActiveSupport::TestCase
13
15
  test 'uniq_name' do
14
16
  assert_equal @product.uniq_name, '111 number one'
15
17
  end
18
+
19
+ test 'pretty_name' do
20
+ assert_equal @product.pretty_name, 'number one (id: 111)'
21
+ end
22
+
23
+ test 'pretty_description' do
24
+ assert_equal @product_with_normal_description.description,
25
+ @product_with_normal_description.pretty_description
26
+ assert_equal @product.pretty_description, 'lorem ipsum dolor sit amet'
27
+ assert_equal @product_with_ugly_description.pretty_description, 'lorem ipsum dolor sit amet'
28
+ end
16
29
  end
17
30
 
18
31
  class SccProductSearchTest < ActiveSupport::TestCase
19
32
  test 'default ordered by name' do
20
- assert_equal SccProduct.all.pluck(:name), ['one', 'two'].sort
33
+ product_names = ['one', 'two', 'three',
34
+ 'p_ext_1', 'p_ext_10', 'p_ext_2', 'p_ext_3',
35
+ 'p_ext_4', 'p_ext_5', 'p_ext_6', 'p_ext_7',
36
+ 'p_ext_8', 'p_ext_9']
37
+ assert_equal SccProduct.all.pluck(:name), product_names.sort
21
38
  end
22
39
 
23
40
  test 'search name' do
@@ -30,3 +47,54 @@ class SccProductSearchTest < ActiveSupport::TestCase
30
47
  assert_empty empty
31
48
  end
32
49
  end
50
+
51
+ # These produt extension tests are pre-tests for the class ProductEmptyRepoAvailableTests.
52
+ # They do not test any direct functionality of the plugin.
53
+ class SccProductExtensionsTest < ActiveSupport::TestCase
54
+ def setup
55
+ @product_with_extensions = scc_products(:one)
56
+ @product_with_extensions.scc_extensions = scc_products.select { |p| p.product_type == 'extension' }
57
+ @product_with_wrong_extensions = scc_products(:two)
58
+ @product_with_wrong_extensions.scc_extensions = [scc_products(:three)]
59
+ @product_without_extensions = scc_products(:three)
60
+ end
61
+
62
+ test 'check product extensions available' do
63
+ assert_equal @product_with_extensions.scc_extensions.count, 10
64
+ assert_not_empty @product_with_extensions.scc_extensions
65
+ assert_empty @product_without_extensions.scc_extensions
66
+ end
67
+
68
+ test 'product extension of correct type' do
69
+ assert_empty(@product_with_extensions.scc_extensions.reject { |p| p.product_type == 'extension' })
70
+ assert_not_empty(@product_with_wrong_extensions.scc_extensions.reject { |p| p.product_type == 'extension' })
71
+ end
72
+ end
73
+
74
+ class SccProductEmptyRepoAvailableTest < ActiveSupport::TestCase
75
+ def setup
76
+ @product_with_repos = scc_products(:one)
77
+ @product_with_repos.scc_extensions = scc_products.select { |p| p.product_type == 'extension' }
78
+ @product_with_repos.scc_repositories = scc_repositories[0..2]
79
+ @product_with_repos.scc_extensions[1].scc_repositories = scc_repositories[3..4]
80
+ @product_with_repos.scc_extensions[2].scc_repositories = scc_repositories[5..7]
81
+ end
82
+
83
+ test 'products with empty repositories' do
84
+ products_with_repos = SccProduct.only_products_with_repos
85
+ assert_equal SccProduct.all.count { |prod| !prod.scc_repositories.empty? }, 3
86
+ assert_equal products_with_repos.count, 3
87
+ end
88
+ end
89
+
90
+ class SccProductNoRepoTest < ActiveSupport::TestCase
91
+ def setup
92
+ @product_with_repos = scc_products(:one)
93
+ @product_with_repos.scc_extensions = scc_products.select { |p| p.product_type == 'extension' }
94
+ end
95
+
96
+ test 'products without any repositories' do
97
+ products_with_repos = SccProduct.only_products_with_repos
98
+ assert_empty products_with_repos
99
+ end
100
+ end
@@ -1,8 +1,9 @@
1
1
  module ForemanSccManager
2
2
  module FixturesSupport
3
3
  FIXTURE_CLASSES = {
4
- scc_accounts: ForemanSccManager::SccAccount,
5
- scc_products: ForemanSccManager::SccProduct
4
+ scc_accounts: ::SccAccount,
5
+ scc_products: ::SccProduct,
6
+ scc_repositories: ::SccRepository
6
7
  }.freeze
7
8
 
8
9
  def self.set_fixture_classes(test_class)
@@ -0,0 +1,15 @@
1
+ # This calls the main test_helper in Foreman-core
2
+ require 'test_helper'
3
+ # require "#{Katello::Engine.root}/test/katello_test_helper"
4
+
5
+ require 'foreman_tasks/test_helpers'
6
+
7
+ module SignInHelper
8
+ def sign_in_as(user)
9
+ post sign_in_url(username: user.login, password: user.password)
10
+ end
11
+ end
12
+
13
+ class ActionDispatch::IntegrationTest
14
+ include SignInHelper
15
+ end
@@ -22,6 +22,7 @@ module FixtureTestCase
22
22
  Dir.mkdir(self.fixture_path)
23
23
  FileUtils.cp(Dir.glob("#{ForemanSccManager::Engine.root}/test/fixtures/models/*"), self.fixture_path)
24
24
  FileUtils.cp(Dir.glob("#{ForemanSccManager::Engine.root}/test/fixtures/files/*"), self.fixture_path)
25
+ FileUtils.cp(Dir.glob("#{ForemanSccManager::Engine.root}/test/fixtures/controllers/*"), self.fixture_path)
25
26
  FileUtils.cp(Dir.glob("#{Rails.root}/test/fixtures/*"), self.fixture_path)
26
27
  fixtures(:all)
27
28
  FIXTURES = load_fixtures(ActiveRecord::Base)
@@ -56,3 +57,11 @@ class ActiveSupport::TestCase
56
57
  organization
57
58
  end
58
59
  end
60
+
61
+ class ActionController::TestCase
62
+ def set_session_user(user = :admin, org = :empty_organization)
63
+ user = user.is_a?(User) ? user : users(user)
64
+ org = org.is_a?(Organization) ? org : taxonomies(org)
65
+ { :user => user.id, :expires_at => 5.minutes.from_now, :organization_id => org.id }
66
+ end
67
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: foreman_scc_manager
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.8.2
4
+ version: 1.8.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - ATIX AG
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-03-17 00:00:00.000000000 Z
11
+ date: 2021-03-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rdoc
@@ -84,14 +84,14 @@ dependencies:
84
84
  name: rails
85
85
  requirement: !ruby/object:Gem::Requirement
86
86
  requirements:
87
- - - "~>"
87
+ - - ">="
88
88
  - !ruby/object:Gem::Version
89
89
  version: '5.1'
90
90
  type: :runtime
91
91
  prerelease: false
92
92
  version_requirements: !ruby/object:Gem::Requirement
93
93
  requirements:
94
- - - "~>"
94
+ - - ">="
95
95
  - !ruby/object:Gem::Version
96
96
  version: '5.1'
97
97
  description: Foreman plugin to sync SUSE Customer Center products and repositories
@@ -153,6 +153,11 @@ files:
153
153
  - db/migrate/20170505063726_add_sync_status_to_scc_account.rb
154
154
  - db/migrate/20180321000000_change_sync_status_to_sync_task.rb
155
155
  - db/migrate/20190417202427_add_recurring_sync.foreman_scc_manager.rb
156
+ - db/migrate/20200520281300_fix_scc_permissions.rb
157
+ - db/migrate/20201119084201_add_gpg_key_to_scc_account.rb
158
+ - db/migrate/20210205082733_add_subscription_valid_to_scc_products_and_repos.rb
159
+ - db/migrate/20210210104407_add_root_repository_id_to_scc_repository.rb
160
+ - db/migrate/20210224095050_connect_katello_root_repository_to_scc_repository.rb
156
161
  - lib/foreman_scc_manager.rb
157
162
  - lib/foreman_scc_manager/engine.rb
158
163
  - lib/foreman_scc_manager/version.rb
@@ -161,13 +166,19 @@ files:
161
166
  - locale/Makefile
162
167
  - locale/action_names.rb
163
168
  - locale/de/LC_MESSAGES/foreman_scc_manager.mo
169
+ - locale/de/foreman_scc_manager.edit.po
164
170
  - locale/de/foreman_scc_manager.po
171
+ - locale/de/foreman_scc_manager.po.time_stamp
165
172
  - locale/en/LC_MESSAGES/foreman_scc_manager.mo
173
+ - locale/en/foreman_scc_manager.edit.po
166
174
  - locale/en/foreman_scc_manager.po
175
+ - locale/en/foreman_scc_manager.po.time_stamp
167
176
  - locale/foreman_scc_manager.pot
168
177
  - locale/gemspec.rb
169
178
  - test/controllers/api/v2/scc_accounts_test.rb
170
179
  - test/controllers/api/v2/scc_products_test.rb
180
+ - test/controllers/scc_accounts_controller_test.rb
181
+ - test/controllers/scc_accounts_controller_test2.rb
171
182
  - test/factories/foreman_scc_manager_factories.rb
172
183
  - test/features/sync_test.rb
173
184
  - test/fixtures/files/data_products_page1.json
@@ -175,10 +186,13 @@ files:
175
186
  - test/fixtures/files/data_repositories.json
176
187
  - test/fixtures/files/data_subscriptions.json
177
188
  - test/fixtures/models/scc_accounts.yml
189
+ - test/fixtures/models/scc_extendings.yml
178
190
  - test/fixtures/models/scc_products.yml
191
+ - test/fixtures/models/scc_repositories.yml
179
192
  - test/models/scc_account_test.rb
180
193
  - test/models/scc_product_test.rb
181
194
  - test/support/fixtures_support.rb
195
+ - test/test_controller_helper.rb
182
196
  - test/test_plugin_helper.rb
183
197
  - test/unit/foreman_scc_manager_test.rb
184
198
  homepage: https://www.orcharhino.com/
@@ -200,23 +214,28 @@ required_rubygems_version: !ruby/object:Gem::Requirement
200
214
  - !ruby/object:Gem::Version
201
215
  version: '0'
202
216
  requirements: []
203
- rubygems_version: 3.0.6
217
+ rubygems_version: 3.1.2
204
218
  signing_key:
205
219
  specification_version: 4
206
220
  summary: Suse Customer Center plugin for Foreman
207
221
  test_files:
222
+ - test/unit/foreman_scc_manager_test.rb
223
+ - test/test_controller_helper.rb
224
+ - test/features/sync_test.rb
225
+ - test/models/scc_product_test.rb
226
+ - test/models/scc_account_test.rb
227
+ - test/factories/foreman_scc_manager_factories.rb
208
228
  - test/controllers/api/v2/scc_accounts_test.rb
209
229
  - test/controllers/api/v2/scc_products_test.rb
210
- - test/test_plugin_helper.rb
211
- - test/features/sync_test.rb
230
+ - test/controllers/scc_accounts_controller_test2.rb
231
+ - test/controllers/scc_accounts_controller_test.rb
212
232
  - test/support/fixtures_support.rb
213
- - test/fixtures/models/scc_products.yml
214
233
  - test/fixtures/models/scc_accounts.yml
215
- - test/fixtures/files/data_subscriptions.json
234
+ - test/fixtures/models/scc_repositories.yml
235
+ - test/fixtures/models/scc_products.yml
236
+ - test/fixtures/models/scc_extendings.yml
237
+ - test/fixtures/files/data_products_page2.json
216
238
  - test/fixtures/files/data_products_page1.json
239
+ - test/fixtures/files/data_subscriptions.json
217
240
  - test/fixtures/files/data_repositories.json
218
- - test/fixtures/files/data_products_page2.json
219
- - test/models/scc_product_test.rb
220
- - test/models/scc_account_test.rb
221
- - test/unit/foreman_scc_manager_test.rb
222
- - test/factories/foreman_scc_manager_factories.rb
241
+ - test/test_plugin_helper.rb