From 3e3ad61c2e89d68aaa33847f085d99c1027f5ff4 Mon Sep 17 00:00:00 2001 From: Partha Aji Date: Thu, 9 Oct 2014 11:06:17 -0400 Subject: [PATCH] Ref #7880: Rubocop fixes update --- .rubocop.yml | 20 ++ .rubocop_todo.yml | 296 ------------------ Rakefile | 20 +- lib/runcible.rb | 2 +- lib/runcible/base.rb | 51 ++- lib/runcible/extensions/consumer.rb | 51 ++- lib/runcible/extensions/consumer_group.rb | 23 +- lib/runcible/extensions/distribution.rb | 2 - lib/runcible/extensions/docker_image.rb | 1 - lib/runcible/extensions/errata.rb | 3 - lib/runcible/extensions/package_category.rb | 3 - lib/runcible/extensions/package_group.rb | 2 - lib/runcible/extensions/puppet_module.rb | 3 - lib/runcible/extensions/repository.rb | 151 ++++----- lib/runcible/extensions/rpm.rb | 10 +- lib/runcible/extensions/unit.rb | 21 +- .../extensions/yum_repo_metadata_file.rb | 3 - lib/runcible/instance.rb | 46 ++- lib/runcible/models/distributor.rb | 9 +- lib/runcible/models/docker_distributor.rb | 8 +- lib/runcible/models/docker_importer.rb | 4 +- lib/runcible/models/export_distributor.rb | 2 +- lib/runcible/models/importer.rb | 9 +- lib/runcible/models/iso_distributor.rb | 2 +- lib/runcible/models/iso_importer.rb | 2 +- lib/runcible/models/nodes_http_distributor.rb | 1 - lib/runcible/models/puppet_distributor.rb | 4 +- lib/runcible/models/yum_clone_distributor.rb | 7 +- lib/runcible/models/yum_distributor.rb | 14 +- lib/runcible/models/yum_importer.rb | 34 +- lib/runcible/resources/consumer.rb | 39 ++- lib/runcible/resources/consumer_group.rb | 28 +- lib/runcible/resources/content.rb | 20 +- lib/runcible/resources/event_notifier.rb | 16 +- lib/runcible/resources/repository.rb | 52 +-- lib/runcible/resources/repository_group.rb | 12 +- lib/runcible/resources/repository_schedule.rb | 12 +- lib/runcible/resources/role.rb | 15 +- lib/runcible/resources/task.rb | 23 +- lib/runcible/resources/unit.rb | 9 +- lib/runcible/resources/user.rb | 17 +- lib/runcible/version.rb | 2 +- runcible.gemspec | 16 +- test/extensions/consumer_group_test.rb | 44 ++- test/extensions/consumer_test.rb | 95 +++--- test/extensions/distribution_test.rb | 18 +- test/extensions/docker_repository_test.rb | 40 +-- test/extensions/errata_test.rb | 17 +- test/extensions/iso_repository_test.rb | 12 +- test/extensions/package_category_test.rb | 14 +- test/extensions/package_group_test.rb | 20 +- test/extensions/puppet_repository_test.rb | 60 ++-- test/extensions/repository_test.rb | 65 ++-- test/extensions/rpm_test.rb | 21 +- test/extensions/unit_base.rb | 23 +- test/extensions/yum_clone_distributor_test.rb | 12 +- test/models/puppet_distributor_test.rb | 6 +- test/models/puppet_importer_test.rb | 4 +- .../models/puppet_install_distributor_test.rb | 6 +- test/resources/consumer_group_test.rb | 70 ++--- test/resources/consumer_test.rb | 69 ++-- test/resources/content_test.rb | 18 +- test/resources/event_notifier_test.rb | 17 +- test/resources/puppet_repository_test.rb | 9 +- test/resources/repository_group_test.rb | 33 +- test/resources/repository_schedule_test.rb | 19 +- test/resources/repository_test.rb | 90 +++--- test/resources/role_test.rb | 10 +- test/resources/task_test.rb | 14 +- test/resources/user_test.rb | 15 +- test/support/consumer_group_support.rb | 9 +- test/support/consumer_support.rb | 12 +- test/support/logger_support.rb | 6 - test/support/repository_support.rb | 69 ++-- test/test_runner.rb | 126 ++++---- test/unit/base_test.rb | 34 +- test/vcr_setup.rb | 10 +- 77 files changed, 809 insertions(+), 1343 deletions(-) diff --git a/.rubocop.yml b/.rubocop.yml index f1e4222b..a89044de 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -3,6 +3,11 @@ inherit_from: - .rubocop_todo.yml # end TODO +AllCops: + RunRailsCops: false # automatically run rails cops + Exclude: + - test/**/** + MethodLength: Description: 'Avoid methods longer than 30 lines of code.' Max: 45 # TODO: set to 30 @@ -75,3 +80,18 @@ FormatString: Style/WordArray: Enabled: false # don't force usage of %w() + +Style/LineLength: + Max: 120 + +Style/GuardClause: + Enabled: false + +Style/ClassLength: + Max: 600 + +Style/CyclomaticComplexity: + Enabled: false + +Style/StringLiterals: + Enabled: false \ No newline at end of file diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 400f0484..e69de29b 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -1,296 +0,0 @@ -# This configuration was generated by `rubocop --auto-gen-config` -# on 2014-10-09 10:45:26 -0400 using RuboCop version 0.24.1. -# The point is for the user to remove these configuration records -# one by one as the offenses are removed from the code base. -# Note that changes in the inspected code, or installation of new -# versions of RuboCop, may require this file to be generated again. - -# Offense count: 1 -Lint/BlockAlignment: - Enabled: false - -# Offense count: 1 -# Cop supports --auto-correct. -Lint/DeprecatedClassMethods: - Enabled: false - -# Offense count: 2 -# Configuration parameters: AlignWith, SupportedStyles. -Lint/EndAlignment: - Enabled: false - -# Offense count: 10 -Lint/HandleExceptions: - Enabled: false - -# Offense count: 12 -Lint/ParenthesesAsGroupedExpression: - Enabled: false - -# Offense count: 8 -# Cop supports --auto-correct. -Lint/RescueException: - Enabled: false - -# Offense count: 7 -# Cop supports --auto-correct. -Lint/StringConversionInInterpolation: - Enabled: false - -# Offense count: 1 -# Cop supports --auto-correct. -Lint/UnusedBlockArgument: - Enabled: false - -# Offense count: 40 -# Cop supports --auto-correct. -Lint/UnusedMethodArgument: - Enabled: false - -# Offense count: 16 -Lint/UselessAssignment: - Enabled: false - -# Offense count: 1 -Lint/Void: - Enabled: false - -# Offense count: 7 -Rails/Output: - Enabled: false - -# Offense count: 2 -Style/AccessorMethodName: - Enabled: false - -# Offense count: 1 -# Cop supports --auto-correct. -Style/AlignArray: - Enabled: false - -# Offense count: 10 -# Cop supports --auto-correct. -# Configuration parameters: EnforcedHashRocketStyle, EnforcedColonStyle, EnforcedLastArgumentHashStyle, SupportedLastArgumentHashStyles. -Style/AlignHash: - Enabled: false - -# Offense count: 42 -# Cop supports --auto-correct. -# Configuration parameters: EnforcedStyle, SupportedStyles. -Style/BracesAroundHashParameters: - Enabled: false - -# Offense count: 5 -# Configuration parameters: IndentWhenRelativeTo, SupportedStyles, IndentOneStep. -Style/CaseIndentation: - Enabled: false - -# Offense count: 1 -# Configuration parameters: EnforcedStyle, SupportedStyles. -Style/ClassAndModuleChildren: - Enabled: false - -# Offense count: 2 -# Cop supports --auto-correct. -# Configuration parameters: EnforcedStyle, SupportedStyles. -Style/ClassCheck: - Enabled: false - -# Offense count: 3 -# Configuration parameters: CountComments. -Style/ClassLength: - Max: 167 - -# Offense count: 25 -Style/ClassVars: - Enabled: false - -# Offense count: 32 -# Cop supports --auto-correct. -# Configuration parameters: PreferredMethods. -Style/CollectionMethods: - Enabled: false - -# Offense count: 1 -# Configuration parameters: Keywords. -Style/CommentAnnotation: - Enabled: false - -# Offense count: 7 -Style/CyclomaticComplexity: - Max: 11 - -# Offense count: 3 -# Cop supports --auto-correct. -Style/DeprecatedHashMethods: - Enabled: false - -# Offense count: 1 -Style/EachWithObject: - Enabled: false - -# Offense count: 65 -# Cop supports --auto-correct. -Style/EmptyLines: - Enabled: false - -# Offense count: 185 -# Cop supports --auto-correct. -Style/EmptyLinesAroundBody: - Enabled: false - -# Offense count: 3 -# Configuration parameters: MinBodyLength. -Style/GuardClause: - Enabled: false - -# Offense count: 6 -# Cop supports --auto-correct. -# Configuration parameters: EnforcedStyle, SupportedStyles. -Style/IndentHash: - Enabled: false - -# Offense count: 7 -# Cop supports --auto-correct. -Style/IndentationConsistency: - Enabled: false - -# Offense count: 16 -# Cop supports --auto-correct. -Style/IndentationWidth: - Enabled: false - -# Offense count: 426 -# Configuration parameters: AllowURI. -Style/LineLength: - Max: 149 - -# Offense count: 15 -# Cop supports --auto-correct. -Style/MethodCallParentheses: - Enabled: false - -# Offense count: 1 -Style/MethodCalledOnDoEndBlock: - Enabled: false - -# Offense count: 1 -# Cop supports --auto-correct. -# Configuration parameters: EnforcedStyle, SupportedStyles. -Style/MethodDefParentheses: - Enabled: false - -# Offense count: 4 -# Configuration parameters: CountComments. -Style/MethodLength: - Max: 45 - -# Offense count: 2 -Style/MultilineBlockChain: - Enabled: false - -# Offense count: 4 -# Cop supports --auto-correct. -Style/NegatedIf: - Enabled: false - -# Offense count: 1 -# Cop supports --auto-correct. -Style/NegatedWhile: - Enabled: false - -# Offense count: 8 -# Cop supports --auto-correct. -Style/NilComparison: - Enabled: false - -# Offense count: 3 -# Cop supports --auto-correct. -Style/RedundantBegin: - Enabled: false - -# Offense count: 1 -Style/RegexpLiteral: - MaxSlashes: 0 - -# Offense count: 1 -# Cop supports --auto-correct. -# Configuration parameters: AllowAsExpressionSeparator. -Style/Semicolon: - Enabled: false - -# Offense count: 7 -# Cop supports --auto-correct. -# Configuration parameters: EnforcedStyle, SupportedStyles. -Style/SignalException: - Enabled: false - -# Offense count: 33 -# Cop supports --auto-correct. -Style/SingleSpaceBeforeFirstArg: - Enabled: false - -# Offense count: 7 -# Cop supports --auto-correct. -Style/SpaceAfterComma: - Enabled: false - -# Offense count: 75 -# Cop supports --auto-correct. -# Configuration parameters: EnforcedStyle, SupportedStyles. -Style/SpaceAroundEqualsInParameterDefault: - Enabled: false - -# Offense count: 122 -# Cop supports --auto-correct. -Style/SpaceAroundOperators: - Enabled: false - -# Offense count: 51 -# Cop supports --auto-correct. -# Configuration parameters: EnforcedStyle, SupportedStyles. -Style/SpaceBeforeBlockBraces: - Enabled: false - -# Offense count: 95 -# Cop supports --auto-correct. -# Configuration parameters: EnforcedStyle, SupportedStyles, EnforcedStyleForEmptyBraces, SpaceBeforeBlockParameters. -Style/SpaceInsideBlockBraces: - Enabled: false - -# Offense count: 2 -# Cop supports --auto-correct. -Style/SpaceInsideBrackets: - Enabled: false - -# Offense count: 423 -# Cop supports --auto-correct. -# Configuration parameters: EnforcedStyle, SupportedStyles. -Style/StringLiterals: - Enabled: false - -# Offense count: 1 -Style/Tab: - Enabled: false - -# Offense count: 32 -# Cop supports --auto-correct. -# Configuration parameters: EnforcedStyle, SupportedStyles. -Style/TrailingBlankLines: - Enabled: false - -# Offense count: 24 -# Cop supports --auto-correct. -Style/TrailingWhitespace: - Enabled: false - -# Offense count: 8 -# Cop supports --auto-correct. -# Configuration parameters: ExactNameMatch, AllowPredicates, AllowDSLWriters, Whitelist. -Style/TrivialAccessors: - Enabled: false - -# Offense count: 1 -# Cop supports --auto-correct. -Style/WhileUntilDo: - Enabled: false diff --git a/Rakefile b/Rakefile index bad72fb7..9d67b3ba 100755 --- a/Rakefile +++ b/Rakefile @@ -1,6 +1,6 @@ #!/usr/bin/env rake -require "bundler/gem_tasks" -require "rake/testtask" +require 'bundler/gem_tasks' +require 'rake/testtask' def clear_cassettes `rm -rf test/fixtures/vcr_cassettes/*.yml` @@ -9,9 +9,8 @@ def clear_cassettes print "Cassettes cleared\n" end - namespace :test do - "Runs the unit tests" + desc 'Runs the unit tests' Rake::TestTask.new :unit do |t| t.pattern = 'test/unit/test_*.rb' end @@ -27,9 +26,9 @@ namespace :test do options[:logging] = ENV['logging'] if !['new_episodes', 'all', 'none', 'once'].include?(options[:mode]) - puts "Invalid test mode" + puts 'Invalid test mode' else - require "./test/test_runner" + require './test/test_runner' test_runner = PulpMiniTestRunner.new @@ -41,13 +40,13 @@ namespace :test do clear_cassettes if options[:mode] == 'all' && options[:test_name].nil? && ENV['record'] != 'false' test_runner.run_tests(task_name, options) - Rake::Task[:update_test_version].invoke if options[:mode] == "all" && ENV['record'] != 'false' + Rake::Task[:update_test_version].invoke if options[:mode] == 'all' && ENV['record'] != 'false' end end end end -desc "Updats the version of Pulp tested against in README" +desc 'Updats the version of Pulp tested against in README' task :update_test_version do text = File.open('README.md').read @@ -60,12 +59,12 @@ task :update_test_version do end end -desc "Clears out all cassette files" +desc 'Clears out all cassette files' task :clear_cassettes do clear_cassettes end -desc "Runs all tests" +desc 'Runs all tests' task :test do Rake::Task['test:unit'].invoke Rake::Task['test:models'].invoke @@ -77,4 +76,5 @@ begin require 'rubocop/rake_task' RuboCop::RakeTask.new rescue + puts "Rubocop not loaded" end diff --git a/lib/runcible.rb b/lib/runcible.rb index d4cab2f1..db095dbb 100644 --- a/lib/runcible.rb +++ b/lib/runcible.rb @@ -36,4 +36,4 @@ resources += Dir[File.dirname(__FILE__) + '/runcible/models/distributor.rb'] resources += Dir[File.dirname(__FILE__) + '/runcible/models/*.rb'] -resources.uniq.each{ |f| require f } +resources.uniq.each { |f| require f } diff --git a/lib/runcible/base.rb b/lib/runcible/base.rb index 350defe7..8a230b50 100644 --- a/lib/runcible/base.rb +++ b/lib/runcible/base.rb @@ -26,11 +26,9 @@ require 'json' require 'thread' - module Runcible class Base - - def initialize(config={}) + def initialize(config = {}) @mutex = Mutex.new @config = config end @@ -42,7 +40,7 @@ def lazy_config=(a_block) def config @mutex.synchronize do @config = @lazy_config.call if defined?(@lazy_config) - raise Runcible::ConfigurationUndefinedError, Runcible::ConfigurationUndefinedError.message unless @config + fail Runcible::ConfigurationUndefinedError, Runcible::ConfigurationUndefinedError.message unless @config @config end end @@ -51,16 +49,12 @@ def path(*args) self.class.path(*args) end - def call(method, path, options={}) + def call(method, path, options = {}) clone_config = self.config.clone #on occation path will already have prefix (sync cancel) - path = clone_config[:api_path] + path if !path.start_with?(clone_config[:api_path]) + path = clone_config[:api_path] + path unless path.start_with?(clone_config[:api_path]) RestClient.log = [] - logger = clone_config[:logging][:logger] - debug_logging = clone_config[:logging][:debug] - exception_logging = clone_config[:logging][:exception] - headers = clone_config[:headers].clone get_params = options[:params] if options[:params] @@ -72,7 +66,7 @@ def call(method, path, options={}) if clone_config[:oauth] headers = add_oauth_header(method, path, headers) if clone_config[:oauth] - headers["pulp-user"] = clone_config[:user] + headers['pulp-user'] = clone_config[:user] client = RestClient::Resource.new(clone_config[:url], client_options) else client_options[:user] = clone_config[:user] @@ -93,7 +87,7 @@ def call(method, path, options={}) end def get_response(client, path, *args) - client[path].send(*args) do |response, request, result, &block| + client[path].send(*args) do |response, request, result, &_block| resp = response.return!(request, result) log_debug return resp @@ -101,14 +95,14 @@ def get_response(client, path, *args) end def combine_get_params(path, params) - query_string = params.collect do |k, v| + query_string = params.map do |k, v| if v.is_a? Array - v.collect{|y| "#{k.to_s}=#{y.to_s}" }.join('&') + v.map { |y| "#{k}=#{y}" }.join('&') else - "#{k.to_s}=#{v.to_s}" + "#{k}=#{v}" end end - query_string = query_string.flatten().join('&') + query_string = query_string.flatten.join('&') path + "?#{query_string}" end @@ -146,19 +140,20 @@ def process_response(response) if body.respond_to? :with_indifferent_access body = body.with_indifferent_access elsif body.is_a? Array - body = body.collect do |i| + body = body.map do |i| i.respond_to?(:with_indifferent_access) ? i.with_indifferent_access : i end end response = RestClient::Response.create(body, response.net_http_res, response.args) rescue JSON::ParserError + log_exception end return response end - def required_params(local_names, binding, keys_to_remove=[]) - local_names = local_names.reduce({}) do |acc, v| + def required_params(local_names, binding, keys_to_remove = []) + local_names = local_names.each_with_object({}) do |v, acc| value = binding.eval(v.to_s) unless v == :_ acc[v] = value unless value.nil? acc @@ -167,8 +162,8 @@ def required_params(local_names, binding, keys_to_remove=[]) #The double delete is to support 1.8.7 and 1.9.3 local_names.delete(:payload) local_names.delete(:optional) - local_names.delete("payload") - local_names.delete("optional") + local_names.delete('payload') + local_names.delete('optional') keys_to_remove.each do |key| local_names.delete(key) local_names.delete(key.to_sym) @@ -184,9 +179,9 @@ def add_http_auth_header def add_oauth_header(method, path, headers) default_options = { :site => config[:url], :http_method => method, - :request_token_path => "", - :authorize_path => "", - :access_token_path => "" } + :request_token_path => '', + :authorize_path => '', + :access_token_path => '' } default_options[:ca_file] = config[:ca_cert_file] unless config[:ca_cert_file].nil? consumer = OAuth::Consumer.new(config[:oauth][:oauth_key], config[:oauth][:oauth_secret], default_options) @@ -205,7 +200,7 @@ def add_oauth_header(method, path, headers) def log_debug if self.config[:logging][:debug] - log_message = generate_log_message + log_message = generate_log_message self.config[:logging][:logger].debug(log_message) end end @@ -224,14 +219,12 @@ def generate_log_message def logger self.config[:logging][:logger] end - - end + end class ConfigurationUndefinedError < StandardError - def self.message # override me to change the error message - "Configuration not set. Runcible::Base.config= must be called before Runcible::Base.config." + 'Configuration not set. Runcible::Base.config= must be called before Runcible::Base.config.' end end end diff --git a/lib/runcible/extensions/consumer.rb b/lib/runcible/extensions/consumer.rb index 2e361f8e..f1286cb8 100644 --- a/lib/runcible/extensions/consumer.rb +++ b/lib/runcible/extensions/consumer.rb @@ -21,11 +21,9 @@ # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - module Runcible module Extensions class Consumer < Runcible::Resources::Consumer - # Bind a consumer to all repositories with a given ID # # @param [String] id the consumer ID @@ -35,10 +33,11 @@ class Consumer < Runcible::Resources::Consumer # @option options [Boolean] :notify_agent sends consumer a notification # @option options [Hash] :binding_config sends consumer a notification # @return [RestClient::Response] set of tasks representing each bind operation - def bind_all(id, repo_id, type_id, options={}) - repository_extension.retrieve_with_details(repo_id)['distributors'].collect do |d| + def bind_all(id, repo_id, type_id, options = {}) + details = repository_extension.retrieve_with_details(repo_id)['distributors'].map do |d| bind(id, repo_id, d['id'], options) if d['distributor_type_id'] == type_id - end.reject{|f| f.nil?}.flatten + end + details.compact.flatten end # Unbind a consumer to all repositories with a given ID @@ -48,9 +47,10 @@ def bind_all(id, repo_id, type_id, options={}) # @param [String] type_id the distributor type_id to unbind from # @return [RestClient::Response] set of tasks representing each unbind operation def unbind_all(id, repo_id, type_id) - repository_extension.retrieve_with_details(repo_id)['distributors'].collect do |d| + details = repository_extension.retrieve_with_details(repo_id)['distributors'].map do |d| unbind(id, repo_id, d['id']) if d['distributor_type_id'] == type_id - end.reject{|f| f.nil?}.flatten + end + details.compact.flatten end # Activate a consumer as a pulp node @@ -58,9 +58,9 @@ def unbind_all(id, repo_id, type_id) # @param [String] id the consumer ID # @param [String] update_strategy update_strategy for the node (defaults to additive) # @return [RestClient::Response] response from update call - def activate_node(id, update_strategy="additive") - delta = {:notes=>{'_child-node' => true, - '_node-update-strategy' => update_strategy}} + def activate_node(id, update_strategy = 'additive') + delta = {:notes => {'_child-node' => true, + '_node-update-strategy' => update_strategy}} self.update(id, delta) end @@ -69,9 +69,9 @@ def activate_node(id, update_strategy="additive") # @param [String] id the consumer ID # @return [RestClient::Response] response from update call def deactivate_node(id) - delta = {:notes=>{'child-node' => nil, - 'update_strategy' => nil}} - self.update(id, :delta=>delta) + delta = {:notes => {'child-node' => nil, + 'update_strategy' => nil}} + self.update(id, :delta => delta) end # Install content to a consumer @@ -81,7 +81,7 @@ def deactivate_node(id) # @param [Array] units array of units to install # @param [Hash] options to pass to content install # @return [RestClient::Response] task representing the install operation - def install_content(id, type_id, units, options={}) + def install_content(id, type_id, units, options = {}) install_units(id, generate_content(type_id, units), options) end @@ -92,7 +92,7 @@ def install_content(id, type_id, units, options={}) # @param [Array] units array of units to update # @param [Hash] options to pass to content update # @return [RestClient::Response] task representing the update operation - def update_content(id, type_id, units, options={}) + def update_content(id, type_id, units, options = {}) update_units(id, generate_content(type_id, units, options), options) end @@ -112,18 +112,18 @@ def uninstall_content(id, type_id, units) # @param [Array] units array of units # @param [Hash] options contains options which may impact the format of the content (e.g :all => true) # @return [Array] array of formatted content units - def generate_content(type_id, units, options={}) + def generate_content(type_id, units, options = {}) content = [] case type_id - when 'rpm', 'package_group' - unit_key = :name - when 'erratum' - unit_key = :id - when 'repository' - unit_key = :repo_id - else - unit_key = :id + when 'rpm', 'package_group' + unit_key = :name + when 'erratum' + unit_key = :id + when 'repository' + unit_key = :repo_id + else + unit_key = :id end if options[:all] @@ -132,7 +132,7 @@ def generate_content(type_id, units, options={}) content_unit[:unit_key] = {} content.push(content_unit) elsif units.nil? - content = [{:unit_key=> nil, :type_id=>type_id}] + content = [{:unit_key => nil, :type_id => type_id}] else units.each do |unit| content_unit = {} @@ -184,7 +184,6 @@ def applicable_errata(ids) def repository_extension Runcible::Extensions::Repository.new(self.config) end - end end end diff --git a/lib/runcible/extensions/consumer_group.rb b/lib/runcible/extensions/consumer_group.rb index 4eeeee19..821e2e95 100644 --- a/lib/runcible/extensions/consumer_group.rb +++ b/lib/runcible/extensions/consumer_group.rb @@ -21,11 +21,9 @@ # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - module Runcible module Extensions class ConsumerGroup < Runcible::Resources::ConsumerGroup - # Add consumers by ID to a consumer group # # @param [String] id the consumer group ID @@ -51,7 +49,7 @@ def remove_consumers_by_id(id, consumer_ids) def make_consumer_criteria(consumer_ids) {:criteria => {:filters => - {:id =>{"$in" =>consumer_ids}} + {:id => {'$in' => consumer_ids}} } } end @@ -63,7 +61,7 @@ def make_consumer_criteria(consumer_ids) # @param [Array] units array of units to install # @param [Hash] options to pass to content install # @return [RestClient::Response] task representing the install operation - def install_content(id, type_id, units, options={}) + def install_content(id, type_id, units, options = {}) install_units(id, generate_content(type_id, units), options) end @@ -74,7 +72,7 @@ def install_content(id, type_id, units, options={}) # @param [Array] units array of units to update # @param [Hash] options to pass to content update # @return [RestClient::Response] task representing the update operation - def update_content(id, type_id, units, options={}) + def update_content(id, type_id, units, options = {}) update_units(id, generate_content(type_id, units, options), options) end @@ -94,16 +92,16 @@ def uninstall_content(id, type_id, units) # @param [Array] units array of units # @param [Hash] options contains options which may impact the format of the content (e.g :all => true) # @return [Array] array of formatted content units - def generate_content(type_id, units, options={}) + def generate_content(type_id, units, options = {}) content = [] case type_id - when 'rpm', 'package_group' - unit_key = :name - when 'erratum' - unit_key = :id - else - unit_key = :id + when 'rpm', 'package_group' + unit_key = :name + when 'erratum' + unit_key = :id + else + unit_key = :id end if options[:all] @@ -121,7 +119,6 @@ def generate_content(type_id, units, options={}) end content end - end end end diff --git a/lib/runcible/extensions/distribution.rb b/lib/runcible/extensions/distribution.rb index 80508e4a..d7fac7dd 100644 --- a/lib/runcible/extensions/distribution.rb +++ b/lib/runcible/extensions/distribution.rb @@ -21,11 +21,9 @@ # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - module Runcible module Extensions class Distribution < Runcible::Extensions::Unit - def self.content_type 'distribution' end diff --git a/lib/runcible/extensions/docker_image.rb b/lib/runcible/extensions/docker_image.rb index 545576ba..ecef0d5c 100644 --- a/lib/runcible/extensions/docker_image.rb +++ b/lib/runcible/extensions/docker_image.rb @@ -21,7 +21,6 @@ # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - module Runcible module Extensions class DockerImage < Runcible::Extensions::Unit diff --git a/lib/runcible/extensions/errata.rb b/lib/runcible/extensions/errata.rb index 6573c807..18855f18 100644 --- a/lib/runcible/extensions/errata.rb +++ b/lib/runcible/extensions/errata.rb @@ -21,15 +21,12 @@ # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - module Runcible module Extensions class Errata < Runcible::Extensions::Unit - def self.content_type 'erratum' end - end end end diff --git a/lib/runcible/extensions/package_category.rb b/lib/runcible/extensions/package_category.rb index aa317339..ef72c6da 100644 --- a/lib/runcible/extensions/package_category.rb +++ b/lib/runcible/extensions/package_category.rb @@ -21,15 +21,12 @@ # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - module Runcible module Extensions class PackageCategory < Runcible::Extensions::Unit - def self.content_type 'package_category' end - end end end diff --git a/lib/runcible/extensions/package_group.rb b/lib/runcible/extensions/package_group.rb index 465f7cdc..bfa118a4 100644 --- a/lib/runcible/extensions/package_group.rb +++ b/lib/runcible/extensions/package_group.rb @@ -21,11 +21,9 @@ # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - module Runcible module Extensions class PackageGroup < Runcible::Extensions::Unit - def self.content_type 'package_group' end diff --git a/lib/runcible/extensions/puppet_module.rb b/lib/runcible/extensions/puppet_module.rb index 603d5bd8..d6057866 100644 --- a/lib/runcible/extensions/puppet_module.rb +++ b/lib/runcible/extensions/puppet_module.rb @@ -21,15 +21,12 @@ # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - module Runcible module Extensions class PuppetModule < Runcible::Extensions::Unit - def self.content_type 'puppet_module' end - end end end diff --git a/lib/runcible/extensions/repository.rb b/lib/runcible/extensions/repository.rb index fac0f484..557c3993 100644 --- a/lib/runcible/extensions/repository.rb +++ b/lib/runcible/extensions/repository.rb @@ -21,15 +21,14 @@ # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - module Runcible module Extensions class Repository < Runcible::Resources::Repository - # Utility function that allows an importer to be added at repository creation time # # @param [String] id the id of the repository being created - # @param [Hash, Runcible::Extensions::Importer] importer either a hash representing an importer or an Importer object + # @param [Hash, Runcible::Extensions::Importer] importer either a hash representing an importer or + # an Importer object # @return [RestClient::Response] the created repository def create_with_importer(id, importer) create_with_importer_and_distributors(id, importer) @@ -38,7 +37,8 @@ def create_with_importer(id, importer) # Utility function that allows distributors to be added at repository creation time # # @param [String] id the id of the repository being created - # @param [Array] distributors an array of hashes representing distributors or an array of Distributor objects + # @param [Array] distributors an array of hashes representing distributors or + # an array of Distributor objects # @return [RestClient::Response] the created repository def create_with_distributors(id, distributors) create_with_importer_and_distributors(id, nil, distributors) @@ -47,11 +47,13 @@ def create_with_distributors(id, distributors) # Utility function that allows an importer and distributors to be added at repository creation time # # @param [String] id the id of the repository being created - # @param [Hash, Runcible::Extensions::Importer] importer either a hash representing an importer or an Importer object - # @param [Array] distributors an array of hashes representing distributors or an array of Distributor objects + # @param [Hash, Runcible::Extensions::Importer] importer either a hash representing an importer or + # an Importer object + # @param [Array] distributors an array of hashes representing distributors or + # an array of Distributor objects # @param [Hash] optional container for all optional parameters # @return [RestClient::Response] the created repository - def create_with_importer_and_distributors(id, importer, distributors=[], optional={}) + def create_with_importer_and_distributors(id, importer, distributors = [], optional = {}) if importer.is_a?(Runcible::Models::Importer) optional[:importer_type_id] = importer.id optional[:importer_config] = importer.config @@ -62,32 +64,32 @@ def create_with_importer_and_distributors(id, importer, distributors=[], optiona repo_type = if importer.methods.include?(:repo_type) importer.repo_type - elsif importer.is_a?(Hash) && importer.has_key?(:repo_type) + elsif importer.is_a?(Hash) && importer.key?(:repo_type) importer[:repo_type] else nil end - if optional.has_key?(:importer_type_id) && repo_type + if optional.key?(:importer_type_id) && repo_type # pulp needs _repo-type in order to determine the type of repo to create. optional[:notes] = { '_repo-type' => importer.repo_type } end - optional[:distributors] = distributors.collect do |d| + optional[:distributors] = distributors.map do |d| if d.is_a?(Runcible::Models::Distributor) {'distributor_type_id' => d.type_id, - "distributor_config" => d.config, - "auto_publish" => d.auto_publish, - "distributor_id" => d.id + 'distributor_config' => d.config, + 'auto_publish' => d.auto_publish, + 'distributor_id' => d.id } else {'distributor_type_id' => d['type_id'], - "distributor_config" => d['config'], - "auto_publish" => d['auto_publish'], - "distributor_id" => d['id'] + 'distributor_config' => d['config'], + 'auto_publish' => d['auto_publish'], + 'distributor_id' => d['id'] } end - end if !distributors.empty? + end unless distributors.empty? optional[:id] = id create(id, optional) end @@ -97,7 +99,7 @@ def create_with_importer_and_distributors(id, importer, distributors=[], optiona # @param [String] repo_id the repository ID # @return [RestClient::Response] a task representing the sync status def sync_status(repo_id) - Runcible::Resources::Task.new(self.config).list(["pulp:repository:#{repo_id}", "pulp:action:sync"]) + Runcible::Resources::Task.new(self.config).list(["pulp:repository:#{repo_id}", 'pulp:action:sync']) end # Retrieves the publish status for a repository @@ -105,7 +107,7 @@ def sync_status(repo_id) # @param [String] repo_id the repository ID # @return [RestClient::Response] a task representing the sync status def publish_status(repo_id) - Runcible::Resources::Task.new(self.config).list(["pulp:repository:#{repo_id}", "pulp:action:publish"]) + Runcible::Resources::Task.new(self.config).list(["pulp:repository:#{repo_id}", 'pulp:action:publish']) end # Retrieves a set of repositories by their IDs @@ -114,34 +116,39 @@ def publish_status(repo_id) # @return [RestClient::Response] the set of repositories requested def search_by_repository_ids(repository_ids) criteria = {:filters => - { "id" => {"$in" => repository_ids}} + { 'id' => {'$in' => repository_ids}} } search(criteria) end - # Retrieves the RPM IDs for a single repository # # @param [String] id the ID of the repository # @return [Array] the array of repository RPM IDs def rpm_ids(id) - criteria = {:type_ids=>[Runcible::Extensions::Rpm.content_type], - :fields=>{:unit=>[], :association=>['unit_id']}} - self.unit_search(id, criteria).collect{|i| i['unit_id']} + criteria = {:type_ids => [Runcible::Extensions::Rpm.content_type], + :fields => {:unit => [], :association => ['unit_id']}} + self.unit_search(id, criteria).map { |i| i['unit_id'] } rescue RestClient::RequestTimeout - self.logger.warn("Call to rpm_ids timed out") + self.logger.warn('Call to rpm_ids timed out') # lazy evaluated iterator from zero to infinite - pages = Enumerator.new { |y| page = 0; loop { y << page; page += 1 } } + pages = Enumerator.new do |y| + page = 0 + loop do + y << page + page += 1 + end + end - # TODO this is hotfix, pagination support should be added to Runcible - pages.inject([]) do |rpm_ids, page| + # TODO: this is hotfix, pagination support should be added to Runcible + pages.reduce([]) do |rpm_ids, page| page_size = 500 criteria = { :type_ids => [Runcible::Extensions::Rpm.content_type], :fields => { :unit => [], :association => ['unit_id'] }, :limit => page_size, - :skip => 0 + page*page_size } - result = unit_search(id, criteria).collect { |i| i['unit_id'] } + :skip => 0 + page * page_size } + result = unit_search(id, criteria).map { |i| i['unit_id'] } rpm_ids.concat(result) if result.empty? || result.size < 500 break rpm_ids @@ -156,8 +163,8 @@ def rpm_ids(id) # @param [String] id the ID of the repository # @return [RestClient::Response] the set of repository RPMs def rpms(id) - criteria = {:type_ids=>[Runcible::Extensions::Rpm.content_type]} - unit_search(id, criteria).collect{|i| i['metadata'].with_indifferent_access} + criteria = {:type_ids => [Runcible::Extensions::Rpm.content_type]} + unit_search(id, criteria).map { |i| i['metadata'].with_indifferent_access } end # Retrieves the RPMs by NVRE for a single repository @@ -168,23 +175,23 @@ def rpms(id) # @param [String] release the release of the RPMs # @param [String] epoch the epoch of the RPMs # @return [RestClient::Response] the set of repository RPMs - def rpms_by_nvre(id, name, version=nil, release=nil, epoch=nil) + def rpms_by_nvre(id, name, version = nil, release = nil, epoch = nil) and_condition = [] - and_condition << {:name=>name} if name - and_condition << {:version=>version} if version - and_condition << {:release=>release} if release - and_condition << {:epoch=>epoch} if epoch - - criteria = {:type_ids=>[Runcible::Extensions::Rpm.content_type], - :filters => { - :unit => { - "$and" => and_condition - } - }, - :sort => { - :unit => [ ['name', 'ascending'], ['version', 'descending'] ] - }} - unit_search(id, criteria).collect{|p| p['metadata'].with_indifferent_access} + and_condition << {:name => name} if name + and_condition << {:version => version} if version + and_condition << {:release => release} if release + and_condition << {:epoch => epoch} if epoch + + criteria = {:type_ids => [Runcible::Extensions::Rpm.content_type], + :filters => { + :unit => { + '$and' => and_condition + } + }, + :sort => { + :unit => [['name', 'ascending'], ['version', 'descending']] + }} + unit_search(id, criteria).map { |p| p['metadata'].with_indifferent_access } end # Retrieves the errata IDs for a single repository @@ -192,10 +199,10 @@ def rpms_by_nvre(id, name, version=nil, release=nil, epoch=nil) # @param [String] id the ID of the repository # @return [RestClient::Response] the set of repository errata IDs def errata_ids(id) - criteria = {:type_ids=>[Runcible::Extensions::Errata.content_type], - :fields=>{:unit=>[], :association=>['unit_id']}} + criteria = {:type_ids => [Runcible::Extensions::Errata.content_type], + :fields => {:unit => [], :association => ['unit_id']}} - unit_search(id, criteria).collect{|i| i['unit_id']} + unit_search(id, criteria).map { |i| i['unit_id'] } end # Retrieves the errata for a single repository @@ -203,8 +210,8 @@ def errata_ids(id) # @param [String] id the ID of the repository # @return [RestClient::Response] the set of repository errata def errata(id) - criteria = {:type_ids=>[Runcible::Extensions::Errata.content_type]} - unit_search(id, criteria).collect{|i| i['metadata'].with_indifferent_access} + criteria = {:type_ids => [Runcible::Extensions::Errata.content_type]} + unit_search(id, criteria).map { |i| i['metadata'].with_indifferent_access } end # Retrieves the distributions for a single repository @@ -212,9 +219,9 @@ def errata(id) # @param [String] id the ID of the repository # @return [RestClient::Response] the set of repository distributions def distributions(id) - criteria = {:type_ids=>[Runcible::Extensions::Distribution.content_type]} + criteria = {:type_ids => [Runcible::Extensions::Distribution.content_type]} - unit_search(id, criteria).collect{|i| i['metadata'].with_indifferent_access} + unit_search(id, criteria).map { |i| i['metadata'].with_indifferent_access } end # Retrieves the package groups for a single repository @@ -222,9 +229,9 @@ def distributions(id) # @param [String] id the ID of the repository # @return [RestClient::Response] the set of repository package groups def package_groups(id) - criteria = {:type_ids=>[Runcible::Extensions::PackageGroup.content_type]} + criteria = {:type_ids => [Runcible::Extensions::PackageGroup.content_type]} - unit_search(id, criteria).collect{|i| i['metadata'].with_indifferent_access} + unit_search(id, criteria).map { |i| i['metadata'].with_indifferent_access } end # Retrieves the package group categoriess for a single repository @@ -232,8 +239,8 @@ def package_groups(id) # @param [String] id the ID of the repository # @return [RestClient::Response] the set of repository package group categories def package_categories(id) - criteria = {:type_ids=>[Runcible::Extensions::PackageCategory.content_type]} - unit_search(id, criteria).collect{|i| i['metadata'].with_indifferent_access} + criteria = {:type_ids => [Runcible::Extensions::PackageCategory.content_type]} + unit_search(id, criteria).map { |i| i['metadata'].with_indifferent_access } end # Retrieves the puppet module IDs for a single repository @@ -241,10 +248,10 @@ def package_categories(id) # @param [String] id the ID of the repository # @return [RestClient::Response] the set of repository puppet module IDs def puppet_module_ids(id) - criteria = {:type_ids=>[Runcible::Extensions::PuppetModule.content_type], - :fields=>{:unit=>[], :association=>['unit_id']}} + criteria = {:type_ids => [Runcible::Extensions::PuppetModule.content_type], + :fields => {:unit => [], :association => ['unit_id']}} - unit_search(id, criteria).collect{|i| i['unit_id']} + unit_search(id, criteria).map { |i| i['unit_id'] } end # Retrieves the puppet modules for a single repository @@ -252,8 +259,8 @@ def puppet_module_ids(id) # @param [String] id the ID of the repository # @return [RestClient::Response] the set of repository puppet modules def puppet_modules(id) - criteria = {:type_ids=>[Runcible::Extensions::PuppetModule.content_type]} - unit_search(id, criteria).collect{|i| i['metadata'].with_indifferent_access} + criteria = {:type_ids => [Runcible::Extensions::PuppetModule.content_type]} + unit_search(id, criteria).map { |i| i['metadata'].with_indifferent_access } end # Retrieves the docker image IDs for a single repository @@ -261,10 +268,10 @@ def puppet_modules(id) # @param [String] id the ID of the repository # @return [RestClient::Response] the set of repository docker image IDs def docker_image_ids(id) - criteria = {:type_ids=>[Runcible::Extensions::DockerImage.content_type], - :fields=>{:unit=>[], :association=>['unit_id']}} + criteria = {:type_ids => [Runcible::Extensions::DockerImage.content_type], + :fields => {:unit => [], :association => ['unit_id']}} - unit_search(id, criteria).collect{|i| i['unit_id']} + unit_search(id, criteria).map { |i| i['unit_id'] } end # Retrieves the docker images for a single repository @@ -272,8 +279,8 @@ def docker_image_ids(id) # @param [String] id the ID of the repository # @return [RestClient::Response] the set of repository docker images def docker_images(id) - criteria = {:type_ids=>[Runcible::Extensions::DockerImage.content_type]} - unit_search(id, criteria).collect{|i| i['metadata'].with_indifferent_access} + criteria = {:type_ids => [Runcible::Extensions::DockerImage.content_type]} + unit_search(id, criteria).map { |i| i['metadata'].with_indifferent_access } end # Creates or updates a sync schedule for a repository @@ -287,7 +294,8 @@ def create_or_update_schedule(repo_id, type, schedule) if schedules.empty? Runcible::Resources::RepositorySchedule.new(self.config).create(repo_id, type, schedule) else - Runcible::Resources::RepositorySchedule.new(self.config).update(repo_id, type, schedules[0]['_id'], {:schedule=>schedule}) + Runcible::Resources::RepositorySchedule.new(self.config).update(repo_id, type, + schedules[0]['_id'], :schedule => schedule) end end @@ -320,7 +328,7 @@ def publish_all(repo_id) # @param [String] repo_id the ID of the repository # @return [RestClient::Response] the repository with full details def retrieve_with_details(repo_id) - retrieve(repo_id, {:details => true}) + retrieve(repo_id, :details => true) end # Regenerate the applicability for consumers bound to a given set of repositories @@ -333,7 +341,6 @@ def regenerate_applicability_by_ids(ids) } regenerate_applicability(criteria) end - end end end diff --git a/lib/runcible/extensions/rpm.rb b/lib/runcible/extensions/rpm.rb index 5eb95c7e..9e4d030c 100644 --- a/lib/runcible/extensions/rpm.rb +++ b/lib/runcible/extensions/rpm.rb @@ -21,28 +21,26 @@ # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - module Runcible module Extensions class Rpm < Runcible::Extensions::Unit - def self.content_type 'rpm' end # This function is not implemented for RPMs since they do not have content IDs def find - raise NotImplementedError + fail NotImplementedError end # This function is not implemented for RPMs since they do not have content IDs def find_all - raise NotImplementedError + fail NotImplementedError end # This function is not implemented for RPMs since they do not have content IDs - def unassociate_ids_from_repo(repo_id, ids) - raise NotImplementedError + def unassociate_ids_from_repo(_repo_id, _ids) + fail NotImplementedError end end end diff --git a/lib/runcible/extensions/unit.rb b/lib/runcible/extensions/unit.rb index b57c9b00..af3aad6e 100644 --- a/lib/runcible/extensions/unit.rb +++ b/lib/runcible/extensions/unit.rb @@ -21,14 +21,12 @@ # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - module Runcible module Extensions class Unit < Runcible::Resources::Unit - # The content type (e.g. rpm, errata) def self.content_type - raise "Content type not defined" + fail 'Content type not defined' end def content_type @@ -46,7 +44,7 @@ def all # # @param [Array] id the content ID of the content to retrieve # @return [RestClient::Response] the requested content - def find(id, optional={}) + def find(id, optional = {}) optional[:include_repos] ||= true find_all([id], optional).first end @@ -55,16 +53,16 @@ def find(id, optional={}) # # @param [Array] ids list of content IDs to retrieve # @return [RestClient::Response] list of content - def find_all(ids, optional={}) + def find_all(ids, optional = {}) optional[:include_repos] ||= true - search(content_type, { :filters => {'id'=> {'$in'=> ids}} }, optional) + search(content_type, { :filters => {'id' => {'$in' => ids}} }, optional) end # Retrieves a single content by it's unit ID # # @param [Array] id the unit ID of the content to retrieve # @return [RestClient::Response] the requested content - def find_by_unit_id(id, optional={}) + def find_by_unit_id(id, optional = {}) optional[:include_repos] ||= true find_all_by_unit_ids([id], [], optional).first end @@ -74,9 +72,9 @@ def find_by_unit_id(id, optional={}) # @param [Array] ids list of content unit IDs to retrieve # @param [Array] fields optional list of to retrieve # @return [RestClient::Response] list of content - def find_all_by_unit_ids(ids, fields=[], optional={}) + def find_all_by_unit_ids(ids, fields = [], optional = {}) optional[:include_repos] ||= true - criteria = { :filters => { :_id => { '$in'=> ids } } } + criteria = { :filters => { :_id => { '$in' => ids } } } criteria[:fields] = fields unless fields.empty? search(content_type, criteria, optional) end @@ -122,14 +120,14 @@ def unassociate_unit_ids_from_repo(repo_id, ids) # @param [String] destination_repo_id the destination repository ID # @param [Hash] optional container for all optional parameters # @return [RestClient::Response] a task representing the unit copy operation - def copy(source_repo_id, destination_repo_id, optional={}) + def copy(source_repo_id, destination_repo_id, optional = {}) criteria = {:type_ids => [content_type], :filters => {}} criteria[:filters]['association'] = {'unit_id' => {'$in' => optional[:ids]}} if optional[:ids] criteria[:filters] = optional[:filters] if optional[:filters] criteria[:fields] = {:unit => optional[:fields]} if optional[:fields] payload = {:criteria => criteria} - payload[:override_config] = optional[:override_config] if optional.has_key?(:override_config) + payload[:override_config] = optional[:override_config] if optional.key?(:override_config) if optional[:copy_children] payload[:override_config] ||= {} @@ -138,7 +136,6 @@ def copy(source_repo_id, destination_repo_id, optional={}) Runcible::Extensions::Repository.new(self.config).unit_copy(destination_repo_id, source_repo_id, payload) end - end end end diff --git a/lib/runcible/extensions/yum_repo_metadata_file.rb b/lib/runcible/extensions/yum_repo_metadata_file.rb index cafdbac8..893ee805 100644 --- a/lib/runcible/extensions/yum_repo_metadata_file.rb +++ b/lib/runcible/extensions/yum_repo_metadata_file.rb @@ -21,15 +21,12 @@ # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - module Runcible module Extensions class YumRepoMetadataFile < Runcible::Extensions::Unit - def self.content_type 'yum_repo_metadata_file' end - end end end diff --git a/lib/runcible/instance.rb b/lib/runcible/instance.rb index 5c6f0b57..d571343d 100644 --- a/lib/runcible/instance.rb +++ b/lib/runcible/instance.rb @@ -23,14 +23,14 @@ module Runcible class Instance - + # rubocop:disable Style/ClassVars def self.resource_classes - @@resource_classes ||= gather_classes("resources") + @@resource_classes ||= gather_classes('resources') @@resource_classes end def self.extension_classes - @@extension_classes ||= gather_classes("extensions") + @@extension_classes ||= gather_classes('extensions') @@extension_classes end @@ -46,20 +46,20 @@ def self.extension_classes # @option config [String] :url Scheme and hostname for the pulp server e.g. https://localhost/ # @option config [String] :api_path URL path for the api e.g. pulp/api/v2/ # @option config [String] :timeout Timeout in seconds for the connection (defaults to rest client's default) - # @option config [String] :open_timeout timeout in seconds for the connection to open(defaults to rest client's default) + # @option config [String] :open_timeout timeout in seconds for the connection + # to open(defaults to rest client's default) # @option config [Hash] :http_auth Needed when using simple http auth # @option http_auth [String] :password The password to use for simple auth - def initialize(config={}) + def initialize(config = {}) @config = { - :api_path => '/pulp/api/v2/', - :url => 'https://localhost', - :user => '', - :http_auth => {:password => {} }, - :headers => {:content_type => 'application/json', - :accept => 'application/json'}, - :logging => {} - }.merge(config).with_indifferent_access - + :api_path => '/pulp/api/v2/', + :url => 'https://localhost', + :user => '', + :http_auth => {:password => {} }, + :headers => {:content_type => 'application/json', + :accept => 'application/json'}, + :logging => {} + }.merge(config).with_indifferent_access initialize_wrappers(config) end @@ -71,13 +71,11 @@ def update_config(key, value) @config[key] = value end - def config - @config - end + attr_reader :config private - def initialize_wrappers(config) + def initialize_wrappers(_config) self.resources = Wrapper.new('resources') self.extensions = Wrapper.new('extensions') @@ -95,22 +93,20 @@ def initialize_wrappers(config) def accessible_class(class_object) #converts a class (Runcible::Resources::ConsumerGroup) to a user friendly name: # (e.g. consumer_group) - class_object.name.split("::").last.underscore + class_object.name.split('::').last.underscore end def self.gather_classes(type) const = Runcible const = const.const_get(type.camelize) path = File.dirname(__FILE__) + "/#{type}/*.rb" - base_names = Dir.glob(path).collect{|f| File.basename(f, '.rb') } - classes = base_names.collect{|name| const.const_get(name.camelize)} + base_names = Dir.glob(path).map { |f| File.basename(f, '.rb') } + base_names.map { |name| const.const_get(name.camelize) } end - end #Wrapper class to provide access to instances class Wrapper - def initialize(name) @name = name @methods = [] @@ -122,9 +118,7 @@ def set_instance(attr_name, instance) end def to_s - "#{@name} - #{@methods.uniq.sort.to_s}" + "#{@name} - #{@methods.uniq.sort}" end end - end - diff --git a/lib/runcible/models/distributor.rb b/lib/runcible/models/distributor.rb index 66812989..2ddb6d4a 100644 --- a/lib/runcible/models/distributor.rb +++ b/lib/runcible/models/distributor.rb @@ -29,10 +29,10 @@ module Models class Distributor attr_accessor 'auto_publish', 'id' - def initialize(params={}) + def initialize(params = {}) @auto_publish = false - id = params[:id] || SecureRandom.hex(10) - params.each{|k,v| send("#{k.to_s}=",v)} + self.id = params[:id] || SecureRandom.hex(10) + params.each { |k, v| send("#{k}=", v) } end # Distributor Type id @@ -43,9 +43,8 @@ def type_id end def self.type_id - raise NotImplementedError("self.type_id") + fail NotImplementedError('self.type_id') end - end end end diff --git a/lib/runcible/models/docker_distributor.rb b/lib/runcible/models/docker_distributor.rb index 300df11c..853c7de8 100644 --- a/lib/runcible/models/docker_distributor.rb +++ b/lib/runcible/models/docker_distributor.rb @@ -28,10 +28,10 @@ module Runcible module Models class DockerDistributor < Distributor #optional - attr_accessor "docker_publish_directory", "protected", - "redirect_url", "repo_registry_id" + attr_accessor 'docker_publish_directory', 'protected', + 'redirect_url', 'repo_registry_id' - def initialize(params={}) + def initialize(params = {}) super(params) end @@ -47,4 +47,4 @@ def config end end end -end \ No newline at end of file +end diff --git a/lib/runcible/models/docker_importer.rb b/lib/runcible/models/docker_importer.rb index 59822c90..c84aa263 100644 --- a/lib/runcible/models/docker_importer.rb +++ b/lib/runcible/models/docker_importer.rb @@ -27,8 +27,8 @@ class DockerImporter < Importer ID = 'docker_importer' REPO_TYPE = 'docker-repo' - attr_accessor 'feed', 'max_speed','max_downloads', 'upstream_name', - 'proxy_port', 'proxy_password', 'proxy_username', "mask_id" + attr_accessor 'feed', 'max_speed', 'max_downloads', 'upstream_name', + 'proxy_port', 'proxy_password', 'proxy_username', 'mask_id' def id DockerImporter::ID diff --git a/lib/runcible/models/export_distributor.rb b/lib/runcible/models/export_distributor.rb index 97da7e72..a41c0a71 100644 --- a/lib/runcible/models/export_distributor.rb +++ b/lib/runcible/models/export_distributor.rb @@ -28,7 +28,7 @@ module Runcible module Models class ExportDistributor < Distributor #required - attr_accessor "http", "https" + attr_accessor 'http', 'https' # Instantiates a export distributor # diff --git a/lib/runcible/models/importer.rb b/lib/runcible/models/importer.rb index bd01aa32..aeb7128a 100644 --- a/lib/runcible/models/importer.rb +++ b/lib/runcible/models/importer.rb @@ -24,17 +24,14 @@ require 'active_support/core_ext/hash' require 'active_support/json' - module Runcible module Models - - # Generic class to represent Pulp Importers + # Generic class to represent Pulp Importers # Child classes should supply id & config methods class Importer - def initialize(params={}) - params.each{|k,v| send("#{k.to_s}=",v)} + def initialize(params = {}) + params.each { |k, v| send("#{k}=", v) } end end - end end diff --git a/lib/runcible/models/iso_distributor.rb b/lib/runcible/models/iso_distributor.rb index 6c29101d..bed4897f 100644 --- a/lib/runcible/models/iso_distributor.rb +++ b/lib/runcible/models/iso_distributor.rb @@ -28,7 +28,7 @@ module Runcible module Models class IsoDistributor < Distributor #required - attr_accessor "serve_http", "serve_https" + attr_accessor 'serve_http', 'serve_https' # Instantiates an iso distributor # diff --git a/lib/runcible/models/iso_importer.rb b/lib/runcible/models/iso_importer.rb index 5aa318f5..6f32c8fc 100644 --- a/lib/runcible/models/iso_importer.rb +++ b/lib/runcible/models/iso_importer.rb @@ -41,7 +41,7 @@ def id # # @return [Hash] def config - as_json + as_json end end end diff --git a/lib/runcible/models/nodes_http_distributor.rb b/lib/runcible/models/nodes_http_distributor.rb index f2c25920..9ccc240a 100644 --- a/lib/runcible/models/nodes_http_distributor.rb +++ b/lib/runcible/models/nodes_http_distributor.rb @@ -27,7 +27,6 @@ module Runcible module Models class NodesHttpDistributor < Distributor - # Instantiates an nodes distributor # # @param [Hash] params Distributor options diff --git a/lib/runcible/models/puppet_distributor.rb b/lib/runcible/models/puppet_distributor.rb index 4001a2d4..fc186d02 100644 --- a/lib/runcible/models/puppet_distributor.rb +++ b/lib/runcible/models/puppet_distributor.rb @@ -29,7 +29,7 @@ module Models class PuppetDistributor < Distributor attr_accessor 'serve_http', 'serve_https', 'http_dir', 'https_dir', 'absolute_path' - def initialize(absolute_path, http, https, params={}) + def initialize(absolute_path, http, https, params = {}) @absolute_path = absolute_path @serve_http = http @serve_https = https @@ -48,4 +48,4 @@ def config end end end -end \ No newline at end of file +end diff --git a/lib/runcible/models/yum_clone_distributor.rb b/lib/runcible/models/yum_clone_distributor.rb index 9cc83128..9a0a45dd 100644 --- a/lib/runcible/models/yum_clone_distributor.rb +++ b/lib/runcible/models/yum_clone_distributor.rb @@ -29,11 +29,10 @@ module Models # Requires the pulp-katello-plugins # https://github.com/Katello/pulp-katello-plugins class YumCloneDistributor < Distributor - #optional - attr_accessor "source_repo_id", "source_distributor_id", "destination_distributor_id" + attr_accessor 'source_repo_id', 'source_distributor_id', 'destination_distributor_id' - def initialize(params={}) + def initialize(params = {}) super(params) end @@ -49,4 +48,4 @@ def config end end end -end \ No newline at end of file +end diff --git a/lib/runcible/models/yum_distributor.rb b/lib/runcible/models/yum_distributor.rb index 11da22b9..d5072d8c 100644 --- a/lib/runcible/models/yum_distributor.rb +++ b/lib/runcible/models/yum_distributor.rb @@ -28,14 +28,14 @@ module Runcible module Models class YumDistributor < Distributor #required - attr_accessor "relative_url", "http", "https" + attr_accessor 'relative_url', 'http', 'https' #optional - attr_accessor "protected", "auth_cert", "auth_ca", - "https_ca", "gpgkey", "generate_metadata", - "checksum_type", "skip", "https_publish_dir", "http_publish_dir" + attr_accessor 'protected', 'auth_cert', 'auth_ca', + 'https_ca', 'gpgkey', 'generate_metadata', + 'checksum_type', 'skip', 'https_publish_dir', 'http_publish_dir' - def initialize(relative_url, http, https, params={}) - @relative_url=relative_url + def initialize(relative_url, http, https, params = {}) + @relative_url = relative_url @http = http @https = https super(params) @@ -53,4 +53,4 @@ def config end end end -end \ No newline at end of file +end diff --git a/lib/runcible/models/yum_importer.rb b/lib/runcible/models/yum_importer.rb index 68798948..23275a2d 100644 --- a/lib/runcible/models/yum_importer.rb +++ b/lib/runcible/models/yum_importer.rb @@ -24,26 +24,26 @@ module Runcible module Models class YumImporter < Importer - ID = 'yum_importer' - REPO_TYPE = 'rpm-repo' + ID = 'yum_importer' + REPO_TYPE = 'rpm-repo' - #https://github.com/pulp/pulp/blob/master/rpm-support/plugins/importers/yum_importer/importer.py - attr_accessor 'feed', 'ssl_verify', 'ssl_ca_cert', 'ssl_client_cert', 'ssl_client_key', - 'proxy_url', 'proxy_port', 'proxy_pass', 'proxy_user', - 'max_speed', 'verify_size', 'verify_checksum', 'num_threads', - 'newest', 'remove_old', 'num_old_packages', 'purge_orphaned', 'skip', 'checksum_type', - 'num_retries', 'retry_delay' - def id - YumImporter::ID - end + #https://github.com/pulp/pulp/blob/master/rpm-support/plugins/importers/yum_importer/importer.py + attr_accessor 'feed', 'ssl_verify', 'ssl_ca_cert', 'ssl_client_cert', 'ssl_client_key', + 'proxy_url', 'proxy_port', 'proxy_pass', 'proxy_user', + 'max_speed', 'verify_size', 'verify_checksum', 'num_threads', + 'newest', 'remove_old', 'num_old_packages', 'purge_orphaned', 'skip', 'checksum_type', + 'num_retries', 'retry_delay' + def id + YumImporter::ID + end - def repo_type - YumImporter::REPO_TYPE - end + def repo_type + YumImporter::REPO_TYPE + end - def config - as_json - end + def config + as_json end + end end end diff --git a/lib/runcible/resources/consumer.rb b/lib/runcible/resources/consumer.rb index 2983fb2d..455b3343 100644 --- a/lib/runcible/resources/consumer.rb +++ b/lib/runcible/resources/consumer.rb @@ -21,18 +21,16 @@ # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - module Runcible module Resources # @see https://pulp-dev-guide.readthedocs.org/en/latest/rest-api/consumer/index.html class Consumer < Runcible::Base - # Generates the API path for Consumers # # @param [String] id the ID of the consumer # @return [String] the consumer path, may contain the id if passed - def self.path(id=nil) - (id == nil) ? "consumers/" : "consumers/#{id}/" + def self.path(id = nil) + (id.nil?) ? 'consumers/' : "consumers/#{id}/" end # Creates a consumer @@ -40,7 +38,7 @@ def self.path(id=nil) # @param [String] id the ID of the consumer # @param [Hash] optional container for all optional parameters # @return [RestClient::Response] - def create(id, optional={}) + def create(_id, optional = {}) required = required_params(binding.send(:local_variables), binding) call(:post, path, :payload => { :required => required, :optional => optional }) end @@ -58,7 +56,7 @@ def retrieve(id) # @param [String] id the ID of the consumer # @param [Hash] optional container for all optional parameters # @return [RestClient::Response] - def update(id, optional={}) + def update(id, optional = {}) call(:put, path(id), :payload => { :delta => optional }) end @@ -76,8 +74,8 @@ def delete(id) # @param [String] content_type the content type # @param [Hash] profile hash representing the consumer profile # @return [RestClient::Response] - def upload_profile(id, content_type, profile) - required = required_params(binding.send(:local_variables), binding, ["id"]) + def upload_profile(id, _content_type, _profile) + required = required_params(binding.send(:local_variables), binding, ['id']) call(:post, path("#{id}/profiles/"), :payload => { :required => required }) end @@ -115,9 +113,9 @@ def retrieve_bindings(id) # @param [String] distributor_id the ID of the distributor # @param [Hash] optional optional parameters # @return [RestClient::Response] - def bind(id, repo_id, distributor_id, optional={}) - required = required_params(binding.send(:local_variables), binding, ["id"]) - call(:post, path("#{id}/bindings/"), :payload => { :required => required, :optional=>optional }) + def bind(id, _repo_id, _distributor_id, optional = {}) + required = required_params(binding.send(:local_variables), binding, ['id']) + call(:post, path("#{id}/bindings/"), :payload => { :required => required, :optional => optional }) end # Unbind a consumer to a repository for a given distributor @@ -136,8 +134,8 @@ def unbind(id, repo_id, distributor_id) # @param [Array] units array of units to install # @param [Hash] options hash of install options # @return [RestClient::Response] - def install_units(id, units, options={}) - required = required_params(binding.send(:local_variables), binding, ["id"]) + def install_units(id, _units, _options = {}) + required = required_params(binding.send(:local_variables), binding, ['id']) call(:post, path("#{id}/actions/content/install/"), :payload => { :required => required }) end @@ -147,8 +145,8 @@ def install_units(id, units, options={}) # @param [Array] units array of units to update # @param [Hash] options hash of update options # @return [RestClient::Response] - def update_units(id, units, options={}) - required = required_params(binding.send(:local_variables), binding, ["id"]) + def update_units(id, _units, _options = {}) + required = required_params(binding.send(:local_variables), binding, ['id']) call(:post, path("#{id}/actions/content/update/"), :payload => { :required => required }) end @@ -158,8 +156,8 @@ def update_units(id, units, options={}) # @param [Array] units array of units to uninstall # @param [Hash] options hash of uninstall options # @return [RestClient::Response] - def uninstall_units(id, units, options={}) - required = required_params(binding.send(:local_variables), binding, ["id"]) + def uninstall_units(id, _units, _options = {}) + required = required_params(binding.send(:local_variables), binding, ['id']) call(:post, path("#{id}/actions/content/uninstall/"), :payload => { :required => required }) end @@ -168,17 +166,16 @@ def uninstall_units(id, units, options={}) # @param [Hash] options payload representing criteria # @return [RestClient::Response] def regenerate_applicability(options = {}) - call(:post, path("actions/content/regenerate_applicability/"), :payload => { :required => options}) + call(:post, path('actions/content/regenerate_applicability/'), :payload => { :required => options}) end # retrieve the applicability for some set of consumers # # @param [Hash] options hash representing criteria # @return [RestClient::Response] - def applicability(options={}) - call(:post, path + "content/applicability/", :payload => { :required => options }) + def applicability(options = {}) + call(:post, path + 'content/applicability/', :payload => { :required => options }) end - end end end diff --git a/lib/runcible/resources/consumer_group.rb b/lib/runcible/resources/consumer_group.rb index ce97e47b..725e1b9e 100644 --- a/lib/runcible/resources/consumer_group.rb +++ b/lib/runcible/resources/consumer_group.rb @@ -27,22 +27,21 @@ module Runcible module Resources # @see https://pulp-dev-guide.readthedocs.org/en/latest/rest-api/consumer/group/index.html class ConsumerGroup < Runcible::Base - # Generates the API path for Consumer Groups # # @param [String] id the ID of the consumer group - # @return [String] the consumer group path, may contain the id if passed - def path(id=nil) - groups = "consumer_groups/" + # @return [String] the consumer group path, may contain the id if passed + def path(id = nil) + groups = 'consumer_groups/' id.nil? ? groups : groups + "#{id}/" end - + # Creates a Consumer Group # # @param [String] id the ID of the consumer # @param [Hash] optional container for all optional parameters # @return [RestClient::Response] - def create(id, optional={}) + def create(_id, optional = {}) required = required_params(binding.send(:local_variables), binding) call(:post, path, :payload => { :required => required, :optional => optional }) end @@ -69,7 +68,7 @@ def delete(id) # @param [Hash] criteria criteria based on Mongo syntax representing consumers to associate # @return [RestClient::Response] def associate(id, criteria) - call(:post, path(id) + "actions/associate/", :payload => {:required => criteria}) + call(:post, path(id) + 'actions/associate/', :payload => {:required => criteria}) end # Unassociates Consumers with a Consumer Group @@ -78,7 +77,7 @@ def associate(id, criteria) # @param [Hash] criteria criteria based on Mongo syntax representing consumers ta unassociate # @return [RestClient::Response] def unassociate(id, criteria) - call(:post, path(id) + "actions/unassociate/", :payload => {:required => criteria}) + call(:post, path(id) + 'actions/unassociate/', :payload => {:required => criteria}) end # Install a set of units to a Consumer Group @@ -87,8 +86,8 @@ def unassociate(id, criteria) # @param [Array] units array of units to install # @param [Hash] options hash of install options # @return [RestClient::Response] - def install_units(id, units, options={}) - required = required_params(binding.send(:local_variables), binding, ["id"]) + def install_units(id, _units, _options = {}) + required = required_params(binding.send(:local_variables), binding, ['id']) call(:post, path("#{id}/actions/content/install"), :payload => { :required => required }) end @@ -98,8 +97,8 @@ def install_units(id, units, options={}) # @param [Array] units array of units to update # @param [Hash] options hash of update options # @return [RestClient::Response] - def update_units(id, units, options={}) - required = required_params(binding.send(:local_variables), binding, ["id"]) + def update_units(id, _units, _options = {}) + required = required_params(binding.send(:local_variables), binding, ['id']) call(:post, path("#{id}/actions/content/update"), :payload => { :required => required }) end @@ -109,11 +108,10 @@ def update_units(id, units, options={}) # @param [Array] units array of units to uninstall # @param [Hash] options hash of uninstall options # @return [RestClient::Response] - def uninstall_units(id, units, options={}) - required = required_params(binding.send(:local_variables), binding, ["id"]) + def uninstall_units(id, _units, _options = {}) + required = required_params(binding.send(:local_variables), binding, ['id']) call(:post, path("#{id}/actions/content/uninstall"), :payload => { :required => required }) end - end end end diff --git a/lib/runcible/resources/content.rb b/lib/runcible/resources/content.rb index 3d643005..c40b2486 100644 --- a/lib/runcible/resources/content.rb +++ b/lib/runcible/resources/content.rb @@ -27,13 +27,12 @@ module Runcible module Resources # @see https://pulp-dev-guide.readthedocs.org/en/latest/rest-api/content/index.html class Content < Runcible::Base - # Generates the API path for Contents # # @param [String] upload_id the id of the upload_request # @return [String] the content path, may contain the upload_id if passed - def upload_path(upload_id=nil) - (upload_id == nil) ? "content/uploads/" : "content/uploads/#{upload_id}/" + def upload_path(upload_id = nil) + (upload_id.nil?) ? 'content/uploads/' : "content/uploads/#{upload_id}/" end # Creates an Upload Request @@ -59,12 +58,14 @@ def upload_bits(upload_id, offset, content) # @param [String] repo_id identifies the associated repository # @param [String] unit_type_id identifies the type of unit the upload represents # @param [String] upload_id the id of the upload_request returned by create_upload_request - # @param [Object] unit_key unique identifier for the new unit; the contents are contingent on the type of unit being uploaded + # @param [Object] unit_key unique identifier for the new unit; the contents are contingent + # on the type of unit being uploaded # @param [Hash] optional container for all optional parameters # @return [RestClient::Response] none - def import_into_repo(repo_id, unit_type_id, upload_id, unit_key, optional={}) + def import_into_repo(repo_id, _unit_type_id, _upload_id, _unit_key, optional = {}) required = required_params(binding.send(:local_variables), binding) - call(:post, Repository.path("#{repo_id}/actions/import_upload/"), :payload => { :required =>required, :optional => optional }) + call(:post, Repository.path("#{repo_id}/actions/import_upload/"), + :payload => { :required => required, :optional => optional }) end # Delete an upload request @@ -79,7 +80,8 @@ def delete_upload_request(upload_id) # List all upload requests # # Query Parameters: None - # @return [RestClient::Response] the list of IDs for all upload requests on the server; empty list if there are none + # @return [RestClient::Response] the list of IDs for all upload requests + # on the server; empty list if there are none def list_all_requests call(:get, upload_path) end @@ -89,7 +91,7 @@ def list_all_requests # @param [String] type_id the type id of the orphaned content # @return [String] the content path, may contain the type_id if passed def orphan_path(type_id = nil) - path = "content/orphans/" + path = 'content/orphans/' path << "#{type_id}/" if type_id path end @@ -109,8 +111,6 @@ def list_orphans(type_id = nil) def remove_orphans(type_id = nil) call(:delete, orphan_path(type_id)) end - end end end - diff --git a/lib/runcible/resources/event_notifier.rb b/lib/runcible/resources/event_notifier.rb index fede09de..d2e53a43 100644 --- a/lib/runcible/resources/event_notifier.rb +++ b/lib/runcible/resources/event_notifier.rb @@ -21,12 +21,10 @@ # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - module Runcible module Resources # @see https://pulp-dev-guide.readthedocs.org/en/latest/events/index.html class EventNotifier < Runcible::Base - class EventTypes REPO_SYNC_COMPLETE = 'repo.sync.finish' REPO_SYNC_START = 'repo.sync.start' @@ -42,8 +40,8 @@ class NotifierTypes # # @param [String] id the ID of the event notifier # @return [String] the event notifier path, may contain the ID if passed - def self.path(id=nil) - (id == nil) ? "events/" : "events/#{id}/" + def self.path(id = nil) + (id.nil?) ? 'events/' : "events/#{id}/" end # Creates an Event Notification @@ -51,8 +49,8 @@ def self.path(id=nil) # @param [String] notifier_type_id the type ID of the event notifier # @param [Hash] notifier_config configuration options for the notifier # @param [Hash] event_types event types to include in the notifier - # @return [RestClient::Response] - def create(notifier_type_id, notifier_config, event_types) + # @return [RestClient::Response] + def create(_notifier_type_id, _notifier_config, _event_types) required = required_params(binding.send(:local_variables), binding) call(:post, path, :payload => {:required => required}) end @@ -60,7 +58,7 @@ def create(notifier_type_id, notifier_config, event_types) # Deletes an Event Notification # # @param [String] id the ID of the event notifier - # @return [RestClient::Response] + # @return [RestClient::Response] def delete(id) call(:delete, path(id)) end @@ -68,12 +66,10 @@ def delete(id) # List all Event Notifiers # # @param [String] id the ID of the event notifier - # @return [RestClient::Response] + # @return [RestClient::Response] def list call(:get, path) end - end end end - diff --git a/lib/runcible/resources/repository.rb b/lib/runcible/resources/repository.rb index b21e5fc4..bd31dbd2 100644 --- a/lib/runcible/resources/repository.rb +++ b/lib/runcible/resources/repository.rb @@ -31,8 +31,8 @@ class Repository < Runcible::Base # # @param [String] id the id of the repository # @return [String] the repository path, may contain the id if passed - def self.path(id=nil) - (id == nil) ? "repositories/" : "repositories/#{id}/" + def self.path(id = nil) + (id.nil?) ? 'repositories/' : "repositories/#{id}/" end # Creates a repository @@ -40,7 +40,7 @@ def self.path(id=nil) # @param [String] id the id of the repository # @param [Hash] optional container for all optional parameters # @return [RestClient::Response] - def create(id, optional={}) + def create(_id, optional = {}) required = required_params(binding.send(:local_variables), binding) call(:post, path, :payload => { :required => required, :optional => optional }) end @@ -50,7 +50,7 @@ def create(id, optional={}) # @param [String] id the id of the repository # @param [Hash] params container for optional query parameters # @return [RestClient::Response] - def retrieve(id, params={}) + def retrieve(id, params = {}) call(:get, path(id), :params => params) end @@ -59,7 +59,7 @@ def retrieve(id, params={}) # @param [String] id the id of the repository # @param [Hash] optional container for all optional parameters # @return [RestClient::Response] - def update(id, optional={}) + def update(id, optional = {}) call(:put, path(id), :payload => { :delta => optional }) end @@ -75,7 +75,7 @@ def delete(id) # # @param [Hash] optional container for all optional parameters # @return [RestClient::Response] - def retrieve_all(optional={}) + def retrieve_all(optional = {}) call(:get, path, :payload => { :optional => optional }) end @@ -84,9 +84,9 @@ def retrieve_all(optional={}) # @param [Hash] criteria criteria object containing Mongo syntax # @param [Hash] optional container for all optional parameters # @return [RestClient::Response] - def search(criteria, optional={}) + def search(_criteria, optional = {}) required = required_params(binding.send(:local_variables), binding) - call(:post, path("search"), :payload => { :required => required, :optional => optional }) + call(:post, path('search'), :payload => { :required => required, :optional => optional }) end # Associates an importer to a repository @@ -95,7 +95,7 @@ def search(criteria, optional={}) # @param [String] importer_type_id the type ID of the importer being associated # @param [Hash] importer_config configuration options for the importer # @return [RestClient::Response] - def associate_importer(id, importer_type_id, importer_config) + def associate_importer(id, _importer_type_id, _importer_config) required = required_params(binding.send(:local_variables), binding) call(:post, path("#{id}/importers"), :payload => { :required => required }) end @@ -107,8 +107,8 @@ def associate_importer(id, importer_type_id, importer_config) # @param [Hash] distributor_config configuration options for the distributor # @param [Hash] optional container for all optional parameters # @return [RestClient::Response] - def associate_distributor(id, distributor_type_id, distributor_config, optional={}) - required = required_params(binding.send(:local_variables), binding, ["id"]) + def associate_distributor(id, _distributor_type_id, _distributor_config, optional = {}) + required = required_params(binding.send(:local_variables), binding, ['id']) call(:post, path("#{id}/distributors"), :payload => { :required => required, :optional => optional }) end @@ -117,7 +117,7 @@ def associate_distributor(id, distributor_type_id, distributor_config, optional= # @param [String] id the id of the repository # @param [Hash] optional container for all optional parameters # @return [RestClient::Response] - def sync(id, optional={}) + def sync(id, optional = {}) call(:post, "#{path(id)}actions/sync/", :payload => { :optional => optional }) end @@ -135,8 +135,8 @@ def sync_history(id) # @param [String] source_repo_id the id of the source repository # @param [Hash] optional container for all optional parameters # @return [RestClient::Response] - def unit_copy(destination_repo_id, source_repo_id, optional={}) - required = required_params(binding.send(:local_variables), binding, ["destination_repo_id"]) + def unit_copy(destination_repo_id, _source_repo_id, optional = {}) + required = required_params(binding.send(:local_variables), binding, ['destination_repo_id']) call(:post, "#{path(destination_repo_id)}actions/associate/", :payload => { :required => required, :optional => optional }) end @@ -146,8 +146,8 @@ def unit_copy(destination_repo_id, source_repo_id, optional={}) # @param [String] source_repo_id the id of the source repository # @param [Hash] criteria criteria object containing Mongo syntax # @return [RestClient::Response] - def unassociate_units(source_repo_id, criteria={}) - required = required_params(binding.send(:local_variables), binding, ["source_repo_id"]) + def unassociate_units(source_repo_id, _criteria = {}) + required = required_params(binding.send(:local_variables), binding, ['source_repo_id']) call(:post, "#{path(source_repo_id)}actions/unassociate/", :payload => { :required => required }) end @@ -157,8 +157,8 @@ def unassociate_units(source_repo_id, criteria={}) # @param [String] id the id of the repository # @param [Hash] criteria criteria object containing Mongo syntax # @return [RestClient::Response] - def unit_search(id, criteria={}) - call(:post, "#{path(id)}search/units/", :payload=>{:required=>{:criteria=>criteria}}) + def unit_search(id, criteria = {}) + call(:post, "#{path(id)}search/units/", :payload => {:required => {:criteria => criteria}}) end # Publishes a repository using the specified distributor @@ -167,8 +167,9 @@ def unit_search(id, criteria={}) # @param [String] distributor_id the id of the distributor # @param [Hash] optional optional params # @return [RestClient::Response] - def publish(id, distributor_id, optional={}) - call(:post, "#{path(id)}actions/publish/", :payload=>{:required=>{:id=>distributor_id}, :optional=>optional}) + def publish(id, distributor_id, optional = {}) + call(:post, "#{path(id)}actions/publish/", + :payload => {:required => {:id => distributor_id}, :optional => optional}) end # Deletes the specified distributor from the repository @@ -186,8 +187,8 @@ def delete_distributor(id, distributor_id) # @param [String] distributor_id the id of the distributor # @param [Hash] distributor_config attributes to change # @return [RestClient::Response] - def update_distributor(id, distributor_id, distributor_config) - required = required_params(binding.send(:local_variables), binding, ["id", "distributor_id"]) + def update_distributor(id, distributor_id, _distributor_config) + required = required_params(binding.send(:local_variables), binding, ['id', 'distributor_id']) call(:put, path("#{id}/distributors/#{distributor_id}/"), :payload => { :required => required}) end @@ -206,8 +207,8 @@ def delete_importer(id, importer_id) # @param [String] importer_id the id of the importer # @param [Hash] importer_config attributes to change # @return [RestClient::Response] - def update_importer(id, importer_id, importer_config) - required = required_params(binding.send(:local_variables), binding, ["id", "importer_id"]) + def update_importer(id, importer_id, _importer_config) + required = required_params(binding.send(:local_variables), binding, ['id', 'importer_id']) call(:put, path("#{id}/importers/#{importer_id}/"), :payload => { :required => required}) end @@ -216,9 +217,8 @@ def update_importer(id, importer_id, importer_config) # @param [Hash] options payload representing criteria # @return [RestClient::Response] def regenerate_applicability(options = {}) - call(:post, path("actions/content/regenerate_applicability/"), :payload => { :required => options}) + call(:post, path('actions/content/regenerate_applicability/'), :payload => { :required => options}) end - end end end diff --git a/lib/runcible/resources/repository_group.rb b/lib/runcible/resources/repository_group.rb index 90bc767a..647ba8d4 100644 --- a/lib/runcible/resources/repository_group.rb +++ b/lib/runcible/resources/repository_group.rb @@ -27,13 +27,12 @@ module Runcible module Resources # @see https://pulp-dev-guide.readthedocs.org/en/latest/integration/rest-api/repo/groups/ class RepositoryGroup < Runcible::Base - # Generates the API path for Repository Groups # # @param [String] id the ID of the Repository group # @return [String] the Repository group path, may contain the id if passed - def self.path(id=nil) - groups = "repo_groups/" + def self.path(id = nil) + groups = 'repo_groups/' id.nil? ? groups : groups + "#{id}/" end @@ -42,7 +41,7 @@ def self.path(id=nil) # @param [String] id the ID of the group # @param [Hash] optional container for all optional parameters # @return [RestClient::Response] - def create(id, optional={}) + def create(_id, optional = {}) required = required_params(binding.send(:local_variables), binding) call(:post, path, :payload => { :required => required, :optional => optional }) end @@ -76,7 +75,7 @@ def delete(id) # @param [Hash] criteria criteria based on Mongo syntax representing repos to associate # @return [RestClient::Response] def associate(id, criteria) - call(:post, path(id) + "actions/associate/", :payload => {:required => criteria}) + call(:post, path(id) + 'actions/associate/', :payload => {:required => criteria}) end # Unassociates Repositories with a Repository Group @@ -85,9 +84,8 @@ def associate(id, criteria) # @param [Hash] criteria criteria based on Mongo syntax representing repos ta unassociate # @return [RestClient::Response] def unassociate(id, criteria) - call(:post, path(id) + "actions/unassociate/", :payload => {:required => criteria}) + call(:post, path(id) + 'actions/unassociate/', :payload => {:required => criteria}) end - end end end diff --git a/lib/runcible/resources/repository_schedule.rb b/lib/runcible/resources/repository_schedule.rb index c658ef1c..8d480347 100644 --- a/lib/runcible/resources/repository_schedule.rb +++ b/lib/runcible/resources/repository_schedule.rb @@ -27,17 +27,16 @@ module Runcible module Resources # @see https://pulp-dev-guide.readthedocs.org/en/latest/rest-api/repo/sync.html#scheduling-a-sync class RepositorySchedule < Runcible::Base - # Generates the API path for Repository Schedules # # @param [String] repo_id the ID of the repository # @param [String] importer_id the ID of the importer # @param [String] schedule_id the ID of the schedule # @return [String] the repository schedule path, may contain the ID of the schedule if passed - def self.path(repo_id, importer_id, schedule_id=nil) + def self.path(repo_id, importer_id, schedule_id = nil) repo_path = Runcible::Resources::Repository.path(repo_id) path = "#{repo_path}importers/#{importer_id}/schedules/sync/" - (schedule_id == nil) ? path : "#{path}#{schedule_id}/" + (schedule_id.nil?) ? path : "#{path}#{schedule_id}/" end # List the schedules for a repository for a given importer type @@ -56,9 +55,9 @@ def list(repo_id, importer_type) # @param [Hash] schedule a hash representing a schedule # @param [Hash] optional container for all optional parameters # @return [RestClient::Response] - def create(repo_id, importer_type, schedule, optional={}) + def create(repo_id, importer_type, schedule, optional = {}) call(:post, path(repo_id, importer_type), - :payload => { :required => {:schedule=>schedule}, :optional => optional }) + :payload => { :required => {:schedule => schedule}, :optional => optional }) end # Update a schedule for a repository for a given importer type @@ -68,7 +67,7 @@ def create(repo_id, importer_type, schedule, optional={}) # @param [String] schedule_id the ID of the schedule # @param [Hash] optional container for all optional parameters # @return [RestClient::Response] - def update(repo_id, importer_type, schedule_id, optional={}) + def update(repo_id, importer_type, schedule_id, optional = {}) call(:put, path(repo_id, importer_type, schedule_id), :payload => {:optional => optional }) end @@ -82,7 +81,6 @@ def update(repo_id, importer_type, schedule_id, optional={}) def delete(repo_id, importer_type, schedule_id) call(:delete, path(repo_id, importer_type, schedule_id)) end - end end end diff --git a/lib/runcible/resources/role.rb b/lib/runcible/resources/role.rb index 8993999f..5b27ae30 100644 --- a/lib/runcible/resources/role.rb +++ b/lib/runcible/resources/role.rb @@ -21,27 +21,25 @@ # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - module Runcible module Resources # @see https://pulp-dev-guide.readthedocs.org/en/latest/rest-api/role/index.html class Role < Runcible::Base - # Generates the API path for Roles # # @param [String] id the ID of the role # @return [String] the role path, may contain the ID if passed - def self.path(id=nil) - (id == nil) ? "roles/" : "roles/#{id}/" + def self.path(id = nil) + (id.nil?) ? 'roles/' : "roles/#{id}/" end # Adds a user to a role # # @param [String] id the ID of the role # @param [String] login the login of the user being added - # @return [RestClient::Response] - def add(id, login) - required = required_params(binding.send(:local_variables), binding, ["id"]) + # @return [RestClient::Response] + def add(id, _login) + required = required_params(binding.send(:local_variables), binding, ['id']) call(:post, "#{path(id)}users/", :payload => { :required => required }) end @@ -49,11 +47,10 @@ def add(id, login) # # @param [String] id the ID of the role # @param [String] login the login of the user being removed - # @return [RestClient::Response] + # @return [RestClient::Response] def remove(id, login) call(:delete, "#{path(id)}users/#{login}/") end - end end end diff --git a/lib/runcible/resources/task.rb b/lib/runcible/resources/task.rb index e028e783..7486066d 100644 --- a/lib/runcible/resources/task.rb +++ b/lib/runcible/resources/task.rb @@ -21,24 +21,22 @@ # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - module Runcible module Resources # @see https://pulp-dev-guide.readthedocs.org/en/latest/rest-api/dispatch/index.html class Task < Runcible::Base - # Generates the API path for Tasks # # @param [String] id the id of the task - # @return [String] the task path, may contain the id if passed - def self.path(id=nil) - (id == nil) ? "tasks/" : "tasks/#{id}/" + # @return [String] the task path, may contain the id if passed + def self.path(id = nil) + (id.nil?) ? 'tasks/' : "tasks/#{id}/" end # Polls for the status of a task # # @param [String] id the id of the task - # @return [RestClient::Response] + # @return [RestClient::Response] def poll(id) call(:get, path(id)) end @@ -46,7 +44,7 @@ def poll(id) # Cancels a task # # @param [String] id the id of the task - # @return [RestClient::Response] + # @return [RestClient::Response] def cancel(id) #cancelling a task may require cancelling some higher level # task, so query the tasks _href field to make sure @@ -56,20 +54,19 @@ def cancel(id) # List all tasks based on a set of tags # # @param [Array] tags array of tags to scope the list on - # @return [RestClient::Response] - def list(tags=[]) - call(:get, path, :params=>{:tag=>tags}) + # @return [RestClient::Response] + def list(tags = []) + call(:get, path, :params => {:tag => tags}) end # Polls all tasks based on array of IDs # temporary solution until https://bugzilla.redhat.com/show_bug.cgi?id=860089 # # @param [Array] ids array of ids to poll the status of - # @return [Array] array of RestClient::Response task poll objects + # @return [Array] array of RestClient::Response task poll objects def poll_all(ids) - return ids.collect{|id| poll(id)} + return ids.map { |id| poll(id) } end - end end end diff --git a/lib/runcible/resources/unit.rb b/lib/runcible/resources/unit.rb index fce22daa..28b541f6 100644 --- a/lib/runcible/resources/unit.rb +++ b/lib/runcible/resources/unit.rb @@ -21,12 +21,10 @@ # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - module Runcible module Resources # @see https://pulp-dev-guide.readthedocs.org/en/latest/rest-api/content/index.html class Unit < Runcible::Base - # Generates the API path for Units # # @param [String] type the unit type @@ -40,11 +38,10 @@ def path(type) # @param [String] type the unit type # @param [Hash] criteria criteria object containing Mongo syntax # @param [Hash] optional container for all optional parameters - # @return [RestClient::Response] - def search(type, criteria, optional={}) - call(:post, path(type), :payload=>{:required=>{:criteria=>criteria}, :optional=>optional}) + # @return [RestClient::Response] + def search(type, criteria, optional = {}) + call(:post, path(type), :payload => {:required => {:criteria => criteria}, :optional => optional}) end end - end end diff --git a/lib/runcible/resources/user.rb b/lib/runcible/resources/user.rb index 4411984f..e9f53146 100644 --- a/lib/runcible/resources/user.rb +++ b/lib/runcible/resources/user.rb @@ -21,23 +21,21 @@ # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - module Runcible module Resources # @see https://pulp-dev-guide.readthedocs.org/en/latest/rest-api/user/index.html class User < Runcible::Base - # Generates the API path for Users # # @param [String] login the user's login # @return [String] the user path, may contain the login if passed - def self.path(login=nil) - (login == nil) ? "users/" : "users/#{login}/" + def self.path(login = nil) + (login.nil?) ? 'users/' : "users/#{login}/" end # Retrieves all users # - # @return [RestClient::Response] + # @return [RestClient::Response] def retrieve_all call(:get, path) end @@ -46,8 +44,8 @@ def retrieve_all # # @param [String] login the login requested for the user # @param [Hash] optional container for all optional parameters - # @return [RestClient::Response] - def create(login, optional={}) + # @return [RestClient::Response] + def create(_login, optional = {}) required = required_params(binding.send(:local_variables), binding) call(:post, path, :payload => { :required => required, :optional => optional }) end @@ -55,7 +53,7 @@ def create(login, optional={}) # Retrieves a user # # @param [String] login the login of the user being retrieved - # @return [RestClient::Response] + # @return [RestClient::Response] def retrieve(login) call(:get, path(login)) end @@ -63,11 +61,10 @@ def retrieve(login) # Deletes a user # # @param [String] login the login of the user being deleted - # @return [RestClient::Response] + # @return [RestClient::Response] def delete(login) call(:delete, path(login)) end - end end end diff --git a/lib/runcible/version.rb b/lib/runcible/version.rb index 4b92fc5c..9cf2824b 100644 --- a/lib/runcible/version.rb +++ b/lib/runcible/version.rb @@ -1,3 +1,3 @@ module Runcible - VERSION = "1.2.0" + VERSION = '1.2.0' end diff --git a/runcible.gemspec b/runcible.gemspec index dcfc49be..f89dc95d 100644 --- a/runcible.gemspec +++ b/runcible.gemspec @@ -2,17 +2,17 @@ require File.expand_path('../lib/runcible/version', __FILE__) Gem::Specification.new do |gem| - gem.authors = ["Eric D Helms, Justin Sherrill"] - gem.email = ["ehelms@redhat.com, jsherril@redhat.com"] + gem.authors = ['Eric D Helms, Justin Sherrill'] + gem.email = ['ehelms@redhat.com, jsherril@redhat.com'] gem.description = "Exposing Pulp's juiciest components to the Ruby world." - gem.summary = "" - gem.homepage = "https://github.com/Katello/runcible" + gem.summary = '' + gem.homepage = 'https://github.com/Katello/runcible' - gem.files = Dir['lib/**/*.rb'] + ['LICENSE', 'Rakefile', 'Gemfile', + gem.files = Dir['lib/**/*.rb'] + ['LICENSE', 'Rakefile', 'Gemfile', 'README.md', 'CONTRIBUTING.md'] - gem.test_files = gem.files.grep(%r{^(test)/}) - gem.name = "runcible" - gem.require_paths = ["lib"] + gem.test_files = gem.files.grep(/^(test)/) + gem.name = 'runcible' + gem.require_paths = ['lib'] gem.version = Runcible::VERSION gem.add_dependency('json') diff --git a/test/extensions/consumer_group_test.rb b/test/extensions/consumer_group_test.rb index 1770693a..6de5e4c2 100644 --- a/test/extensions/consumer_group_test.rb +++ b/test/extensions/consumer_group_test.rb @@ -31,7 +31,6 @@ module Extensions class TestConsumerGroup < MiniTest::Unit::TestCase - def self.before_suite @@repo_support = RepositorySupport.new @@consumer_support = ConsumerSupport.new @@ -52,8 +51,8 @@ def setup criteria = {:criteria => {:filters => - {:id => {"$in" => [ConsumerSupport.consumer_id]}}}} - distro_id = @@repo_support.distributor()['id'] + {:id => {'$in' => [ConsumerSupport.consumer_id]}}}} + distro_id = @@repo_support.distributor['id'] TestRuncible.server.extensions.consumer.bind(ConsumerSupport.consumer_id, RepositorySupport.repo_id, distro_id) @resource.associate(ConsumerGroupSupport.consumer_group_id, criteria) @@ -68,63 +67,62 @@ def teardown def test_add_consumers_by_id response = @extension.add_consumers_by_id(ConsumerGroupSupport.consumer_group_id, [ConsumerSupport.consumer_id]) - assert_equal 200, response.code - refute_empty response + assert_equal 200, response.code + refute_empty response assert_includes response, ConsumerSupport.consumer_id end def test_remove_consumers_by_id - assert_includes @resource.retrieve(ConsumerGroupSupport.consumer_group_id)["consumer_ids"], ConsumerSupport.consumer_id + assert_includes @resource.retrieve(ConsumerGroupSupport.consumer_group_id)['consumer_ids'], ConsumerSupport.consumer_id response = @extension.remove_consumers_by_id(ConsumerGroupSupport.consumer_group_id, [ConsumerSupport.consumer_id]) - assert_equal 200, response.code - assert_empty response # no consumers - refute_includes @resource.retrieve(ConsumerGroupSupport.consumer_group_id)["consumer_ids"], ConsumerSupport.consumer_id + assert_equal 200, response.code + assert_empty response # no consumers + refute_includes @resource.retrieve(ConsumerGroupSupport.consumer_group_id)['consumer_ids'], ConsumerSupport.consumer_id end def test_make_consumer_criteria criteria = @extension.make_consumer_criteria([ConsumerSupport.consumer_id]) - assert_kind_of Hash, criteria - refute_empty criteria[:criteria][:filters][:id]["$in"] + assert_kind_of Hash, criteria + refute_empty criteria[:criteria][:filters][:id]['$in'] end def test_install_content - response = @extension.install_content(@consumer_group_id, "rpm", ["zsh", "foo"]) + response = @extension.install_content(@consumer_group_id, 'rpm', ['zsh', 'foo']) assert_equal 202, response.code - assert response["spawned_tasks"].first["task_id"] + assert response['spawned_tasks'].first['task_id'] end def test_update_content - response = @extension.update_content(@consumer_group_id, "rpm", ["zsh", "foo"]) + response = @extension.update_content(@consumer_group_id, 'rpm', ['zsh', 'foo']) assert_equal 202, response.code - assert response["spawned_tasks"].first["task_id"] + assert response['spawned_tasks'].first['task_id'] end def test_uninstall_content - response = @extension.uninstall_content(@consumer_group_id, "rpm", ["zsh", "foo"]) + response = @extension.uninstall_content(@consumer_group_id, 'rpm', ['zsh', 'foo']) assert_equal 202, response.code - assert response["spawned_tasks"].first["task_id"] + assert response['spawned_tasks'].first['task_id'] end def test_generate_content - content = @extension.generate_content("rpm", ["unit_1", "unit_2"]) + content = @extension.generate_content('rpm', ['unit_1', 'unit_2']) refute_empty content - refute_empty content.select{ |unit| unit[:type_id] == "rpm" } + refute_empty content.select { |unit| unit[:type_id] == 'rpm' } end def test_generate_content_all - content = @extension.generate_content("rpm", ["unit_1"], {:all => true}) + content = @extension.generate_content('rpm', ['unit_1'], :all => true) refute_empty content - assert_equal "rpm", content.first[:type_id] + assert_equal 'rpm', content.first[:type_id] assert_empty content.first[:unit_key] end - end -end \ No newline at end of file +end diff --git a/test/extensions/consumer_test.rb b/test/extensions/consumer_test.rb index 8fcfa750..b0ef7975 100644 --- a/test/extensions/consumer_test.rb +++ b/test/extensions/consumer_test.rb @@ -30,7 +30,6 @@ module Extensions class TestConsumer < MiniTest::Unit::TestCase - def self.before_suite @@repo_support = RepositorySupport.new @@consumer_support = ConsumerSupport.new @@ -44,7 +43,7 @@ def self.after_suite def setup @resource = TestRuncible.server.resources.consumer @extension = TestRuncible.server.extensions.consumer - @consumer_id = "integration_test_consumer_extensions11000" + @consumer_id = 'integration_test_consumer_extensions11000' @@consumer_support.destroy_consumer @@consumer_support.create_consumer(true) @consumer_id = ConsumerSupport.consumer_id @@ -57,7 +56,7 @@ def teardown def bind_repo response = @extension.bind_all(@consumer_id, RepositorySupport.repo_id, - Runcible::Models::YumDistributor.type_id, {:notify_agent=>false}) + Runcible::Models::YumDistributor.type_id, :notify_agent => false) @@repo_support.wait_on_response(response.first) end @@ -75,7 +74,7 @@ def test_deactivate_node def test_bind_all @extension.unbind_all(@consumer_id, RepositorySupport.repo_id, Runcible::Models::YumDistributor.type_id) response = @extension.bind_all(@consumer_id, RepositorySupport.repo_id, - Runcible::Models::YumDistributor.type_id, {:notify_agent=>false}) + Runcible::Models::YumDistributor.type_id, :notify_agent => false) assert_equal 200, response.first.code end @@ -87,82 +86,79 @@ def test_unbind_all end def test_install_content - response = @extension.install_content(@consumer_id, "rpm", ["zsh", "foo"]) + response = @extension.install_content(@consumer_id, 'rpm', ['zsh', 'foo']) - assert_equal 202, response.code - assert response["spawned_tasks"].first["task_id"] + assert_equal 202, response.code + assert response['spawned_tasks'].first['task_id'] end def test_update_content - response = @extension.update_content(@consumer_id, "rpm", ["zsh", "foo"]) + response = @extension.update_content(@consumer_id, 'rpm', ['zsh', 'foo']) assert_equal 202, response.code - assert response["spawned_tasks"].first["task_id"] + assert response['spawned_tasks'].first['task_id'] end def test_uninstall_content - response = @extension.uninstall_content(@consumer_id, "rpm", ["zsh", "foo"]) + response = @extension.uninstall_content(@consumer_id, 'rpm', ['zsh', 'foo']) assert_equal 202, response.code - assert response["spawned_tasks"].first["task_id"] + assert response['spawned_tasks'].first['task_id'] end def test_generate_content - content = @extension.generate_content("rpm", ["unit_1", "unit_2"]) + content = @extension.generate_content('rpm', ['unit_1', 'unit_2']) refute_empty content - refute_empty content.select{ |unit| unit[:type_id] == "rpm" } + refute_empty content.select { |unit| unit[:type_id] == 'rpm' } end def test_generate_content_all - content = @extension.generate_content("rpm", ["unit_1"], {:all => true}) + content = @extension.generate_content('rpm', ['unit_1'], :all => true) refute_empty content - assert_equal "rpm", content.first[:type_id] + assert_equal 'rpm', content.first[:type_id] assert_empty content.first[:unit_key] end - def test_generate_applicability_by_ids - response = @extension.regenerate_applicability_by_ids([@consumer_id]) - - assert_equal 202, response.code - tasks = RepositorySupport.new.wait_on_response(response) - assert 'finished', tasks.first['state'] - end + def test_generate_applicability_by_ids + response = @extension.regenerate_applicability_by_ids([@consumer_id]) - def test_applicable_errata - response = @extension.applicable_errata([@consumer_id]) + assert_equal 202, response.code + tasks = RepositorySupport.new.wait_on_response(response) + assert 'finished', tasks.first['state'] + end - assert_equal 200, response.code - end + def test_applicable_errata + response = @extension.applicable_errata([@consumer_id]) + assert_equal 200, response.code + end end - class TestConsumerApplicabilityScenario < MiniTest::Unit::TestCase + def self.before_suite + @@repo_support = RepositorySupport.new + @@consumer_support = ConsumerSupport.new + @@repo_support.create_and_sync_repo(:importer_and_distributor => true) + end - def self.before_suite - @@repo_support = RepositorySupport.new - @@consumer_support = ConsumerSupport.new - @@repo_support.create_and_sync_repo(:importer_and_distributor => true) - end - - def self.after_suite - @@repo_support.destroy_repo - end - - def setup - @extension = TestRuncible.server.extensions.consumer - @consumer_id = "integration_test_consumer_extensions11000" - @@consumer_support.destroy_consumer - @@consumer_support.create_consumer(false) - @consumer_id = ConsumerSupport.consumer_id - bind_repo - end + def self.after_suite + @@repo_support.destroy_repo + end + + def setup + @extension = TestRuncible.server.extensions.consumer + @consumer_id = 'integration_test_consumer_extensions11000' + @@consumer_support.destroy_consumer + @@consumer_support.create_consumer(false) + @consumer_id = ConsumerSupport.consumer_id + bind_repo + end def test_applicability - @extension.upload_profile(@consumer_id, 'rpm', [{"name" => "elephant", "version" => "0.2", "release" => "0.7", - "epoch" => 0, "arch" => "noarch", "vendor" => "Fedora"}]) + @extension.upload_profile(@consumer_id, 'rpm', [{'name' => 'elephant', 'version' => '0.2', 'release' => '0.7', + 'epoch' => 0, 'arch' => 'noarch', 'vendor' => 'Fedora'}]) task = @extension.regenerate_applicability_by_ids([@consumer_id]) RepositorySupport.new.wait_on_response(task) applicability = @extension.applicable_errata([@consumer_id]) @@ -174,9 +170,8 @@ def test_applicability def bind_repo tasks = @extension.bind_all(@consumer_id, RepositorySupport.repo_id, - Runcible::Models::YumDistributor.type_id, {:notify_agent=>false}) + Runcible::Models::YumDistributor.type_id, :notify_agent => false) @@repo_support.wait_on_response(tasks.first) end - end -end \ No newline at end of file +end diff --git a/test/extensions/distribution_test.rb b/test/extensions/distribution_test.rb index 7f1210ce..14e2c6c3 100644 --- a/test/extensions/distribution_test.rb +++ b/test/extensions/distribution_test.rb @@ -30,7 +30,6 @@ module Extensions class TestDistribution < MiniTest::Unit::TestCase - def self.before_suite self.support = RepositorySupport.new @@extension = TestRuncible.server.extensions.distribution @@ -53,7 +52,7 @@ def test_all end def test_find - id = @@extension.all.sort_by{|p| p['id']}.first['id'] + id = @@extension.all.sort_by { |p| p['id'] }.first['id'] response = @@extension.find(id) refute_empty response @@ -61,7 +60,7 @@ def test_find end def test_find_by_unit_id - id = @@extension.all.sort_by{|p| p['id']}.first['_id'] + id = @@extension.all.sort_by { |p| p['id'] }.first['_id'] response = @@extension.find_by_unit_id(id) refute_empty response @@ -75,7 +74,7 @@ def test_find_unknown end def test_find_all_by_unit_ids - id = @@extension.all.sort_by{|p| p['id']}.first['_id'] + id = @@extension.all.sort_by { |p| p['id'] }.first['_id'] response = @@extension.find_all_by_unit_ids([id]) refute_empty response @@ -83,14 +82,13 @@ def test_find_all_by_unit_ids end def test_find_all - pkgs = @@extension.all.sort_by{|p| p['id']} - ids = pkgs[0..2].collect{|p| p['id']} + pkgs = @@extension.all.sort_by { |p| p['id'] } + ids = pkgs[0..2].map { |p| p['id'] } response = @@extension.find_all(ids) assert_equal 200, response.code assert_equal ids.length, response.length end - end class TestDistributionCopy < UnitCopyBase @@ -98,14 +96,12 @@ def self.extension_class TestRuncible.server.extensions.distribution end - def test_copy response = self.class.extension_class.copy(RepositorySupport.repo_id, self.class.clone_name) tasks = assert_async_response(response) assert_includes tasks.first['tags'], 'pulp:action:associate' end - end class TestDistributionUnassociate < UnitUnassociateBase @@ -131,7 +127,6 @@ def test_unassociate_unit_ids_from_repo assert_equal (ids.length - 1), unit_ids(self.class.clone_name).length end - def test_unassociate_from_repo ids = unit_ids(RepositorySupport.repo_id) refute_empty ids @@ -140,6 +135,5 @@ def test_unassociate_from_repo assert_async_response(response) assert_equal (ids.length - 1), unit_ids(self.class.clone_name).length end - end -end \ No newline at end of file +end diff --git a/test/extensions/docker_repository_test.rb b/test/extensions/docker_repository_test.rb index b8dc1f3d..70d66198 100644 --- a/test/extensions/docker_repository_test.rb +++ b/test/extensions/docker_repository_test.rb @@ -30,7 +30,7 @@ module Extensions module TestDockerRepositoryBase def setup - @support = RepositorySupport.new("docker") + @support = RepositorySupport.new('docker') @extension = TestRuncible.server.extensions.repository end end @@ -44,29 +44,29 @@ def teardown end def test_create_with_importer - response = @extension.create_with_importer(RepositorySupport.repo_id, {:id=>"docker_importer"}) + response = @extension.create_with_importer(RepositorySupport.repo_id, :id => 'docker_importer') assert_equal 201, response.code - response = @extension.retrieve(RepositorySupport.repo_id, {:details => true}) + response = @extension.retrieve(RepositorySupport.repo_id, :details => true) assert_equal RepositorySupport.repo_id, response['id'] - assert_equal "docker_importer", response['importers'].first['importer_type_id'] + assert_equal 'docker_importer', response['importers'].first['importer_type_id'] end def test_create_with_importer_object response = @extension.create_with_importer(RepositorySupport.repo_id, - Runcible::Models::DockerImporter.new(:feed => "https://index.docker.io", - :upstream_name => "busybox")) + Runcible::Models::DockerImporter.new(:feed => 'https://index.docker.io', + :upstream_name => 'busybox')) assert_equal 201, response.code - response = @extension.retrieve(RepositorySupport.repo_id, {:details => true}) + response = @extension.retrieve(RepositorySupport.repo_id, :details => true) assert_equal RepositorySupport.repo_id, response['id'] - assert_equal "docker_importer", response['importers'].first['importer_type_id'] + assert_equal 'docker_importer', response['importers'].first['importer_type_id'] @extension.expects(:create).with(RepositorySupport.repo_id, has_entry(:notes, anything)).returns(true) @extension.create_with_importer(RepositorySupport.repo_id, Runcible::Models::DockerImporter.new) end def test_create_with_distributors - distributors = [{'type_id' => 'docker_distributor_web', 'id'=>'123', 'auto_publish'=>true, - 'config'=>{'docker_publish_directory' => '/path'}}] + distributors = [{'type_id' => 'docker_distributor_web', 'id' => '123', 'auto_publish' => true, + 'config' => {'docker_publish_directory' => '/path'}}] response = @extension.create_with_distributors(RepositorySupport.repo_id, distributors) assert_equal 201, response.code @@ -74,11 +74,11 @@ def test_create_with_distributors end def test_create_with_distributor_object - repo_id = RepositorySupport.repo_id + "_distro" - response = @extension.create_with_distributors(repo_id, [Runcible::Models::DockerDistributor.new(:docker_publish_directory => "/path", + repo_id = RepositorySupport.repo_id + '_distro' + response = @extension.create_with_distributors(repo_id, [Runcible::Models::DockerDistributor.new(:docker_publish_directory => '/path', :id => '123')]) assert_equal 201, response.code - response = @extension.retrieve(repo_id, {:details => true}) + response = @extension.retrieve(repo_id, :details => true) assert_equal repo_id, response['id'] assert_equal 'docker_distributor_web', response['distributors'].first['distributor_type_id'] ensure @@ -86,25 +86,25 @@ def test_create_with_distributor_object end def test_create_with_importer_and_distributors - distributors = [{'type_id' => 'docker_distributor_web', 'id'=>'123', 'auto_publish'=>true, - 'config'=>{}}] - response = @extension.create_with_importer_and_distributors(RepositorySupport.repo_id, {:id=>'docker_importer'}, distributors) + distributors = [{'type_id' => 'docker_distributor_web', 'id' => '123', 'auto_publish' => true, + 'config' => {}}] + response = @extension.create_with_importer_and_distributors(RepositorySupport.repo_id, {:id => 'docker_importer'}, distributors) assert_equal 201, response.code - response = @extension.retrieve(RepositorySupport.repo_id, {:details => true}) + response = @extension.retrieve(RepositorySupport.repo_id, :details => true) assert_equal RepositorySupport.repo_id, response['id'] assert_equal 'docker_distributor_web', response['distributors'].first['distributor_type_id'] end def test_create_with_importer_and_distributors_objects distributors = [Runcible::Models::DockerDistributor.new(:id => '123')] - importer = Runcible::Models::DockerImporter.new() + importer = Runcible::Models::DockerImporter.new response = @extension.create_with_importer_and_distributors(RepositorySupport.repo_id, importer, distributors) assert_equal 201, response.code - response = @extension.retrieve(RepositorySupport.repo_id, {:details => true}) + response = @extension.retrieve(RepositorySupport.repo_id, :details => true) assert_equal RepositorySupport.repo_id, response['id'] - assert_equal "docker_importer", response['importers'].first['importer_type_id'] + assert_equal 'docker_importer', response['importers'].first['importer_type_id'] end end end diff --git a/test/extensions/errata_test.rb b/test/extensions/errata_test.rb index 1023760d..2ba4c330 100644 --- a/test/extensions/errata_test.rb +++ b/test/extensions/errata_test.rb @@ -30,7 +30,6 @@ module Extensions class TestErrata < MiniTest::Unit::TestCase - def self.before_suite self.support = RepositorySupport.new @@extension = TestRuncible.server.extensions.errata @@ -49,7 +48,7 @@ def test_all end def test_find - id = @@extension.all.sort_by{|p| p['id']}.first['id'] + id = @@extension.all.sort_by { |p| p['id'] }.first['id'] response = @@extension.find(id) refute_empty response @@ -57,7 +56,7 @@ def test_find end def test_find_by_unit_id - id = @@extension.all.sort_by{|p| p['id']}.first['_id'] + id = @@extension.all.sort_by { |p| p['id'] }.first['_id'] response = @@extension.find_by_unit_id(id) refute_empty response @@ -71,7 +70,7 @@ def test_find_unknown end def test_find_all_by_unit_ids - id = @@extension.all.sort_by{|p| p['_id']}.first['_id'] + id = @@extension.all.sort_by { |p| p['_id'] }.first['_id'] response = @@extension.find_all_by_unit_ids([id]) refute_empty response @@ -79,14 +78,13 @@ def test_find_all_by_unit_ids end def test_find_all - pkgs = @@extension.all.sort_by{|p| p['id']} - ids = pkgs[0..2].collect{|p| p['id']} + pkgs = @@extension.all.sort_by { |p| p['id'] } + ids = pkgs[0..2].map { |p| p['id'] } response = @@extension.find_all(ids) assert_equal 200, response.code assert_equal ids.length, response.length end - end class TestErrataCopy < UnitCopyBase @@ -103,7 +101,6 @@ def test_copy end class TestErrataUnassociate < UnitUnassociateBase - def self.extension_class TestRuncible.server.extensions.errata end @@ -131,7 +128,6 @@ def test_unassociate_unit_ids_from_repo assert_equal (ids.length - 1), unit_ids(self.class.clone_name).length end - def test_unassociate_from_repo ids = unit_ids(RepositorySupport.repo_id) refute_empty ids @@ -141,6 +137,5 @@ def test_unassociate_from_repo assert_async_response(response) assert_equal (ids.length - 1), unit_ids(self.class.clone_name).length end - end -end \ No newline at end of file +end diff --git a/test/extensions/iso_repository_test.rb b/test/extensions/iso_repository_test.rb index f97a95e8..ab0c81c1 100644 --- a/test/extensions/iso_repository_test.rb +++ b/test/extensions/iso_repository_test.rb @@ -29,12 +29,10 @@ module Extensions module TestIsoRepositoryBase - def setup @support = RepositorySupport.new @extension = TestRuncible.server.extensions.repository end - end class TestIsoRepositoryCreate < MiniTest::Unit::TestCase @@ -42,7 +40,7 @@ class TestIsoRepositoryCreate < MiniTest::Unit::TestCase def setup super - @repo_url = "file://#{File.expand_path(File.dirname(__FILE__))}".gsub("test/extensions", "test/fixtures/repositories/iso/") + @repo_url = "file://#{File.expand_path(File.dirname(__FILE__))}".gsub('test/extensions', 'test/fixtures/repositories/iso/') @repo_id = 'test_repo_iso_fixture' end @@ -53,14 +51,14 @@ def teardown def test_create_with_importer_and_distributors_objects distributors = [Runcible::Models::IsoDistributor.new(true, true)] - importer = Runcible::Models::IsoImporter.new(:feed=>@repo_url) + importer = Runcible::Models::IsoImporter.new(:feed => @repo_url) response = @extension.create_with_importer_and_distributors(@repo_id, importer, distributors) assert_equal 201, response.code - response = @extension.retrieve(@repo_id, {:details => true}) + response = @extension.retrieve(@repo_id, :details => true) assert_equal @repo_id, response['id'] - assert_equal "iso_importer", response['importers'].first['importer_type_id'] + assert_equal 'iso_importer', response['importers'].first['importer_type_id'] response = @extension.sync(@repo_id) assert_async_response(response) @@ -69,4 +67,4 @@ def test_create_with_importer_and_distributors_objects assert_equal 'success', response.first['result'] end end -end \ No newline at end of file +end diff --git a/test/extensions/package_category_test.rb b/test/extensions/package_category_test.rb index 3bfeba9f..2cb37547 100644 --- a/test/extensions/package_category_test.rb +++ b/test/extensions/package_category_test.rb @@ -6,7 +6,6 @@ module Extensions class TestPackageCategory < MiniTest::Unit::TestCase - def self.before_suite self.support = RepositorySupport.new @@extension = TestRuncible.server.extensions.package_category @@ -29,7 +28,7 @@ def test_all end def test_find - id = @@extension.all.sort_by{|p| p['id']}.first['id'] + id = @@extension.all.sort_by { |p| p['id'] }.first['id'] response = @@extension.find(id) refute_empty response @@ -37,7 +36,7 @@ def test_find end def test_find_by_unit_id - id = @@extension.all.sort_by{|p| p['id']}.first['_id'] + id = @@extension.all.sort_by { |p| p['id'] }.first['_id'] response = @@extension.find_by_unit_id(id) refute_empty response @@ -51,8 +50,8 @@ def test_find_unknown end def test_find_all - pkgs = @@extension.all.sort_by{|p| p['id']} - ids = pkgs[0..2].collect{|p| p['id']} + pkgs = @@extension.all.sort_by { |p| p['id'] } + ids = pkgs[0..2].map { |p| p['id'] } response = @@extension.find_all(ids) assert_equal 200, response.code @@ -60,12 +59,11 @@ def test_find_all end def test_find_all_by_unit_ids - id = @@extension.all.sort_by{|p| p['id']}.first['_id'] + id = @@extension.all.sort_by { |p| p['id'] }.first['_id'] response = @@extension.find_all_by_unit_ids([id]) refute_empty response assert_equal id, response.first['_id'] end - end -end \ No newline at end of file +end diff --git a/test/extensions/package_group_test.rb b/test/extensions/package_group_test.rb index 2b978e51..28e4d17a 100644 --- a/test/extensions/package_group_test.rb +++ b/test/extensions/package_group_test.rb @@ -6,9 +6,7 @@ require './test/support/repository_support' module Extensions - class TestPackageGroup < MiniTest::Unit::TestCase - def self.before_suite self.support = RepositorySupport.new @@extension = TestRuncible.server.extensions.package_group @@ -31,7 +29,7 @@ def test_all end def test_find - id = @@extension.all.sort_by{|p| p['id']}.first['id'] + id = @@extension.all.sort_by { |p| p['id'] }.first['id'] response = @@extension.find(id) refute_empty response @@ -39,7 +37,7 @@ def test_find end def test_find_by_unit_id - id = @@extension.all.sort_by{|p| p['id']}.first['_id'] + id = @@extension.all.sort_by { |p| p['id'] }.first['_id'] response = @@extension.find_by_unit_id(id) refute_empty response @@ -53,8 +51,8 @@ def test_find_unknown end def test_find_all - pkgs = @@extension.all.sort_by{|p| p['id']} - ids = pkgs.collect{|p| p['id']} + pkgs = @@extension.all.sort_by { |p| p['id'] } + ids = pkgs.map { |p| p['id'] } response = @@extension.find_all(ids) assert_equal 200, response.code @@ -62,13 +60,12 @@ def test_find_all end def test_find_all_by_unit_ids - id = @@extension.all.sort_by{|p| p['id']}.first['_id'] + id = @@extension.all.sort_by { |p| p['id'] }.first['_id'] response = @@extension.find_all_by_unit_ids([id]) refute_empty response assert_equal id, response.first['_id'] end - end class TestPackageGroupCopy < UnitCopyBase @@ -84,13 +81,11 @@ def test_copy original_ids = unit_ids(RepositorySupport.repo_id) assert_includes tasks.first['tags'], 'pulp:action:associate' - assert_equal original_ids.length, clone_ids.length + assert_equal original_ids.length, clone_ids.length end - end class TestPackageGroupUnassociate < UnitUnassociateBase - def self.extension_class TestRuncible.server.extensions.package_group end @@ -128,6 +123,5 @@ def test_unassociate_from_repo def test_copied_package_groups assert_equal 2, @unit_ids.length end - end -end \ No newline at end of file +end diff --git a/test/extensions/puppet_repository_test.rb b/test/extensions/puppet_repository_test.rb index 6220cf8c..e78c3041 100644 --- a/test/extensions/puppet_repository_test.rb +++ b/test/extensions/puppet_repository_test.rb @@ -29,12 +29,10 @@ module Extensions module TestPuppetRepositoryBase - def setup - @support = RepositorySupport.new("puppet") + @support = RepositorySupport.new('puppet') @extension = TestRuncible.server.extensions.repository end - end class TestPuppetRepositoryCreate < MiniTest::Unit::TestCase @@ -46,29 +44,29 @@ def teardown end def test_create_with_importer - response = @extension.create_with_importer(RepositorySupport.repo_id, {:id=>"puppet_importer"}) + response = @extension.create_with_importer(RepositorySupport.repo_id, :id => 'puppet_importer') assert_equal 201, response.code - response = @extension.retrieve(RepositorySupport.repo_id, {:details => true}) + response = @extension.retrieve(RepositorySupport.repo_id, :details => true) assert_equal RepositorySupport.repo_id, response['id'] - assert_equal "puppet_importer", response['importers'].first['importer_type_id'] + assert_equal 'puppet_importer', response['importers'].first['importer_type_id'] end def test_create_with_importer_object - response = @extension.create_with_importer(RepositorySupport.repo_id, Runcible::Models::PuppetImporter.new()) + response = @extension.create_with_importer(RepositorySupport.repo_id, Runcible::Models::PuppetImporter.new) assert_equal 201, response.code - response = @extension.retrieve(RepositorySupport.repo_id, {:details => true}) + response = @extension.retrieve(RepositorySupport.repo_id, :details => true) assert_equal RepositorySupport.repo_id, response['id'] - assert_equal "puppet_importer", response['importers'].first['importer_type_id'] + assert_equal 'puppet_importer', response['importers'].first['importer_type_id'] @extension.expects(:create).with(RepositorySupport.repo_id, has_entry(:notes, anything)).returns(true) - @extension.create_with_importer(RepositorySupport.repo_id, Runcible::Models::PuppetImporter.new()) + @extension.create_with_importer(RepositorySupport.repo_id, Runcible::Models::PuppetImporter.new) end def test_create_with_distributors - distributors = [{'type_id' => 'puppet_distributor', 'id'=>'123', 'auto_publish'=>true, - 'config'=>{'relative_url' => '/path', 'http' => true, 'https' => true}}] + distributors = [{'type_id' => 'puppet_distributor', 'id' => '123', 'auto_publish' => true, + 'config' => {'relative_url' => '/path', 'http' => true, 'https' => true}}] response = @extension.create_with_distributors(RepositorySupport.repo_id, distributors) assert_equal 201, response.code @@ -76,40 +74,38 @@ def test_create_with_distributors end def test_create_with_distributor_object - begin - repo_id = RepositorySupport.repo_id + "_distro" - response = @extension.create_with_distributors(repo_id, [Runcible::Models::PuppetDistributor.new( - '/path', true, true, :id => '123')]) - assert_equal 201, response.code - - response = @extension.retrieve(repo_id, {:details => true}) - assert_equal repo_id, response['id'] - assert_equal 'puppet_distributor', response['distributors'].first['distributor_type_id'] - ensure - @support.destroy_repo(repo_id) - end + repo_id = RepositorySupport.repo_id + '_distro' + response = @extension.create_with_distributors(repo_id, [Runcible::Models::PuppetDistributor.new( + '/path', true, true, :id => '123')]) + assert_equal 201, response.code + + response = @extension.retrieve(repo_id, :details => true) + assert_equal repo_id, response['id'] + assert_equal 'puppet_distributor', response['distributors'].first['distributor_type_id'] + ensure + @support.destroy_repo(repo_id) end def test_create_with_importer_and_distributors - distributors = [{'type_id' => 'puppet_distributor', 'id'=>'123', 'auto_publish'=>true, - 'config'=>{'relative_url' => '/', 'http' => true, 'https' => true}}] - response = @extension.create_with_importer_and_distributors(RepositorySupport.repo_id, {:id=>'puppet_importer'}, distributors) + distributors = [{'type_id' => 'puppet_distributor', 'id' => '123', 'auto_publish' => true, + 'config' => {'relative_url' => '/', 'http' => true, 'https' => true}}] + response = @extension.create_with_importer_and_distributors(RepositorySupport.repo_id, {:id => 'puppet_importer'}, distributors) assert_equal 201, response.code - response = @extension.retrieve(RepositorySupport.repo_id, {:details => true}) + response = @extension.retrieve(RepositorySupport.repo_id, :details => true) assert_equal RepositorySupport.repo_id, response['id'] assert_equal 'puppet_distributor', response['distributors'].first['distributor_type_id'] end def test_create_with_importer_and_distributors_objects distributors = [Runcible::Models::PuppetDistributor.new('/path', true, true, :id => '123')] - importer = Runcible::Models::PuppetImporter.new() + importer = Runcible::Models::PuppetImporter.new response = @extension.create_with_importer_and_distributors(RepositorySupport.repo_id, importer, distributors) assert_equal 201, response.code - response = @extension.retrieve(RepositorySupport.repo_id, {:details => true}) + response = @extension.retrieve(RepositorySupport.repo_id, :details => true) assert_equal RepositorySupport.repo_id, response['id'] - assert_equal "puppet_importer", response['importers'].first['importer_type_id'] + assert_equal 'puppet_importer', response['importers'].first['importer_type_id'] end end -end \ No newline at end of file +end diff --git a/test/extensions/repository_test.rb b/test/extensions/repository_test.rb index cb2cc95a..f97bac8e 100644 --- a/test/extensions/repository_test.rb +++ b/test/extensions/repository_test.rb @@ -29,12 +29,10 @@ module Extensions module TestRepositoryBase - def setup @support = RepositorySupport.new @extension = TestRuncible.server.extensions.repository end - end class TestRepositoryCreate < MiniTest::Unit::TestCase @@ -51,26 +49,26 @@ def teardown end def test_create_with_importer - response = @extension.create_with_importer(RepositorySupport.repo_id, {:id=>"yum_importer"}) + response = @extension.create_with_importer(RepositorySupport.repo_id, :id => 'yum_importer') assert_equal 201, response.code - response = @extension.retrieve(RepositorySupport.repo_id, {:details => true}) + response = @extension.retrieve(RepositorySupport.repo_id, :details => true) assert_equal RepositorySupport.repo_id, response['id'] - assert_equal "yum_importer", response['importers'].first['importer_type_id'] + assert_equal 'yum_importer', response['importers'].first['importer_type_id'] end def test_create_with_importer_object - response = @extension.create_with_importer(RepositorySupport.repo_id, Runcible::Models::YumImporter.new()) + response = @extension.create_with_importer(RepositorySupport.repo_id, Runcible::Models::YumImporter.new) assert_equal 201, response.code - response = @extension.retrieve(RepositorySupport.repo_id, {:details => true}) + response = @extension.retrieve(RepositorySupport.repo_id, :details => true) assert_equal RepositorySupport.repo_id, response['id'] - assert_equal "yum_importer", response['importers'].first['importer_type_id'] + assert_equal 'yum_importer', response['importers'].first['importer_type_id'] end def test_create_with_distributors - distributors = [{'type_id' => 'yum_distributor', 'id'=>'123', 'auto_publish'=>true, - 'config'=>{'relative_url' => '/path', 'http' => true, 'https' => true}}] + distributors = [{'type_id' => 'yum_distributor', 'id' => '123', 'auto_publish' => true, + 'config' => {'relative_url' => '/path', 'http' => true, 'https' => true}}] response = @extension.create_with_distributors(RepositorySupport.repo_id, distributors) assert_equal 201, response.code @@ -78,12 +76,12 @@ def test_create_with_distributors end def test_create_with_distributor_object - repo_id = RepositorySupport.repo_id + "_distro" + repo_id = RepositorySupport.repo_id + '_distro' response = @extension.create_with_distributors(repo_id, [Runcible::Models::YumDistributor.new( '/path', true, true, :id => '123')]) assert_equal 201, response.code - response = @extension.retrieve(repo_id, {:details => true}) + response = @extension.retrieve(repo_id, :details => true) assert_equal repo_id, response['id'] assert_equal 'yum_distributor', response['distributors'].first['distributor_type_id'] ensure @@ -91,12 +89,12 @@ def test_create_with_distributor_object end def test_create_with_importer_and_distributors - distributors = [{'type_id' => 'yum_distributor', 'id'=>'123', 'auto_publish'=>true, - 'config'=>{'relative_url' => '/123/456', 'http' => true, 'https' => true}}] - response = @extension.create_with_importer_and_distributors(RepositorySupport.repo_id, {:id=>'yum_importer'}, distributors) + distributors = [{'type_id' => 'yum_distributor', 'id' => '123', 'auto_publish' => true, + 'config' => {'relative_url' => '/123/456', 'http' => true, 'https' => true}}] + response = @extension.create_with_importer_and_distributors(RepositorySupport.repo_id, {:id => 'yum_importer'}, distributors) assert_equal 201, response.code - response = @extension.retrieve(RepositorySupport.repo_id, {:details => true}) + response = @extension.retrieve(RepositorySupport.repo_id, :details => true) assert_equal RepositorySupport.repo_id, response['id'] assert_equal 'yum_distributor', response['distributors'].first['distributor_type_id'] end @@ -104,20 +102,17 @@ def test_create_with_importer_and_distributors def test_create_with_importer_and_distributors_objects distributors = [Runcible::Models::YumDistributor.new( '/path', true, true, :id => '123')] - importer = Runcible::Models::YumImporter.new() + importer = Runcible::Models::YumImporter.new response = @extension.create_with_importer_and_distributors(RepositorySupport.repo_id, importer, distributors) assert_equal 201, response.code - response = @extension.retrieve(RepositorySupport.repo_id, {:details => true}) + response = @extension.retrieve(RepositorySupport.repo_id, :details => true) assert_equal RepositorySupport.repo_id, response['id'] - assert_equal "yum_importer", response['importers'].first['importer_type_id'] + assert_equal 'yum_importer', response['importers'].first['importer_type_id'] end - - end class TestRepositoryMisc < MiniTest::Unit::TestCase - def self.before_suite self.support = RepositorySupport.new self.support.create_and_sync_repo(:importer_and_distributor => true) @@ -135,20 +130,20 @@ def test_search_by_repository_ids response = @extension.search_by_repository_ids([RepositorySupport.repo_id]) assert_equal 200, response.code - refute_empty response.collect{ |repo| repo["display_name"] == RepositorySupport.repo_id } + refute_empty response.map { |repo| repo['display_name'] == RepositorySupport.repo_id } end def test_create_or_update_schedule - response = @extension.create_or_update_schedule(RepositorySupport.repo_id, 'yum_importer', "2012-09-25T20:44:00Z/P7D") + response = @extension.create_or_update_schedule(RepositorySupport.repo_id, 'yum_importer', '2012-09-25T20:44:00Z/P7D') assert_equal 201, response.code - response = @extension.create_or_update_schedule(RepositorySupport.repo_id, 'yum_importer', "2011-09-25T20:44:00Z/P7D") + response = @extension.create_or_update_schedule(RepositorySupport.repo_id, 'yum_importer', '2011-09-25T20:44:00Z/P7D') assert_equal 200, response.code end def test_remove_schedules - TestRuncible.server.resources.repository_schedule.create(RepositorySupport.repo_id, 'yum_importer', "2012-10-25T20:44:00Z/P7D") - response = @extension.remove_schedules(RepositorySupport.repo_id, "yum_importer") + TestRuncible.server.resources.repository_schedule.create(RepositorySupport.repo_id, 'yum_importer', '2012-10-25T20:44:00Z/P7D') + response = @extension.remove_schedules(RepositorySupport.repo_id, 'yum_importer') assert_equal 200, response.code end @@ -156,7 +151,7 @@ def test_remove_schedules def test_retrieve_with_details response = @extension.retrieve_with_details(RepositorySupport.repo_id) - assert_equal 200, response.code + assert_equal 200, response.code assert_includes response, 'distributors' end @@ -186,12 +181,9 @@ def test_generate_applicability_by_ids tasks = assert_async_response(response) assert_equal 'finished', tasks.first['state'] end - end - class TestRepositoryUnitList < MiniTest::Unit::TestCase - def self.before_suite @@extension = TestRuncible.server.extensions.repository self.support = RepositorySupport.new @@ -206,15 +198,15 @@ def self.after_suite def test_rpm_ids response = @@extension.rpm_ids(RepositorySupport.repo_id) - refute_empty response - assert_kind_of String, response.first + refute_empty response + assert_kind_of String, response.first end def test_rpms response = @@extension.rpms(RepositorySupport.repo_id) - refute_empty response - assert_kind_of Hash, response.first + refute_empty response + assert_kind_of Hash, response.first end def test_errata_ids @@ -261,6 +253,5 @@ def test_rpms_by_nvre refute_empty response end - end -end \ No newline at end of file +end diff --git a/test/extensions/rpm_test.rb b/test/extensions/rpm_test.rb index b26a1b80..95c40a8c 100644 --- a/test/extensions/rpm_test.rb +++ b/test/extensions/rpm_test.rb @@ -7,7 +7,6 @@ module Extensions class TestRpm < MiniTest::Unit::TestCase - def self.before_suite self.support = RepositorySupport.new @@extension = TestRuncible.server.extensions.rpm @@ -38,7 +37,7 @@ def test_find_all end def test_find_by_unit_id - id = @@extension.all.sort_by{|p| p['_id']}.first['_id'] + id = @@extension.all.sort_by { |p| p['_id'] }.first['_id'] response = @@extension.find_by_unit_id(id) refute_empty response @@ -52,18 +51,16 @@ def test_find_unknown end def test_find_all_by_unit_ids - pkgs = @@extension.all.sort_by{|p| p['_id']} - ids = pkgs[0..2].collect{|p| p['_id']} + pkgs = @@extension.all.sort_by { |p| p['_id'] } + ids = pkgs[0..2].map { |p| p['_id'] } response = @@extension.find_all_by_unit_ids(ids) assert_equal 200, response.code assert_equal ids.length, response.length end - end class TestRpmCopy < UnitCopyBase - def self.extension_class TestRuncible.server.extensions.rpm end @@ -79,10 +76,10 @@ def test_copy_with_filters response = self.class.extension_class.copy(RepositorySupport.repo_id, self.class.clone_name, :filters => { - :unit => { - "$and" => [{'name' => {'$regex' => 'p.*'}}, - {'version'=> {'$gt'=> '1.0'}}] - }} + :unit => { + '$and' => [{'name' => {'$regex' => 'p.*'}}, + {'version' => {'$gt' => '1.0'}}] + }} ) tasks = assert_async_response(response) assert_includes tasks.first['tags'], 'pulp:action:associate' @@ -90,7 +87,6 @@ def test_copy_with_filters end class TestRpmUnassociate < UnitUnassociateBase - def self.extension_class TestRuncible.server.extensions.rpm end @@ -125,6 +121,5 @@ def test_unassociate_from_repo assert_async_response(response) assert_equal (ids.length - 1), unit_ids(self.class.clone_name).length end - end -end \ No newline at end of file +end diff --git a/test/extensions/unit_base.rb b/test/extensions/unit_base.rb index 79206298..2b8e24ef 100644 --- a/test/extensions/unit_base.rb +++ b/test/extensions/unit_base.rb @@ -30,7 +30,7 @@ module Extensions class UnitCopyBase < MiniTest::Unit::TestCase def self.clone_name - RepositorySupport.repo_id + "_clone" + RepositorySupport.repo_id + '_clone' end def self.before_suite @@ -39,7 +39,7 @@ def self.before_suite self.support.destroy_repo(clone_name) self.support.destroy_repo self.support.create_and_sync_repo(:importer => true) - TestRuncible.server.extensions.repository.create_with_importer(clone_name, {:id=>"yum_importer"}) + TestRuncible.server.extensions.repository.create_with_importer(clone_name, :id => 'yum_importer') end end @@ -52,26 +52,24 @@ def self.after_suite def units(repo) TestRuncible.server.extensions.repository.unit_search(repo, - :type_ids=>[self.class.extension_class.class.content_type]) + :type_ids => [self.class.extension_class.class.content_type]) end def unit_ids(repo) - units(repo).collect {|i| i['unit_id']} + units(repo).map { |i| i['unit_id'] } end - end - class UnitUnassociateBase < MiniTest::Unit::TestCase def self.clone_name - RepositorySupport.repo_id + "_clone" + RepositorySupport.repo_id + '_clone' end def self.before_suite self.support = RepositorySupport.new if respond_to?(:extension_class) self.support.create_and_sync_repo(:importer => true) - TestRuncible.server.extensions.repository.create_with_importer(clone_name, {:id=>"yum_importer"}) + TestRuncible.server.extensions.repository.create_with_importer(clone_name, :id => 'yum_importer') end end @@ -84,17 +82,16 @@ def self.after_suite def content_ids(repo) groups = units(repo) - groups.collect{|i| i['metadata']['id']} + groups.map { |i| i['metadata']['id'] } end def units(repo) TestRuncible.server.extensions.repository.unit_search(repo, - :type_ids=>[self.class.extension_class.content_type]) + :type_ids => [self.class.extension_class.content_type]) end def unit_ids(repo) - units(repo).collect {|i| i['unit_id']} + units(repo).map { |i| i['unit_id'] } end - end -end \ No newline at end of file +end diff --git a/test/extensions/yum_clone_distributor_test.rb b/test/extensions/yum_clone_distributor_test.rb index a2eab4cf..1e324a84 100644 --- a/test/extensions/yum_clone_distributor_test.rb +++ b/test/extensions/yum_clone_distributor_test.rb @@ -5,19 +5,17 @@ module Extensions class TestExtensionsRpm < MiniTest::Unit::TestCase - def setup - @dist = Runcible::Models::YumCloneDistributor.new(:id=>"some_distributor_clone", - :destination_distributor_id => "Foo_dist") + @dist = Runcible::Models::YumCloneDistributor.new(:id => 'some_distributor_clone', + :destination_distributor_id => 'Foo_dist') end def test_config - assert_equal({:destination_distributor_id => "Foo_dist"}.as_json, @dist.config) + assert_equal({:destination_distributor_id => 'Foo_dist'}.as_json, @dist.config) end def test_type_id - assert_equal('yum_clone_distributor', @dist.class.type_id) + assert_equal('yum_clone_distributor', @dist.class.type_id) end - end -end \ No newline at end of file +end diff --git a/test/models/puppet_distributor_test.rb b/test/models/puppet_distributor_test.rb index 713c0517..b3d62d81 100644 --- a/test/models/puppet_distributor_test.rb +++ b/test/models/puppet_distributor_test.rb @@ -4,18 +4,16 @@ require './lib/runcible' class PuppetDistributorTest < MiniTest::Unit::TestCase - def setup - @dist = Runcible::Models::PuppetDistributor.new("/some/path/testing/", true, true) + @dist = Runcible::Models::PuppetDistributor.new('/some/path/testing/', true, true) end def test_config - config = {"absolute_path" => "/some/path/testing/", "serve_http" => true, "serve_https" => true} + config = {'absolute_path' => '/some/path/testing/', 'serve_http' => true, 'serve_https' => true} assert_equal config, @dist.config end def test_type_id assert_equal('puppet_distributor', @dist.type_id) end - end diff --git a/test/models/puppet_importer_test.rb b/test/models/puppet_importer_test.rb index e6e053e9..73935c44 100644 --- a/test/models/puppet_importer_test.rb +++ b/test/models/puppet_importer_test.rb @@ -4,9 +4,8 @@ require './lib/runcible' class PuppetImporterTest < MiniTest::Unit::TestCase - def setup - @attrs = {"feed" => "http://forge.puppetlabs.com", "queries" => "apache"} + @attrs = {'feed' => 'http://forge.puppetlabs.com', 'queries' => 'apache'} @importer = Runcible::Models::PuppetImporter.new(@attrs) end @@ -17,5 +16,4 @@ def test_config def test_repo_type assert_equal Runcible::Models::PuppetImporter::REPO_TYPE, @importer.repo_type end - end diff --git a/test/models/puppet_install_distributor_test.rb b/test/models/puppet_install_distributor_test.rb index fd1ca14b..33696442 100644 --- a/test/models/puppet_install_distributor_test.rb +++ b/test/models/puppet_install_distributor_test.rb @@ -4,18 +4,16 @@ require './lib/runcible' class PuppetInstallDistributorTest < MiniTest::Unit::TestCase - def setup - @dist = Runcible::Models::PuppetInstallDistributor.new("/etc/puppet") + @dist = Runcible::Models::PuppetInstallDistributor.new('/etc/puppet') end def test_config - config = {"install_path" => "/etc/puppet", "auto_publish" => false} + config = {'install_path' => '/etc/puppet', 'auto_publish' => false} assert_equal config, @dist.config end def test_type_id assert_equal('puppet_install_distributor', @dist.type_id) end - end diff --git a/test/resources/consumer_group_test.rb b/test/resources/consumer_group_test.rb index f619c1dd..8818a447 100644 --- a/test/resources/consumer_group_test.rb +++ b/test/resources/consumer_group_test.rb @@ -29,26 +29,23 @@ require './test/support/repository_support' require './test/support/consumer_support' - module Resources +module Resources module TestConsumerGroupBase - - def setup - @resource = TestRuncible.server.resources.consumer_group - @consumer_group_id = "integration_test_consumer_group" + def setu(p) + @resource = TestRuncible.server.resources.consumer_grou p + @consumer_group_id = 'integration_test_consumer_group ' end - def create_consumer_group - @resource.create(@consumer_group_id, :display_name => "foo", :description => 'Test description.', :consumer_ids => []) - rescue Exception => e + def create_consumer_grou(_p) + @resource.create(@consumer_group_id, :display_name => 'foo', :description => 'Test description.', :consumer_ids => []) + rescue => e end - def destroy_consumer_group + def destroy_consumer_grou(_p) @resource.delete(@consumer_group_id) - rescue Exception => e + rescue => e end - - end - +end class TestConsumerGroupCreate < MiniTest::Unit::TestCase include TestConsumerGroupBase @@ -65,7 +62,6 @@ def test_create end end - class TestConsumerGroupDestroy < MiniTest::Unit::TestCase include TestConsumerGroupBase @@ -79,7 +75,6 @@ def test_destroy assert_equal 200, response.code end - end class ConsumerGroupTests < MiniTest::Unit::TestCase @@ -95,7 +90,6 @@ def teardown destroy_consumer_group super end - end class TestConsumerGroup < ConsumerGroupTests @@ -119,11 +113,9 @@ def test_retrieve assert_equal @consumer_group_id, response['id'] assert_empty response['consumer_ids'] end - end class ConsumerGroupWithConsumerTests < ConsumerGroupTests - def setup super @support = ConsumerSupport.new @@ -131,7 +123,7 @@ def setup @criteria = {:criteria => {:filters => {:id => - {"$in" => [ConsumerSupport.consumer_id]} + {'$in' => [ConsumerSupport.consumer_id]} } } } @@ -141,44 +133,37 @@ def teardown @support.destroy_consumer super end - end class TestConsumerGroupAssociate < ConsumerGroupWithConsumerTests - def test_associate response = @resource.associate(@consumer_group_id, @criteria) - assert_equal 200, response.code + assert_equal 200, response.code assert_includes response, ConsumerSupport.consumer_id end - end class TestConsumerGroupUnassociate < ConsumerGroupWithConsumerTests - def setup super @resource.associate(@consumer_group_id, @criteria) end def test_unassociate - assert_includes @resource.retrieve(@consumer_group_id)["consumer_ids"], ConsumerSupport.consumer_id + assert_includes @resource.retrieve(@consumer_group_id)['consumer_ids'], ConsumerSupport.consumer_id response = @resource.unassociate(@consumer_group_id, @criteria) - assert_equal 200, response.code + assert_equal 200, response.code refute_includes response, ConsumerSupport.consumer_id - refute_includes @resource.retrieve(@consumer_group_id)["consumer_ids"], ConsumerSupport.consumer_id + refute_includes @resource.retrieve(@consumer_group_id)['consumer_ids'], ConsumerSupport.consumer_id end end - class TestConsumerGroupRequiresRepo < ConsumerGroupTests - def self.before_suite RepositorySupport.new.create_and_sync_repo(:importer_and_distributor => true) - end def self.after_suite @@ -190,9 +175,9 @@ def setup @support.create_consumer criteria = {:criteria => {:filters => - {:id => {"$in" => [ConsumerSupport.consumer_id]}}}} + {:id => {'$in' => [ConsumerSupport.consumer_id]}}}} - distro_id = RepositorySupport.new.distributor()['id'] + distro_id = RepositorySupport.new.distributor['id'] TestRuncible.server.resources.consumer.bind(ConsumerSupport.consumer_id, RepositorySupport.repo_id, distro_id) @resource.associate(@consumer_group_id, criteria) @@ -204,25 +189,24 @@ def teardown end def test_install_units - response = @resource.install_units(@consumer_group_id, ["unit_key"=>{:name => "zsh"}, "type_id" => "rpm"]) + response = @resource.install_units(@consumer_group_id, ['unit_key' => {:name => 'zsh'}, 'type_id' => 'rpm']) - assert_equal 202, response.code - assert response["spawned_tasks"].first["task_id"] + assert_equal 202, response.code + assert response['spawned_tasks'].first['task_id'] end def test_update_units - response = @resource.update_units(@consumer_group_id, ["unit_key"=>{:name => "zsh"}, "type_id" => "rpm"]) + response = @resource.update_units(@consumer_group_id, ['unit_key' => {:name => 'zsh'}, 'type_id' => 'rpm']) - assert_equal 202, response.code - assert response["spawned_tasks"].first["task_id"] + assert_equal 202, response.code + assert response['spawned_tasks'].first['task_id'] end def test_uninstall_units - response = @resource.uninstall_units(@consumer_group_id, ["unit_key"=>{:name => "zsh"}, "type_id" => "rpm"]) + response = @resource.uninstall_units(@consumer_group_id, ['unit_key' => {:name => 'zsh'}, 'type_id' => 'rpm']) - assert_equal 202, response.code - assert response["spawned_tasks"].first["task_id"] + assert_equal 202, response.code + assert response['spawned_tasks'].first['task_id'] end - end -end \ No newline at end of file +end diff --git a/test/resources/consumer_test.rb b/test/resources/consumer_test.rb index a28e3470..5ba59554 100644 --- a/test/resources/consumer_test.rb +++ b/test/resources/consumer_test.rb @@ -31,18 +31,17 @@ module Resources module TestConsumerBase - def setup @resource = TestRuncible.server.resources.consumer @extension = TestRuncible.server.extensions.consumer - @consumer_id = "integration_test_consumer" + @consumer_id = 'integration_test_consumer' end def create_consumer(package_profile = false) - consumer = @resource.create(@consumer_id, :name=>"boo") + consumer = @resource.create(@consumer_id, :name => 'boo') if package_profile - @consumer_resource.upload_profile(@consumer_id,'rpm',[{"name" => "elephant", "version" => "0.2", "release" => "0.7", - "epoch" => 0, "arch" => "noarch"}]) + @consumer_resource.upload_profile(@consumer_id, 'rpm', [{'name' => 'elephant', 'version' => '0.2', 'release' => '0.7', + 'epoch' => 0, 'arch' => 'noarch'}]) end consumer end @@ -51,7 +50,6 @@ def destroy_consumer @resource.delete(@consumer_id) rescue end - end class ConsumerTests < MiniTest::Unit::TestCase @@ -66,10 +64,8 @@ def teardown destroy_consumer super end - end - class TestConsumerCreate < MiniTest::Unit::TestCase include TestConsumerBase @@ -81,10 +77,9 @@ def teardown def test_create response = create_consumer - assert response.kind_of? Hash + assert response.is_a? Hash assert_equal @consumer_id, response['consumer']['id'] end - end class TestConsumerDestroy < MiniTest::Unit::TestCase @@ -100,10 +95,8 @@ def test_destroy assert_equal 200, response.code end - end - class TestGeneralMethods < MiniTest::Unit::TestCase include TestConsumerBase @@ -137,17 +130,15 @@ def test_retrieve end def test_update - description = "Test description" + description = 'Test description' response = @resource.update(@consumer_id, :description => description) assert_equal 200, response.code assert_equal description, response['description'] end - end - - class TestConsumerApplicability "FedoraHosted", "name" => "elephant", - "version" => "0.3", "release" => "0.8", - "arch" => "noarch", "epoch" => ""}] + packages = [{'vendor' => 'FedoraHosted', 'name' => 'elephant', + 'version' => '0.3', 'release' => '0.8', + 'arch' => 'noarch', 'epoch' => ''}] response = @resource.upload_profile(@consumer_id, 'rpm', packages) assert_equal 201, response.code end def test_retrieve_profile - packages = [{"vendor" => "FedoraHosted", "name" => "elephant", - "version" => "0.3", "release" => "0.8", - "arch" => "noarch", "epoch" => "1"}] + packages = [{'vendor' => 'FedoraHosted', 'name' => 'elephant', + 'version' => '0.3', 'release' => '0.8', + 'arch' => 'noarch', 'epoch' => '1'}] @resource.upload_profile(@consumer_id, 'rpm', packages) response = @resource.retrieve_profile(@consumer_id, 'rpm') - assert_equal @consumer_id, response["consumer_id"] - assert_equal packages, response["profile"] + assert_equal @consumer_id, response['consumer_id'] + assert_equal packages, response['profile'] end - end - class ConsumerRequiresRepoTests < MiniTest::Unit::TestCase include TestConsumerBase @@ -237,18 +223,15 @@ def self.after_suite end def self.bind_repo - distro_id = @@repo_support.distributor()['id'] + distro_id = @@repo_support.distributor['id'] tasks = TestRuncible.server.resources.consumer.bind(ConsumerSupport.consumer_id, - RepositorySupport.repo_id, distro_id, {:notify_agent=>false}) + RepositorySupport.repo_id, distro_id, :notify_agent => false) @@repo_support.wait_on_response(tasks) return tasks end - end - class TestConsumerBindings < ConsumerRequiresRepoTests - def test_bind response = self.class.bind_repo @@ -258,26 +241,23 @@ def test_bind def test_unbind self.class.bind_repo - distro_id = @@repo_support.distributor()['id'] + distro_id = @@repo_support.distributor['id'] refute_empty @resource.retrieve_bindings(ConsumerSupport.consumer_id) response = @resource.unbind(ConsumerSupport.consumer_id, RepositorySupport.repo_id, distro_id) assert_equal 200, response.code end - end - class TestConsumerRequiresRepo < ConsumerRequiresRepoTests - def self.before_suite super bind_repo end def test_retrieve_binding - distributor_id = @@repo_support.distributor()['id'] + distributor_id = @@repo_support.distributor['id'] response = @resource.retrieve_binding(ConsumerSupport.consumer_id, RepositorySupport.repo_id, distributor_id) assert_equal 200, response.code @@ -292,25 +272,24 @@ def test_retrieve_bindings end def test_install_units - response = @resource.install_units(ConsumerSupport.consumer_id, - [{"unit_key"=>{:name => "zsh"}, :type_id => 'rpm'}]) + response = @resource.install_units(ConsumerSupport.consumer_id, + [{'unit_key' => {:name => 'zsh'}, :type_id => 'rpm'}]) assert_equal 202, response.code refute_empty response end def test_update_units response = @resource.update_units(ConsumerSupport.consumer_id, - [{"unit_key"=>{:name => "zsh"}, :type_id => 'rpm'}]) + [{'unit_key' => {:name => 'zsh'}, :type_id => 'rpm'}]) assert_equal 202, response.code refute_empty response end def test_uninstall_units response = @resource.uninstall_units(ConsumerSupport.consumer_id, - [{"unit_key"=>{:name => "zsh"}, :type_id => 'rpm'}]) + [{'unit_key' => {:name => 'zsh'}, :type_id => 'rpm'}]) assert_equal 202, response.code refute_empty response end - end -end \ No newline at end of file +end diff --git a/test/resources/content_test.rb b/test/resources/content_test.rb index cba51f32..02fb73e9 100644 --- a/test/resources/content_test.rb +++ b/test/resources/content_test.rb @@ -15,9 +15,7 @@ require './test/support/repository_support' module Resources - module TestContentBase - def setup @resource = TestRuncible.server.resources.content end @@ -29,10 +27,9 @@ class TestCreateUploadRequest < MiniTest::Unit::TestCase def test_create_upload_request response = @resource.create_upload_request - assert response.kind_of? Hash + assert response.is_a? Hash assert_equal 201, response.code end - end class TestUploadBits < MiniTest::Unit::TestCase @@ -43,15 +40,14 @@ def test_upload_bits response = @resource.upload_bits(test_request['upload_id'], '0', 'abcde') assert_equal 200, response.code end - end class TestImportIntoRepo < MiniTest::Unit::TestCase include TestContentBase def test_import_into_repo - test_unit_key = {"checksumtype"=> "sha256", "checksum"=> "5e9fb809128d23a3e25d0c5fd38dd5d37d4ebceae7c6af8f15fed93e39d3145f", - "epoch"=> "0", "version"=> "8.3.3", "release"=> "1.elfake", "arch"=> "noarch", "name"=> "recons"} + test_unit_key = {'checksumtype' => 'sha256', 'checksum' => '5e9fb809128d23a3e25d0c5fd38dd5d37d4ebceae7c6af8f15fed93e39d3145f', + 'epoch' => '0', 'version' => '8.3.3', 'release' => '1.elfake', 'arch' => 'noarch', 'name' => 'recons'} self.class.support = RepositorySupport.new self.class.support.create_and_sync_repo(:importer_and_distributor => true) @@ -59,9 +55,7 @@ def test_import_into_repo assert_async_response(response) ensure self.class.support.destroy_repo - end - end class TestDeleteUploadRequest < MiniTest::Unit::TestCase @@ -72,7 +66,6 @@ def test_delete_upload_request response = @resource.delete_upload_request(test_request['upload_id']) assert_equal 200, response.code end - end class TestListAllUploadRequests < MiniTest::Unit::TestCase @@ -83,10 +76,8 @@ def test_list_all_requests assert_equal 200, response.code end - end - class TestOrphans < MiniTest::Unit::TestCase include TestContentBase @@ -98,5 +89,4 @@ def test_remove_orphans assert @resource.remove_orphans.is_a?(Hash) end end - -end \ No newline at end of file +end diff --git a/test/resources/event_notifier_test.rb b/test/resources/event_notifier_test.rb index 580eb036..9573fb0c 100644 --- a/test/resources/event_notifier_test.rb +++ b/test/resources/event_notifier_test.rb @@ -28,13 +28,11 @@ require './lib/runcible/resources/event_notifier' module Resources - module TestEventNotifierBase def setup @resource = TestRuncible.server.resources.event_notifier @resource_class = Runcible::Resources::EventNotifier end - end class TestEventNotifier < MiniTest::Unit::TestCase @@ -50,22 +48,20 @@ def teardown end def test_create - response = @resource.create(@resource_class::NotifierTypes::REST_API, {:url=>'http://foo.com/foo/'}, + response = @resource.create(@resource_class::NotifierTypes::REST_API, {:url => 'http://foo.com/foo/'}, [@resource_class::EventTypes::REPO_PUBLISH_COMPLETE]) @@notifier_id = response['id'] assert_equal 201, response.code end - end - class TestEventNotifierList < MiniTest::Unit::TestCase include TestEventNotifierBase def setup super - response = @resource.create(@resource.class::NotifierTypes::REST_API, {:url=>'http://foo.com/foo/'}, + response = @resource.create(@resource.class::NotifierTypes::REST_API, {:url => 'http://foo.com/foo/'}, [@resource_class::EventTypes::REPO_PUBLISH_COMPLETE]) @@notifier_id = response['id'] end @@ -75,12 +71,11 @@ def teardown end def test_list - response = @resource.list() + response = @resource.list assert_equal 200, response.code refute_empty response end - end class TestEventNotifierDelete < MiniTest::Unit::TestCase @@ -88,7 +83,7 @@ class TestEventNotifierDelete < MiniTest::Unit::TestCase def setup super - response = @resource.create(@resource.class::NotifierTypes::REST_API, {:url=>'http://foo.com/foo/'}, + response = @resource.create(@resource.class::NotifierTypes::REST_API, {:url => 'http://foo.com/foo/'}, [@resource_class::EventTypes::REPO_PUBLISH_COMPLETE]) @@notifier_id = response['id'] end @@ -98,7 +93,5 @@ def test_remove assert_equal 200, response.code end - end - -end \ No newline at end of file +end diff --git a/test/resources/puppet_repository_test.rb b/test/resources/puppet_repository_test.rb index 3d12ee44..e2ed3804 100644 --- a/test/resources/puppet_repository_test.rb +++ b/test/resources/puppet_repository_test.rb @@ -29,13 +29,11 @@ module Resources module TestPuppetRepositoryBase - def setup @resource = TestRuncible.server.resources.repository @extension = TestRuncible.server.extensions.repository @support = RepositorySupport.new end - end class TestPuppetRepositoryRequiresSync < MiniTest::Unit::TestCase @@ -73,9 +71,8 @@ def test_unit_search def test_sync_history response = @resource.sync_history(RepositorySupport.repo_id) - assert 200, response.code - refute_empty response + assert 200, response.code + refute_empty response end - end -end \ No newline at end of file +end diff --git a/test/resources/repository_group_test.rb b/test/resources/repository_group_test.rb index 6c7d54d3..728c1a03 100644 --- a/test/resources/repository_group_test.rb +++ b/test/resources/repository_group_test.rb @@ -29,26 +29,23 @@ module Resources module TestRepoGroupBase - def setup @support = RepositorySupport.new @resource = TestRuncible.server.resources.repository_group - @repo_group_id = "integration_test_repository_group" + @repo_group_id = 'integration_test_repository_group' end def create_repo_group - @resource.create(@repo_group_id, :display_name => "foo", :description => 'Test description.') - rescue Exception => e + @resource.create(@repo_group_id, :display_name => 'foo', :description => 'Test description.') + rescue => e end def destroy_repo_group @resource.delete(@repo_group_id) - rescue Exception => e + rescue => e end - end - class TestRepoGroupCreate < MiniTest::Unit::TestCase include TestRepoGroupBase @@ -61,10 +58,8 @@ def test_create response = create_repo_group assert_equal @repo_group_id, response['id'] end - end - class TestRepoGroup < MiniTest::Unit::TestCase include TestRepoGroupBase @@ -79,18 +74,17 @@ def setup end def test_retrieve - response = @resource.retrieve(@repo_group_id) - assert_equal @repo_group_id, response['id'] + response = @resource.retrieve(@repo_group_id) + assert_equal @repo_group_id, response['id'] end def test_retrieve_all response = @resource.retrieve_all refute_empty response - assert_equal 1, response.select{|grp| grp[:id] == @repo_group_id}.size + assert_equal 1, response.select { |grp| grp[:id] == @repo_group_id }.size end end - class TestRepoGroupDestroy < MiniTest::Unit::TestCase include TestRepoGroupBase @@ -103,10 +97,8 @@ def test_destroy response = @resource.delete(@repo_group_id) assert_equal 200, response.code end - end - class TestRepoGroupAssociate < MiniTest::Unit::TestCase include TestRepoGroupBase @@ -127,18 +119,17 @@ def test_associate @criteria = {:criteria => {:filters => {:id => - {"$in" => [@repo_id]} + {'$in' => [@repo_id]} } } } response = @resource.associate(@repo_group_id, @criteria) - assert_equal 200, response.code + assert_equal 200, response.code assert_includes response, @repo_id end end - class TestRepoGroupUnassociate < MiniTest::Unit::TestCase include TestRepoGroupBase @@ -150,7 +141,7 @@ def setup @criteria = {:criteria => {:filters => {:id => - {"$in" => [@repo_id]} + {'$in' => [@repo_id]} } } } @@ -166,8 +157,8 @@ def teardown def test_unassociate response = @resource.unassociate(@repo_group_id, @criteria) - assert_equal 200, response.code + assert_equal 200, response.code refute_includes response, @repo_id end end -end \ No newline at end of file +end diff --git a/test/resources/repository_schedule_test.rb b/test/resources/repository_schedule_test.rb index 6703f91b..a7d81314 100644 --- a/test/resources/repository_schedule_test.rb +++ b/test/resources/repository_schedule_test.rb @@ -28,12 +28,10 @@ module Resources module TestScheduleBase - def setup @resource = TestRuncible.server.resources.repository_schedule @support = RepositorySupport.new end - end class TestRepositoryCreateSchedule < MiniTest::Unit::TestCase @@ -41,7 +39,7 @@ class TestRepositoryCreateSchedule < MiniTest::Unit::TestCase def setup super - @support.create_repo :importer=>true + @support.create_repo :importer => true @support.create_schedule end @@ -53,11 +51,11 @@ def teardown def test_repository_schedules_path path = @resource.class.path('foo', 'some_importer') - assert_match "repositories/foo/importers/some_importer/schedules/sync/", path + assert_match 'repositories/foo/importers/some_importer/schedules/sync/', path end def test_schedule_create - response = @resource.create(RepositorySupport.repo_id, 'yum_importer', "2012-09-25T20:44:00Z/P7D") + response = @resource.create(RepositorySupport.repo_id, 'yum_importer', '2012-09-25T20:44:00Z/P7D') assert_equal 201, response.code end @@ -67,7 +65,6 @@ def test_list_schedules assert_match list.first[:schedule], @support.schedule_time end - end class TestScheduleUpdate < MiniTest::Unit::TestCase @@ -75,7 +72,7 @@ class TestScheduleUpdate < MiniTest::Unit::TestCase def setup super - @support.create_repo :importer=>true + @support.create_repo :importer => true @support.create_schedule end @@ -86,19 +83,18 @@ def teardown def test_update_schedule id = @resource.list(RepositorySupport.repo_id, 'yum_importer').first['_id'] - response = @resource.update(RepositorySupport.repo_id, 'yum_importer', id, {:schedule=>'P1DT'}) + response = @resource.update(RepositorySupport.repo_id, 'yum_importer', id, :schedule => 'P1DT') assert_equal 200, response.code end end - class TestScheduleDelete < MiniTest::Unit::TestCase include TestScheduleBase def setup super - @support.create_repo :importer=>true + @support.create_repo :importer => true @support.create_schedule end @@ -113,6 +109,5 @@ def test_delete_schedules assert_equal 200, response.code end - end -end \ No newline at end of file +end diff --git a/test/resources/repository_test.rb b/test/resources/repository_test.rb index d6b11979..50579cb5 100644 --- a/test/resources/repository_test.rb +++ b/test/resources/repository_test.rb @@ -14,31 +14,26 @@ require './test/support/repository_support' require './lib/runcible' - module Resources module TestRepositoryBase - def setup @resource = TestRuncible.server.resources.repository @extension = TestRuncible.server.extensions.repository @support = RepositorySupport.new end - def assert_async_response(response) if response.code == 202 tasks = @support.wait_on_response(response) tasks.each do |task| - assert task["state"], "finished" + assert task['state'], 'finished' end else assert response.code, 200 end end - end - class TestRepositoryCreate < MiniTest::Unit::TestCase include TestRepositoryBase @@ -59,7 +54,6 @@ def test_create end end - class TestRepositoryDelete < MiniTest::Unit::TestCase include TestRepositoryBase @@ -74,7 +68,6 @@ def test_delete assert_equal 202, response.code end - end class TestRepositoryMisc < MiniTest::Unit::TestCase @@ -94,7 +87,7 @@ def teardown def test_path path = @resource.class.path - assert_match "repositories/", path + assert_match 'repositories/', path end def test_repository_path_with_id @@ -104,21 +97,21 @@ def test_repository_path_with_id end def test_update - response = @resource.update(RepositorySupport.repo_id, { :description => "updated_description_" + RepositorySupport.repo_id }) + response = @resource.update(RepositorySupport.repo_id, :description => 'updated_description_' + RepositorySupport.repo_id) assert_equal 200, response.code - assert_equal "updated_description_" + RepositorySupport.repo_id, response["result"]["description"] + assert_equal 'updated_description_' + RepositorySupport.repo_id, response['result']['description'] end def test_retrieve - response = @resource.retrieve(RepositorySupport.repo_id) + response = @resource.retrieve(RepositorySupport.repo_id) - assert_equal 200, response.code - assert_equal RepositorySupport.repo_id, response["display_name"] + assert_equal 200, response.code + assert_equal RepositorySupport.repo_id, response['display_name'] end def test_retrieve_all - response = @resource.retrieve_all() + response = @resource.retrieve_all assert_equal 200, response.code refute_empty response @@ -140,10 +133,8 @@ def test_generate_applicability task = RepositorySupport.new.wait_on_response(response) assert 'finished', task.first['state'] end - end - class TestRespositoryDistributor < MiniTest::Unit::TestCase include TestRepositoryBase def setup @@ -157,41 +148,37 @@ def teardown super end - def test_associate_distributor - distributor_config = {"relative_url" => "/123/456", "http" => true, "https" => true} - response = @resource.associate_distributor(RepositorySupport.repo_id, "yum_distributor", distributor_config, - {:distributor_id => "dist_1"}) + distributor_config = {'relative_url' => '/123/456', 'http' => true, 'https' => true} + response = @resource.associate_distributor(RepositorySupport.repo_id, 'yum_distributor', distributor_config, + :distributor_id => 'dist_1') assert_equal 201, response.code - assert_equal "yum_distributor", response['distributor_type_id'] + assert_equal 'yum_distributor', response['distributor_type_id'] end def test_delete_distributor - distributor_config = {"relative_url" => "/123/456", "http" => true, "https" => true} - @resource.associate_distributor(RepositorySupport.repo_id, "yum_distributor", - distributor_config, {:distributor_id => "dist_1"}) + distributor_config = {'relative_url' => '/123/456', 'http' => true, 'https' => true} + @resource.associate_distributor(RepositorySupport.repo_id, 'yum_distributor', + distributor_config, :distributor_id => 'dist_1') - response = @resource.delete_distributor(RepositorySupport.repo_id, "dist_1") + response = @resource.delete_distributor(RepositorySupport.repo_id, 'dist_1') @support.wait_on_response(response) assert_equal 202, response.code end def test_update_distributor - distributor_config = {"relative_url" => "/123/456", "http" => true, "https" => true} - distributor = @resource.associate_distributor(RepositorySupport.repo_id, "yum_distributor", - distributor_config, {:distributor_id => "dist_1"}) + distributor_config = {'relative_url' => '/123/456', 'http' => true, 'https' => true} + distributor = @resource.associate_distributor(RepositorySupport.repo_id, 'yum_distributor', + distributor_config, :distributor_id => 'dist_1') response = @resource.update_distributor(RepositorySupport.repo_id, distributor['id'], - {:relative_url=>"/new_path/"}) + :relative_url => '/new_path/') assert_equal 202, response.code end - end - - class TestRepositoryImporter < MiniTest::Unit::TestCase include TestRepositoryBase @@ -207,30 +194,29 @@ def teardown end def test_associate_importer - response = @resource.associate_importer(RepositorySupport.repo_id, "yum_importer", {}) + response = @resource.associate_importer(RepositorySupport.repo_id, 'yum_importer', {}) assert_async_response(response) - repo = @resource.retrieve(RepositorySupport.repo_id, {:details => true}) - assert_equal "yum_importer", repo['importers'].first['id'] + repo = @resource.retrieve(RepositorySupport.repo_id, :details => true) + assert_equal 'yum_importer', repo['importers'].first['id'] end def test_delete_importer - @resource.associate_importer(RepositorySupport.repo_id, "yum_importer", {}) - response = @resource.delete_importer(RepositorySupport.repo_id, "yum_importer") + @resource.associate_importer(RepositorySupport.repo_id, 'yum_importer', {}) + response = @resource.delete_importer(RepositorySupport.repo_id, 'yum_importer') assert_async_response(response) end def test_update_importer - @resource.associate_importer(RepositorySupport.repo_id, "yum_importer", {}) - response = @resource.update_importer(RepositorySupport.repo_id, "yum_importer", - {:feed=>"http://katello.org/repo/"}) + @resource.associate_importer(RepositorySupport.repo_id, 'yum_importer', {}) + response = @resource.update_importer(RepositorySupport.repo_id, 'yum_importer', + :feed => 'http://katello.org/repo/') assert_async_response(response) end end - class TestRepositorySync < MiniTest::Unit::TestCase include TestRepositoryBase @@ -249,7 +235,7 @@ def test_sync response = @resource.sync(RepositorySupport.repo_id) tasks = assert_async_response(response) - assert_includes tasks.first["tags"], 'pulp:action:sync' + assert_includes tasks.first['tags'], 'pulp:action:sync' end def test_sync_repo_with_yum_importer @@ -257,11 +243,10 @@ def test_sync_repo_with_yum_importer response = @resource.sync(RepositorySupport.repo_id) tasks = assert_async_response(response) - assert_includes tasks.first["tags"], 'pulp:action:sync' + assert_includes tasks.first['tags'], 'pulp:action:sync' end end - class TestRepositoryRequiresSync < MiniTest::Unit::TestCase include TestRepositoryBase @@ -280,7 +265,7 @@ def test_publish response = @resource.publish(RepositorySupport.repo_id, @support.distributor['id']) tasks = assert_async_response(response) - assert_includes tasks.first["tags"], 'pulp:action:publish' + assert_includes tasks.first['tags'], 'pulp:action:publish' end def test_unassociate_units @@ -299,21 +284,19 @@ def test_unit_search def test_sync_history response = @resource.sync_history(RepositorySupport.repo_id) - assert 200, response.code - refute_empty response + assert 200, response.code + refute_empty response end - end - class TestRepositoryClone < MiniTest::Unit::TestCase include TestRepositoryBase def setup super - @clone_name = RepositorySupport.repo_id + "_clone" + @clone_name = RepositorySupport.repo_id + '_clone' @support.create_and_sync_repo(:importer => true) - @extension.create_with_importer(@clone_name, :id => "yum_importer") + @extension.create_with_importer(@clone_name, :id => 'yum_importer') end def teardown @@ -329,6 +312,5 @@ def test_unit_copy assert_includes tasks.first['tags'], 'pulp:action:associate' end - end -end \ No newline at end of file +end diff --git a/test/resources/role_test.rb b/test/resources/role_test.rb index 71ae36f2..0bb07a96 100644 --- a/test/resources/role_test.rb +++ b/test/resources/role_test.rb @@ -28,11 +28,10 @@ require './lib/runcible/resources/role' module Resources - class TestRoles < MiniTest::Unit::TestCase def setup - @username = "integration_test_user" - @role_name = "super-users" + @username = 'integration_test_user' + @role_name = 'super-users' @resource = TestRuncible.server.resources.role TestRuncible.server.resources.user.create(@username) @@ -45,7 +44,7 @@ def teardown def test_path_without_role_name path = @resource.class.path - assert_match "roles/", path + assert_match 'roles/', path end def test_path_with_role_name @@ -67,6 +66,5 @@ def test_remove assert_equal 200, response.code end - end -end \ No newline at end of file +end diff --git a/test/resources/task_test.rb b/test/resources/task_test.rb index 7a5c3dd7..ff135063 100644 --- a/test/resources/task_test.rb +++ b/test/resources/task_test.rb @@ -29,21 +29,18 @@ module Resources module TestTaskBase - def setup @resource = TestRuncible.server.resources.task end - end - class TestTask < MiniTest::Unit::TestCase include TestTaskBase def self.before_suite self.support = RepositorySupport.new self.support.create_repo(:importer => true) - @@task_id = self.support.sync_repo["spawned_tasks"].first["task_id"] + @@task_id = self.support.sync_repo['spawned_tasks'].first['task_id'] end def self.after_suite @@ -53,7 +50,7 @@ def self.after_suite def test_path path = @resource.class.path - assert_match "tasks/", path + assert_match 'tasks/', path end def test_path_with_task_id @@ -77,7 +74,7 @@ def test_list end def test_cancel - skip "TODO: Needs more reliable testable scenario" + skip 'TODO: Needs more reliable testable scenario' response = @resource.cancel(@@task_id) assert_equal 200, response.code @@ -87,8 +84,7 @@ def test_poll_all tasks = @resource.poll_all([@@task_id]) refute_empty tasks - refute_empty tasks.select{ |task| task['task_id'] == @@task_id } + refute_empty tasks.select { |task| task['task_id'] == @@task_id } end - end -end \ No newline at end of file +end diff --git a/test/resources/user_test.rb b/test/resources/user_test.rb index 015d46f6..6dcf224f 100644 --- a/test/resources/user_test.rb +++ b/test/resources/user_test.rb @@ -27,7 +27,7 @@ module Resources module TestUserBase def setup - @username = "integration_test_user" + @username = 'integration_test_user' @resource = TestRuncible.server.resources.user end end @@ -49,15 +49,13 @@ def test_create end def test_create_with_name_and_password - response = @resource.create(@username, {:name => @username, :password => "integration_test_password"}) + response = @resource.create(@username, :name => @username, :password => 'integration_test_password') assert_equal 201, response.code assert_equal @username, response['name'] end - end - class TestUser < MiniTest::Unit::TestCase include TestUserBase @@ -80,7 +78,7 @@ def teardown def test_path path = @resource.class.path - assert_match "users/", path + assert_match 'users/', path end def test_path_with_username @@ -93,11 +91,11 @@ def test_retrieve response = @resource.retrieve(@username) assert_equal 200, response.code - assert_equal @username, response["login"] + assert_equal @username, response['login'] end def test_retrieve_all - response = @resource.retrieve_all() + response = @resource.retrieve_all assert_equal 200, response.code refute_empty response @@ -108,6 +106,5 @@ def test_delete assert_equal 200, response.code end - end -end \ No newline at end of file +end diff --git a/test/support/consumer_group_support.rb b/test/support/consumer_group_support.rb index 7674898f..4018ffc8 100644 --- a/test/support/consumer_group_support.rb +++ b/test/support/consumer_group_support.rb @@ -25,29 +25,26 @@ require './lib/runcible/resources/consumer_group' require './lib/runcible/extensions/consumer_group' - class ConsumerGroupSupport - def initialize @consumer_group_resource = TestRuncible.server.extensions.consumer_group end def self.consumer_group_id - "integration_test_consumer_group_support" + 'integration_test_consumer_group_support' end def create_consumer_group destroy_consumer_group consumer_group = @consumer_group_resource.create(self.class.consumer_group_id) return consumer_group - rescue Exception => e + rescue => e raise e unless e.class == RestClient::ResourceNotFound end def destroy_consumer_group @consumer_group_resource.delete(self.class.consumer_group_id) - rescue Exception => e + rescue => e raise e unless e.class == RestClient::ResourceNotFound end - end diff --git a/test/support/consumer_support.rb b/test/support/consumer_support.rb index 5cb808e5..af9e4d86 100644 --- a/test/support/consumer_support.rb +++ b/test/support/consumer_support.rb @@ -26,21 +26,20 @@ require './lib/runcible/extensions/consumer' class ConsumerSupport - def initialize @consumer_resource = TestRuncible.server.resources.consumer end def self.consumer_id - "integration_test_consumer_support" + 'integration_test_consumer_support' end - def create_consumer(package_profile=false) + def create_consumer(package_profile = false) destroy_consumer consumer = @consumer_resource.create(self.class.consumer_id) if package_profile - @consumer_resource.upload_profile(self.class.consumer_id, 'rpm', [{"name" => "elephant", "version" => "0.2", "release" => "0.7", - "epoch" => 0, "arch" => "noarch", "vendor" => "Fedora"}]) + @consumer_resource.upload_profile(self.class.consumer_id, 'rpm', [{'name' => 'elephant', 'version' => '0.2', 'release' => '0.7', + 'epoch' => 0, 'arch' => 'noarch', 'vendor' => 'Fedora'}]) end return consumer rescue => e @@ -49,8 +48,7 @@ def create_consumer(package_profile=false) def destroy_consumer @consumer_resource.delete(self.class.consumer_id) - rescue Exception => e + rescue => e raise e unless e.class == RestClient::ResourceNotFound end - end diff --git a/test/support/logger_support.rb b/test/support/logger_support.rb index f372f7b6..bd298d4c 100644 --- a/test/support/logger_support.rb +++ b/test/support/logger_support.rb @@ -21,11 +21,8 @@ # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - module Runcible - class Logger - attr_accessor :message def debug(message) @@ -35,8 +32,5 @@ def debug(message) def error(message) @message = message end - end - end - diff --git a/test/support/repository_support.rb b/test/support/repository_support.rb index 5d0be4a1..ab09f064 100644 --- a/test/support/repository_support.rb +++ b/test/support/repository_support.rb @@ -26,11 +26,10 @@ require './lib/runcible' class RepositorySupport - - @@repo_id = "integration_test_id" + @@repo_id = 'integration_test_id' @@repo_name = @@repo_id - def initialize(type = "yum") + def initialize(type = 'yum') @repo_resource = TestRuncible.server.extensions.repository @schedule_resource = TestRuncible.server.resources.repository_schedule @repo_extension = TestRuncible.server.extensions.repository @@ -39,12 +38,12 @@ def initialize(type = "yum") @repo_type = type @importer_type = "#{@repo_type}_importer" - if @repo_type == "yum" - @distributors = [Runcible::Models::YumDistributor.new('/path', true, true, :id => "puppet_dist")] - @repo_url = "file://#{File.expand_path(File.dirname(__FILE__))}".gsub("support", "fixtures/repositories/zoo5") - elsif @repo_type == "puppet" - @distributors = [Runcible::Models::PuppetDistributor.new('/path', true, true, :id => "yum_dist")] - @repo_url = "http://davidd.fedorapeople.org/repos/random_puppet/" + if @repo_type == 'yum' + @distributors = [Runcible::Models::YumDistributor.new('/path', true, true, :id => 'puppet_dist')] + @repo_url = "file://#{File.expand_path(File.dirname(__FILE__))}".gsub('support', 'fixtures/repositories/zoo5') + elsif @repo_type == 'puppet' + @distributors = [Runcible::Models::PuppetDistributor.new('/path', true, true, :id => 'yum_dist')] + @repo_url = 'http://davidd.fedorapeople.org/repos/random_puppet/' end end @@ -64,45 +63,34 @@ def self.repo_url @@repo_url end - def schedule_time - @schedule_time - end - - def task_resource - @task_resource - end + attr_reader :schedule_time - def repo_resource - @repo_resource - end + attr_reader :task_resource - def task=(task) - @task = task - end + attr_reader :repo_resource - def task - @task - end + attr_writer :task + attr_reader :task - def create_and_sync_repo(options={}) + def create_and_sync_repo(options = {}) destroy_repo create_repo(options) sync_repo(options) end - def create_repo(options={}) + def create_repo(options = {}) repo = @repo_resource.retrieve(RepositorySupport.repo_id) - if !repo.nil? + unless repo.nil? destroy_repo end if options[:importer] - repo = @repo_extension.create_with_importer(RepositorySupport.repo_id, {:id=>@importer_type, :feed => @repo_url}) + repo = @repo_extension.create_with_importer(RepositorySupport.repo_id, :id => @importer_type, :feed => @repo_url) elsif options[:importer_and_distributor] repo = @repo_extension.create_with_importer_and_distributors(RepositorySupport.repo_id, - {:id=>@importer_type, :feed => @repo_url}, @distributors) + {:id => @importer_type, :feed => @repo_url}, @distributors) else repo = @repo_resource.create(RepositorySupport.repo_id) end @@ -110,10 +98,10 @@ def create_repo(options={}) rescue RestClient::ResourceNotFound if options[:importer] - repo = @repo_extension.create_with_importer(RepositorySupport.repo_id, {:id=>@importer_type, :feed => @repo_url}) + repo = @repo_extension.create_with_importer(RepositorySupport.repo_id, :id => @importer_type, :feed => @repo_url) elsif options[:importer_and_distributor] repo = @repo_extension.create_with_importer_and_distributors(RepositorySupport.repo_id, - {:id=>@importer_type, :feed => @repo_url}, @distributors) + {:id => @importer_type, :feed => @repo_url}, @distributors) else repo = @repo_resource.create(RepositorySupport.repo_id) end @@ -121,10 +109,10 @@ def create_repo(options={}) return repo end - def sync_repo(options={}) + def sync_repo(options = {}) task = @repo_resource.sync(RepositorySupport.repo_id) - if !options[:wait] + unless options[:wait] self.wait_on_response(task) end @@ -132,7 +120,7 @@ def sync_repo(options={}) end def wait_on_response(response) - wait_on_tasks(response["spawned_tasks"].map{|task_ref| {"task_id"=> task_ref["task_id"]}}) + wait_on_tasks(response['spawned_tasks'].map { |task_ref| {'task_id' => task_ref['task_id']} }) end def wait_on_tasks(tasks) @@ -141,10 +129,10 @@ def wait_on_tasks(tasks) end end - def wait_on_task task - while !(['finished', 'error', 'timed_out', 'canceled', 'reset'].include?(task['state'])) do + def wait_on_task(task) + until (['finished', 'error', 'timed_out', 'canceled', 'reset'].include?(task['state'])) self.sleep_if_needed - task = @task_resource.poll(task["task_id"]) + task = @task_resource.poll(task['task_id']) end task end @@ -160,7 +148,7 @@ def create_schedule schedule['_id'] end - def destroy_repo(id=RepositorySupport.repo_id) + def destroy_repo(id = RepositorySupport.repo_id) if @task wait_on_response(@task) @task = nil @@ -168,11 +156,10 @@ def destroy_repo(id=RepositorySupport.repo_id) tasks = @repo_resource.delete(id) wait_on_response(tasks) - rescue Exception => e + rescue => e end def rpm_ids @repo_extension.rpm_ids(RepositorySupport.repo_id) end - end diff --git a/test/test_runner.rb b/test/test_runner.rb index ca412492..17a0fa5c 100644 --- a/test/test_runner.rb +++ b/test/test_runner.rb @@ -33,7 +33,7 @@ begin require 'debugger' rescue LoadError - puts "Debugging not enabled." + puts 'Debugging not enabled.' end class TestRuncible @@ -47,19 +47,18 @@ def self.server end class MiniTest::Unit::TestCase - def cassette_name - test_name = self.__name__.gsub("test_", "") - parent = (self.class.name.split("::")[-2] || "").underscore - self_class = self.class.name.split("::")[-1].underscore.gsub("test_", "") + test_name = self.__name__.gsub('test_', '') + parent = (self.class.name.split('::')[-2] || '').underscore + self_class = self.class.name.split('::')[-1].underscore.gsub('test_', '') "#{parent}/#{self_class}/#{test_name}" end def run_with_vcr(args) - VCR.insert_cassette(cassette_name) - to_ret = run_without_vcr(args) - VCR.eject_cassette - to_ret + VCR.insert_cassette(cassette_name) + to_ret = run_without_vcr(args) + VCR.eject_cassette + to_ret end alias_method_chain :run, :vcr @@ -68,28 +67,26 @@ class << self attr_accessor :support def suite_cassette_name - parent = (self.name.split("::")[-2] || "").underscore - self_class = self.name.split("::")[-1].underscore.gsub("test_", "") + parent = (self.name.split('::')[-2] || '').underscore + self_class = self.name.split('::')[-1].underscore.gsub('test_', '') "#{parent}/#{self_class}/suite" end end def assert_async_response(response) support = @support || self.class.support - fail "@support or @@supsport not defined" unless support + fail '@support or @@supsport not defined' unless support assert_equal 202, response.code tasks = support.wait_on_response(response) tasks.each do |task| - assert task["state"], "finished" + assert task['state'], 'finished' end end - end class CustomMiniTestRunner class Unit < MiniTest::Unit - def before_suites # code to run before the first test end @@ -99,96 +96,87 @@ def after_suites end def _run_suites(suites, type) - begin - if ENV['suite'] - suites = suites.select do |suite| - suite.name == ENV['suite'] - end - end - - before_suites - super(suites, type) - ensure - after_suites + if ENV['suite'] + suites = suites.select do |suite| + suite.name == ENV['suite'] + end end + before_suites + super(suites, type) + ensure + after_suites end def _run_suite(suite, type) - begin - if logging? - puts "Running Suite #{suite.inspect} - #{type.inspect} " - end - - if suite.respond_to?(:before_suite) - VCR.use_cassette(suite.suite_cassette_name) do - suite.before_suite - end - end - super(suite, type) - ensure - if suite.respond_to?(:after_suite) - VCR.use_cassette(suite.suite_cassette_name) do - suite.after_suite - end - end - - if logging? - puts "Completed Running Suite #{suite.inspect} - #{type.inspect} " + if logging? + puts "Running Suite #{suite.inspect} - #{type.inspect} " + end + if suite.respond_to?(:before_suite) + VCR.use_cassette(suite.suite_cassette_name) do + suite.before_suite + end + end + super(suite, type) + ensure + if suite.respond_to?(:after_suite) + VCR.use_cassette(suite.suite_cassette_name) do + suite.after_suite end end + if logging? + puts "Completed Running Suite #{suite.inspect} - #{type.inspect} " + end end def logging? ENV['logging'] end - end end class PulpMiniTestRunner - - def run_tests(suite, options={}) - mode = options[:mode] || "none" + def run_tests(suite, options = {}) + mode = options[:mode] || 'none' test_name = options[:test_name] || nil - auth_type = options[:auth_type] || "http" + auth_type = options[:auth_type] || 'http' logging = options[:logging] || false MiniTest::Unit.runner = CustomMiniTestRunner::Unit.new - if mode == "all" - set_runcible_config({ :auth_type => auth_type, :logging => logging }) + if mode == 'all' + set_runcible_config(:auth_type => auth_type, :logging => logging) else - set_runcible_config({ :logging => logging }) + set_runcible_config(:logging => logging) end set_vcr_config(mode) - if test_name && File.exists?(test_name) + if test_name && File.exist?(test_name) require test_name elsif test_name require "./test/#{test_name}_test.rb" else - Dir["./test/#{suite}/*_test.rb"].each {|file| require file } + Dir["./test/#{suite}/*_test.rb"].each { |file| require file } end end def set_runcible_config(options) config = { - :api_path => "/pulp/api/v2/", + :api_path => '/pulp/api/v2/', :http_auth => {} } - if options[:logging] == "true" + if options[:logging] == 'true' log = ::Logger.new(STDOUT) log.level = Logger::DEBUG config[:logging] = { :logger => log, :debug => true, - :stdout => true + :stdout => true } end - if options[:auth_type] == "http" + if options[:auth_type] == 'http' File.open('/etc/pulp/server.conf') do |f| f.each_line do |line| @@ -197,40 +185,40 @@ def set_runcible_config(options) elsif line.start_with?('default_login') config[:user] = line.split(':')[1].strip elsif line.start_with?('server_name') - config[:url] = "https://#{line.split(':')[1].chomp.strip}" + config[:url] = "https://#{line.split(':')[1].chomp.strip}" end end end - elsif options[:auth_type] == "oauth" + elsif options[:auth_type] == 'oauth' File.open('/etc/pulp/server.conf') do |f| f.each_line do |line| if line.start_with?('oauth_secret') config[:oauth][:oauth_secret] = line.split(':')[1].strip elsif line.start_with?('oauth_key') - config[:oauth][:oauth_key] = line.split(':')[1].strip + config[:oauth][:oauth_key] = line.split(':')[1].strip elsif line.start_with?('default_login') - config[:user] = line.split(':')[1].strip + config[:user] = line.split(':')[1].strip elsif line.start_with?('server_name') - config[:url] = "https://#{line.split(':')[1].chomp.strip}" + config[:url] = "https://#{line.split(':')[1].chomp.strip}" end end end else config[:http_auth][:password] = 'admin' config[:user] = 'admin' - config[:url] = "https://localhost" + config[:url] = 'https://localhost' end TestRuncible.server = Runcible::Instance.new(config) end def set_vcr_config(mode) - if mode == "all" + if mode == 'all' configure_vcr(:all) - elsif mode == "new_episodes" + elsif mode == 'new_episodes' configure_vcr(:new_episodes) - elsif mode == "once" + elsif mode == 'once' configure_vcr(:once) else configure_vcr(:none) diff --git a/test/unit/base_test.rb b/test/unit/base_test.rb index 1c1ba475..83aaa7ad 100644 --- a/test/unit/base_test.rb +++ b/test/unit/base_test.rb @@ -29,13 +29,12 @@ module Base class TestBase < MiniTest::Unit::TestCase - def setup @logger = ::Runcible::Logger.new @my_runcible = Runcible::Base.new ({ - :base_url => "http://localhost/", - :user => "test_user", - :password => "test_password", + :base_url => 'http://localhost/', + :user => 'test_user', + :password => 'test_password', :headers => { :content_type => 'application/json', :accept => 'application/json' }, :logging => { :logger => @logger } @@ -50,18 +49,18 @@ def test_config end def test_process_response_returns_hash - json = { :a => "test", :b => "data" }.to_json + json = { :a => 'test', :b => 'data' }.to_json response = OpenStruct.new(:body => json) data = @my_runcible.process_response(response) - assert_equal "test", data.body["a"] + assert_equal 'test', data.body['a'] end def test_process_response_returns_string - response = OpenStruct.new(:body => "true") + response = OpenStruct.new(:body => 'true') data = @my_runcible.process_response(response) - assert_equal "true", data.body + assert_equal 'true', data.body end def test_verbose_logger @@ -79,22 +78,21 @@ def test_exception_logger end def test_generate_payload - options = {:payload => "abc123"} - assert_equal "abc123", @my_runcible.generate_payload(options) + options = {:payload => 'abc123'} + assert_equal 'abc123', @my_runcible.generate_payload(options) - payload = {:required => {:a => "1", - :b => "2" + payload = {:required => {:a => '1', + :b => '2' }, - :optional => {:c => "3" + :optional => {:c => '3' } } - result = {:a => "1", - :b => "2", - :c => "3" + result = {:a => '1', + :b => '2', + :c => '3' } assert_equal result.to_json, @my_runcible.generate_payload(:payload => payload) end - end -end \ No newline at end of file +end diff --git a/test/vcr_setup.rb b/test/vcr_setup.rb index fd4671db..e4808f74 100644 --- a/test/vcr_setup.rb +++ b/test/vcr_setup.rb @@ -24,18 +24,16 @@ require 'rubygems' require 'vcr' - -def configure_vcr(mode=:none) - - if ENV['record'] == "false" && mode == :none - raise "Record flag is not applicable for mode 'none', please use with 'mode=all'" +def configure_vcr(mode = :none) + if ENV['record'] == 'false' && mode == :none + fail "Record flag is not applicable for mode 'none', please use with 'mode=all'" end VCR.configure do |c| c.cassette_library_dir = 'test/fixtures/vcr_cassettes' c.hook_into :webmock - if ENV['record'] == "false" && mode != :none + if ENV['record'] == 'false' && mode != :none uri = URI.parse(Runcible::Base.config[:url]) c.ignore_hosts uri.host end