Skip to content
Permalink
Browse files

Adapt Y2Packager::Product to the new API

  • Loading branch information...
imobachgs committed Apr 4, 2018
1 parent 0cc79cf commit 98d493001eaa451c86710197b8fa63d78e6ccfb1
Showing with 28 additions and 54 deletions.
  1. +9 −21 library/packages/src/lib/y2packager/product.rb
  2. +19 −33 library/packages/test/y2packager/product_test.rb
@@ -12,8 +12,8 @@

Yast.import "Pkg"
require "y2packager/product_reader"
require "y2packager/license_reader"
require "y2packager/release_notes_reader"
require "y2packager/product_license"

module Y2Packager
# Represent a product which is present in a repository. At this
@@ -196,39 +196,34 @@ def label

# Return the license to confirm
#
# It will return the empty string ("") if the license does not exist or if
# it was already confirmed.
#
# @param lang [String] Language
# @return [String,nil] Product's license; nil if the product was not found.
# @return [ProductLicense,nil] Product's license; nil if the license was not found.
def license
license_reader.license
@license ||= ProductLicense.find(name, :rpm)
end

# Return the license text to be confirmed
#
# It will return the empty string ("") if the license does not exist or if
# it was already confirmed.
#
# @param lang [String] Language
# @return [String,nil] Product's license; nil if the product was not found.
# @return [String] Product's license; empty string ("") if no license was found.
def license_content(lang)
license_reader.license_content(lang)
return "" unless license?
license.content_for(lang)
end

# Determines whether the product has a license
#
# @param lang [String] Language
# @return [Boolean] true if the product has a license
def license?
license ? true : false
!!license
end

# Determine whether the license should be accepted or not
#
# @return [Boolean] true if the license acceptance is required
def license_confirmation_required?
license_reader.license_confirmation_required?
license.license_confirmation_required?
end

# Set license confirmation for the product
@@ -254,7 +249,7 @@ def license_confirmed?
#
# @return [Array<String>] Language codes ("de_DE", "en_US", etc.)
def license_locales
license_reader.locales
license.locales
end

# Return product's release notes
@@ -306,12 +301,5 @@ def resolvable_properties
data["version"] == version
end
end

private

def license_reader
# FIXME: Determine which source should be used
@license_reader ||= LicenseReader.new(name)
end
end
end
@@ -17,12 +17,13 @@
let(:reader) { Y2Packager::ProductReader.new }
let(:sles) { instance_double(Y2Packager::Product) }
let(:sdk) { instance_double(Y2Packager::Product) }
let(:product_license) { instance_double(Y2Packager::ProductLicense, content_for: "content") }
let(:products) { [sles, sdk] }
let(:license_reader) { product.send(:license_reader) }

before do
allow(Y2Packager::ProductReader).to receive(:new).and_return(reader)
allow(reader).to receive(:all_products).and_return(products)
allow(product).to receive(:license).and_return(product_license)
end

describe ".selected_base" do
@@ -186,50 +187,33 @@
end

describe "#license_content" do
let(:license_content) { "license content" }
let(:lang) { "en_US" }

before do
allow(license_reader).to receive(:license_content).and_return(license_content)
end

it "return the license content" do
expect(product.license_content(lang)).to eq(license_content)
it "returns the license content" do
expect(product_license).to receive(:content_for).with(lang).and_return("content")
expect(product.license_content(lang)).to eq("content")
end

context "when the no license to confirm was found" do
let(:license_content) { "" }
context "when no license was found" do
let(:product_license) { nil }

it "return the empty string" do
it "returns the empty string" do
expect(product.license_content(lang)).to eq("")
end
end

context "when the product does not exist" do
let(:license_content) { nil }

it "return nil" do
expect(product.license_content(lang)).to be_nil
end
end
end

describe "#license?" do
let(:lang) { "en_US" }
let(:license) { instance_double("Y2Packager::License") }

before do
allow(product).to receive(:license).and_return(license)
end
context "when the product has a license" do
let(:product_license) { instance_double(Y2Packager::ProductLicense) }

context "when product has a license" do
it "returns true" do
expect(product.license?).to eq(true)
end
end

context "when product does not have a license" do
let(:license) { nil }
context "when the product does not have a license" do
let(:product_license) { nil }

it "returns false" do
expect(product.license?).to eq(false)
@@ -238,16 +222,18 @@
end

describe "#license_locales" do
it "returns license locales from the corrsponding fetcher" do
expect(license_reader).to receive(:locales).and_return(["en_US", "de_DE"])
let(:product_license) do
instance_double(Y2Packager::ProductLicense, locales: ["en_US", "de_DE"])
end

expect(product.license_locales).to eq(["en_US", "de_DE"])
it "returns product license locales" do
expect(product.license_locales).to eq(product_license.locales)
end
end

describe "#license_confirmation_required?" do
before do
allow(license_reader).to receive(:license_confirmation_required?).and_return(needed)
allow(product_license).to receive(:license_confirmation_required?).and_return(needed)
end

context "when accepting the license is required" do
@@ -268,7 +254,7 @@
end

describe "#license_confirmation=" do
let(:license) { instance_double(Y2Packager::License, accept!: true, reject!: true) }
let(:license) { instance_double(Y2Packager::ProductLicense, accept!: true, reject!: true) }

before do
allow(product).to receive(:license).and_return(license)

0 comments on commit 98d4930

Please sign in to comment.
You can’t perform that action at this time.