-
Notifications
You must be signed in to change notification settings - Fork 44
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
131 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
# ------------------------------------------------------------------------------ | ||
# Copyright (c) 2018 SUSE LLC, All Rights Reserved. | ||
# | ||
# This program is free software; you can redistribute it and/or modify it under | ||
# the terms of version 2 of the GNU General Public License as published by the | ||
# Free Software Foundation. | ||
# | ||
# This program is distributed in the hope that it will be useful, but WITHOUT | ||
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS | ||
# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. | ||
# ------------------------------------------------------------------------------ | ||
|
||
require "y2packager/licenses_handlers/rpm" | ||
|
||
module Y2Packager | ||
module LicensesHandlers | ||
# Return the licenses proper fetcher for a given source | ||
# | ||
# @param source [Symbol] :rpm or :url | ||
def self.for(source, product_name) | ||
klass = const_get(source.to_s.capitalize) | ||
klass.new(product_name) | ||
end | ||
end | ||
end |
46 changes: 46 additions & 0 deletions
46
library/packages/src/lib/y2packager/licenses_handlers/rpm.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
# ------------------------------------------------------------------------------ | ||
# Copyright (c) 2018 SUSE LLC, All Rights Reserved. | ||
# | ||
# This program is free software; you can redistribute it and/or modify it under | ||
# the terms of version 2 of the GNU General Public License as published by the | ||
# Free Software Foundation. | ||
# | ||
# This program is distributed in the hope that it will be useful, but WITHOUT | ||
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS | ||
# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. | ||
# ------------------------------------------------------------------------------ | ||
|
||
Yast.import "Pkg" | ||
|
||
module Y2Packager | ||
module LicensesHandlers | ||
class Rpm | ||
attr_reader :product_name | ||
|
||
# Constructor | ||
# | ||
# @param product_name [String] Product's name | ||
def initialize(product_name) | ||
@product_name = product_name | ||
end | ||
|
||
# Determine whether the license should be accepted or not | ||
# | ||
# @return [Boolean] true if the license acceptance is required | ||
def license_confirmation_required? | ||
Yast::Pkg.PrdNeedToAcceptLicense(product_name) | ||
end | ||
|
||
# Set the license confirmation for the product | ||
# | ||
# @param confirmed [Boolean] true if it should be accepted; false otherwise | ||
def license_confirmation=(confirmed) | ||
if confirmed | ||
Yast::Pkg.PrdMarkLicenseConfirmed(product_name) | ||
else | ||
Yast::Pkg.PrdMarkLicenseNotConfirmed(product_name) | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 45 additions & 0 deletions
45
library/packages/test/y2packager/licenses_handlers/rpm_test.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
#!/usr/bin/env rspec | ||
# ------------------------------------------------------------------------------ | ||
# Copyright (c) 2018 SUSE LLC, All Rights Reserved. | ||
# | ||
# This program is free software; you can redistribute it and/or modify it under | ||
# the terms of version 2 of the GNU General Public License as published by the | ||
# Free Software Foundation. | ||
# | ||
# This program is distributed in the hope that it will be useful, but WITHOUT | ||
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS | ||
# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. | ||
# ------------------------------------------------------------------------------ | ||
|
||
require_relative "../../test_helper" | ||
|
||
require "y2packager/product_license" | ||
|
||
describe Y2Packager::LicensesHandlers::Rpm do | ||
subject(:handler) { described_class.new(product_name) } | ||
|
||
let(:product_name) { "SLES" } | ||
|
||
describe "#license_confirmation_required?" do | ||
before do | ||
allow(Yast::Pkg).to receive(:PrdNeedToAcceptLicense) | ||
.with(product_name).and_return(needed) | ||
end | ||
|
||
context "when according to libzypp the license is required to be confirmed" do | ||
let(:needed) { true } | ||
|
||
it "returns true" do | ||
expect(handler.license_confirmation_required?).to eq(true) | ||
end | ||
end | ||
|
||
context "when according to libzypp the license is not required to be confirmed" do | ||
let(:needed) { false } | ||
|
||
it "returns false" do | ||
expect(handler.license_confirmation_required?).to eq(false) | ||
end | ||
end | ||
end | ||
end |