Skip to content

Commit

Permalink
use the status call and properly mark the already registered extensions
Browse files Browse the repository at this point in the history
- 3.1.82
  • Loading branch information
lslezak committed Jul 1, 2014
1 parent f0c8806 commit 37e1ce3
Show file tree
Hide file tree
Showing 6 changed files with 62 additions and 8 deletions.
7 changes: 7 additions & 0 deletions package/yast2-registration.changes
@@ -1,3 +1,10 @@
-------------------------------------------------------------------
Tue Jul 1 11:49:20 UTC 2014 - lslezak@suse.cz

- use the status call and properly mark the already registered
extensions
- 3.1.82

-------------------------------------------------------------------
Mon Jun 30 11:36:46 UTC 2014 - lslezak@suse.cz

Expand Down
6 changes: 3 additions & 3 deletions package/yast2-registration.spec
Expand Up @@ -17,7 +17,7 @@


Name: yast2-registration
Version: 3.1.81
Version: 3.1.82
Release: 0

BuildRoot: %{_tmppath}/%{name}-%{version}-build
Expand All @@ -31,7 +31,7 @@ Requires: yast2 >= 3.1.26
Requires: yast2-pkg-bindings >= 2.17.20
# N_() method
Requires: yast2-ruby-bindings >= 3.1.12
Requires: rubygem-suse-connect >= 0.1.2
Requires: rubygem-suse-connect >= 0.2.0
Requires: yast2-slp >= 3.1.2
Requires: yast2-add-on >= 3.1.8
Requires: yast2-packager >= 3.1.22
Expand All @@ -41,7 +41,7 @@ BuildRequires: update-desktop-files
BuildRequires: yast2-devtools >= 3.1.6
BuildRequires: rubygem-yast-rake >= 0.1.8
BuildRequires: rubygem-rspec
BuildRequires: rubygem-suse-connect >= 0.1.2
BuildRequires: rubygem-suse-connect >= 0.2.0
BuildRequires: yast2-slp >= 3.1.2
BuildRequires: yast2-packager >= 3.1.22

Expand Down
12 changes: 11 additions & 1 deletion src/lib/registration/addon.rb
Expand Up @@ -27,8 +27,18 @@ class << self
def find_all(registration)
return @cached_addons if @cached_addons
pure_addons = registration.get_addon_list
activated_addons = registration.activated_products

@cached_addons = pure_addons.reduce([]) do |res, addon|
res.concat(create_addon_with_deps(addon))
yast_addons = create_addon_with_deps(addon)
res.concat(yast_addons)

# mark the root addon as registered if found in activated addons
if activated_addons.find { |activated_addon| activated_addon.id == addon.id }
yast_addons.first.registered
end

res
end
end

Expand Down
7 changes: 7 additions & 0 deletions src/lib/registration/registration.rb
Expand Up @@ -99,6 +99,13 @@ def get_addon_list
addons.reject{ |a| a.identifier == base_product["name"] }
end

def activated_products
activated = SUSE::Connect::YaST.status(connect_params({})).activated_products || []
log.info "Number of activated products: #{activated.size}"
log.debug "Activated products: #{activated.inspect}"
activated
end

def self.is_registered?
SUSE::Connect::System.registered?
end
Expand Down
37 changes: 33 additions & 4 deletions test/addon_spec.rb
Expand Up @@ -19,26 +19,52 @@
it "find all addons for current base product" do
prod1 = addon_generator
prod2 = addon_generator
registration = double(:get_addon_list => [prod1, prod2])
registration = double(
:activated_products => [],
:get_addon_list => [prod1, prod2]
)

expect(Registration::Addon.find_all(registration).size).to be 2
end

it "find even dependend products" do
prod1 = addon_with_child_generator
registration = double(:get_addon_list => [prod1])
registration = double(
:activated_products => [],
:get_addon_list => [prod1]
)

expect(Registration::Addon.find_all(registration).size).to be 2
end

it "sets properly dependencies between addons" do
prod1 = addon_with_child_generator
registration = double(:get_addon_list => [prod1])
registration = double(
:activated_products => [],
:get_addon_list => [prod1]
)

addons = Registration::Addon.find_all(registration)
expect(addons.any? {|addon| addon.children.size == 1}).to be_true
expect(addons.any?(&:depends_on)).to be_true
end

it "sets the registration status from status call" do
prod1 = addon_generator("name" => "prod1")
prod2 = addon_generator("name" => "prod2")
registration = double(
:activated_products => [prod1],
:get_addon_list => [prod1, prod2]
)

addons = Registration::Addon.find_all(registration)

addon1 = addons.find{ |addon| addon.name == "prod1"}
addon2 = addons.find{ |addon| addon.name == "prod2"}

expect(addon1.registered?).to be_true
expect(addon2.registered?).to be_false
end
end

describe ".selected" do
Expand Down Expand Up @@ -118,7 +144,10 @@

describe "#selectable?" do
let(:addons) do
Registration::Addon.find_all(double(:get_addon_list => [addon_with_child_generator]))
Registration::Addon.find_all(double(
:get_addon_list => [addon_with_child_generator],
:activated_products => []
))
end

let(:parent) { addons.first }
Expand Down
1 change: 1 addition & 0 deletions test/factories.rb
Expand Up @@ -7,6 +7,7 @@ def suse_connect_product_generator(attrs={})
params['name'] = attrs['name'] || "Product#{rand(100000)}"
params['friendly_name'] = attrs['friendly_name'] || "The best cool #{params['name']}"
params['description'] = attrs['description'] || "Bla bla bla bla!"
params["id"] = attrs["id"] || "#{rand(10000)}"
params['identifier'] = attrs['zypper_name'] || "prod#{rand(100000)}"
params['version'] = attrs['version'] || "#{rand(13)}"
params['arch'] = attrs['arch'] || "x86_64"
Expand Down

0 comments on commit 37e1ce3

Please sign in to comment.