Project

General

Profile

Revision ee942928

Added by Thomas McKay about 9 years ago

akeys - activation keys and other stuff

View differences:

hammer_cli_csv.gemspec
5 5
Gem::Specification.new do |spec|
6 6
  spec.name = "hammer_cli_csv"
7 7
  spec.version = HammerCLICsv.version
8
  spec.authors = ["Adam Price"]
9
  spec.email = ["komidore64@gmail.com"]
8
  spec.authors = ["@thomasmckay"]
9
  spec.email = ["thomasmckay@redhat.com"]
10 10

  
11 11
  spec.platform = Gem::Platform::RUBY
12 12
  spec.summary = "Csv commands for Hammer"
......
17 17

  
18 18
  spec.add_dependency("hammer_cli", ">= 0.0.6")
19 19
  spec.add_dependency("katello_api")
20
  #spec.add_development_dependency("rake")
21
  #spec.add_development_dependency("thor")
22
  #spec.add_development_dependency("minitest", "4.7.4")
23
  #spec.add_development_dependency("minitest-spec-context")
24
  #spec.add_development_dependency("mocha")
25
  #spec.add_development_dependency("ci_reporter")
26
  #spec.add_development_dependency("simplecov")
27
  #spec.add_development_dependency("debugger")
28 20
end
lib/hammer_cli_csv.rb
14 14
  require 'hammer_cli_csv/roles'
15 15
  require 'hammer_cli_csv/permissions'
16 16
  require 'hammer_cli_csv/system_groups'
17
  require 'hammer_cli_csv/activation_keys'
17 18

  
18 19
end
lib/hammer_cli_csv/activation_keys.rb
1
# Copyright (c) 2013 Red Hat
2
#
3
# MIT License
4
#
5
# Permission is hereby granted, free of charge, to any person obtaining
6
# a copy of this software and associated documentation files (the
7
# "Software"), to deal in the Software without restriction, including
8
# without limitation the rights to use, copy, modify, merge, publish,
9
# distribute, sublicense, and/or sell copies of the Software, and to
10
# permit persons to whom the Software is furnished to do so, subject to
11
# the following conditions:
12
#
13
# The above copyright notice and this permission notice shall be
14
# included in all copies or substantial portions of the Software.
15
#
16
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23
#
24
#
25
# -= Activation Key CSV =-
26
#
27
# Columns
28
#   Name
29
#     - Activation key name
30
#     - May contain '%d' which will be replaced with current iteration number of Count
31
#     - eg. "group%d" -> "group1"
32
#   Count
33
#     - Number of times to iterate on this line of the CSV file
34
#   Org Label
35
#   Limit
36
#   Description
37
#
38

  
39
require 'hammer_cli'
40
require 'katello_api'
41
require 'json'
42
require 'csv'
43

  
44
module HammerCLICsv
45
  class ActivationKeysCommand < BaseCommand
46

  
47
    def initialize(*args)
48
      super(args)
49
      @activationkey_api = KatelloApi::Resources::ActivationKey.new(@init_options)
50
      @organization_api = KatelloApi::Resources::Organization.new(@init_options)
51
      @environment_api = KatelloApi::Resources::Environment.new(@init_options)
52
      @contentview_api = KatelloApi::Resources::ContentView.new(@init_options)
53
    end
54

  
55
    def execute
56
      csv_export? ? export : import
57

  
58
      HammerCLI::EX_OK
59
    end
60

  
61
    def export
62
      CSV.open(csv_file, 'wb') do |csv|
63
        csv << ['Name', 'Count', 'Org Label', 'Description', 'Limit', 'Environment', 'Content View', 'System Groups']
64
        @organization_api.index[0].each do |organization|
65
          @activationkey_api.index({'organization_id' => organization['label']})[0].each do |activationkey|
66
            puts "Writing activation key '#{activationkey['name']}'"
67
            csv << [activationkey['name'], 1, organization['label'],
68
                    activationkey['description'],
69
                    activationkey['usage_limit'].to_i < 0 ? 'Unlimited' : sytemgroup['usage_limit']]
70
          end
71
        end
72
      end
73
    end
74

  
75
    def import
76
      @existing = {}
77

  
78
      thread_import do |line|
79
        create_activationkeys_from_csv(line)
80
      end
81
    end
82

  
83
    def create_activationkeys_from_csv(line)
84
      details = parse_activationkey_csv(line)
85

  
86
      if !@existing[details[:org_label]]
87
        @existing[details[:org_label]] = {}
88
        @activationkey_api.index({'organization_id' => details[:org_label]})[0].each do |activationkey|
89
          @existing[details[:org_label]][activationkey['name']] = activationkey['id']
90
        end
91
        @environments = {}
92
        @environments[details[:org_label]] = {}
93
        @environment_api.index({'organization_id' => details[:org_label]})[0].each do |environment|
94
          @environments[details[:org_label]][details[:environment]] = environment['id']
95
        end
96
        @contentviews = {}
97
        @contentviews[details[:org_label]] = {}
98
        @contentview_api.index({'organization_id' => details[:org_label]})[0].each do |contentview|
99
          @contentviews[details[:org_label]][details[:content_view]] = contentview['id']
100
        end
101
      end
102

  
103
      details[:count].times do |number|
104
        name = namify(details[:name_format], number)
105
        if !@existing[details[:org_label]].include? name
106
          puts "Creating activationkey '#{name}'" if verbose?
107
          @activationkey_api.create({
108
                             'environment_id' => @environments[details[:org_label]][details[:environment]],
109
                             'activation_key' => {
110
                               'name' => name,
111
                               'content_view_id' => details[:content_view],
112
                               'description' => details[:description]
113
                             }
114
                           })
115
        else
116
          puts "Updating activationkey '#{name}'" if verbose?
117
          @activationkey_api.update({
118
                             'organization_id' => details[:org_label],
119
                             'id' => @existing[details[:org_label]][name],
120
                             'activation_key' => {
121
                               'name' => name,
122
                               'description' => details[:description]
123
                             }
124
                           })
125
        end
126
      end
127
    end
128

  
129
    def parse_activationkey_csv(line)
130
      keys = [:name_format, :count, :org_label, :description, :limit, :environment, :content_view, :system_groups]
131
      details = CSV.parse(line).map { |a| Hash[keys.zip(a)] }[0]
132

  
133
      details[:count] = details[:count].to_i
134

  
135
      details
136
    end
137
  end
138

  
139
  HammerCLI::MainCommand.subcommand("csv:activationkeys", "ping the katello server", HammerCLICsv::ActivationKeysCommand)
140
end
lib/hammer_cli_csv/base.rb
35 35

  
36 36
    option ["-v", "--verbose"], :flag, "be verbose"
37 37
    option ['--threads'], 'THREAD_COUNT', 'Number of threads to hammer with', :default => 1
38
    option ['--csv-file'], 'FILE_NAME', 'CSV file to name'
38
    option ['--csv-file'], 'FILE_NAME', 'CSV file to name', :required => true
39 39
    option ['--csv-export'], :flag, 'Export current data instead of importing'
40 40

  
41 41
    def initialize(*args)
lib/hammer_cli_csv/organizations.rb
1
# Copyright (c) 2013 Red Hat
2
#
3
# MIT License
4
#
5
# Permission is hereby granted, free of charge, to any person obtaining
6
# a copy of this software and associated documentation files (the
7
# "Software"), to deal in the Software without restriction, including
8
# without limitation the rights to use, copy, modify, merge, publish,
9
# distribute, sublicense, and/or sell copies of the Software, and to
10
# permit persons to whom the Software is furnished to do so, subject to
11
# the following conditions:
12
#
13
# The above copyright notice and this permission notice shall be
14
# included in all copies or substantial portions of the Software.
15
#
16
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23
#
24
#
25
# -= Organizations CSV =-
26
#
27
# Columns
28
#   Name
29
#     - Name of the organization.
30
#     - May contain '%d' which will be replaced with current iteration number of Count
31
#     - eg. "organization%d" -> "organization1"
32
#   Count
33
#     - Number of times to iterate on this line of the CSV file
34
#   Org Label
35
#     - Label of the organization.
36
#     - May contain '%d' which will be replaced with current iteration number of Count
37
#     - eg. "organization%d" -> "organization1"
38
#   Description
39
#
40

  
41
require 'hammer_cli'
42
require 'katello_api'
43
require 'json'
44
require 'csv'
45

  
46
module HammerCLICsv
47
  class OrganizationsCommand < BaseCommand
48

  
49
    def initialize(*args)
50
      super(args)
51
      @organization_api = KatelloApi::Resources::Organization.new(@init_options)
52
    end
53

  
54
    def execute
55
      csv_export? ? export : import
56

  
57
      HammerCLI::EX_OK
58
    end
59

  
60
    def export
61
      CSV.open(csv_file, 'wb') do |csv|
62
        csv << ['Name','Count','Org Label', 'Description']
63
        @organization_api.index[0].each do |organization|
64
          csv << [organization['name'], 1, organization['label'], organization['description']]
65
        end
66
      end
67
    end
68

  
69
    def import
70
      @existing = {}
71
      @organization_api.index[0].each do |organization|
72
          @existing[organization['name']] = organization['label']
73
      end
74

  
75
      thread_import do |line|
76
        create_organizations_from_csv(line)
77
      end
78
    end
79

  
80
    def create_organizations_from_csv(line)
81
      details = parse_organization_csv(line)
82

  
83
      details[:count].times do |number|
84
        name = namify(details[:name_format], number)
85
        label = namify(details[:label_format], number)
86
        if !@existing.include? name
87
          puts "Creating organization '#{name}'" if verbose?
88
          @organization_api.create({
89
                             :organization => {
90
                               :name => name,
91
                               :label => label,
92
                               :description => details[:description]
93
                             }
94
                           }, HEADERS)
95
        else
96
          puts "Updating organization '#{name}'" if verbose?
97
          @organization_api.update({
98
                             'id' => label,
99
                             :organization => {
100
                               :name => name,
101
                               :description => details[:description]
102
                             }
103
                           }, HEADERS)
104
        end
105
      end
106
    end
107

  
108
    def parse_organization_csv(line)
109
      keys = [:name_format, :count, :label_format, :description]
110
      details = CSV.parse(line).map { |a| Hash[keys.zip(a)] }[0]
111

  
112
      details[:count] = details[:count].to_i
113

  
114
      details
115
    end
116
  end
117

  
118
  HammerCLI::MainCommand.subcommand("csv:organizations", "ping the katello server", HammerCLICsv::OrganizationsCommand)
119
end
lib/hammer_cli_csv/system_groups.rb
48 48
      super(args)
49 49
      @organization_api = KatelloApi::Resources::Organization.new(@init_options)
50 50
      @systemgroup_api = KatelloApi::Resources::SystemGroup.new(@init_options)
51
      @permission_api = KatelloApi::Resources::Permission.new(@init_options)
52 51
    end
53 52

  
54 53
    def execute
......
82 81
    def create_systemgroups_from_csv(line)
83 82
      details = parse_systemgroup_csv(line)
84 83

  
85
      @existing[details[:org_label]] ||= {}
86
      @systemgroup_api.index({'organization_id' => details[:org_label]})[0].each do |systemgroup|
84
      if !@existing[details[:org_label]]
85
        @existing[details[:org_label]] = {}
86
        @systemgroup_api.index({'organization_id' => details[:org_label]})[0].each do |systemgroup|
87 87
          @existing[details[:org_label]][systemgroup['name']] = systemgroup['id']
88
        end
88 89
      end
89 90

  
90 91
      details[:count].times do |number|
test/activation_keys_test.rb
1
require File.join(File.dirname(__FILE__), 'csv_test_helper')
2
require File.join(File.dirname(__FILE__), 'apipie_resource_mock')
3

  
4

  
5
describe HammerCLICsv::ActivationKeysCommand do
6

  
7
  extend CommandTestHelper
8

  
9
  before :each do
10
    @activationkey_api = ApipieResourceMock.new(KatelloApi::Resources::ActivationKey)
11
    @organization_api = ApipieResourceMock.new(KatelloApi::Resources::Organization)
12
    @environment_api = ApipieResourceMock.new(KatelloApi::Resources::Environment)
13
    @contentview_api = ApipieResourceMock.new(KatelloApi::Resources::ContentView)
14
  end
15

  
16
  context "ActivationKeysCommand" do
17

  
18
    let(:cmd) { HammerCLICsv::ActivationKeysCommand.new("", ctx) }
19

  
20
    context "parameters" do
21
      it "blah" do
22
        cmd.stubs(:get_lines).returns([
23
                                       "Name,Count,Org Label,Description,Limit,Environment,Content View,System Groups",
24
                                       "'akey',1,'org','some description','Unlimited','Library','Default_Content_view',"
25
                                      ])
26
        cmd.run(['--csv-file=some_file', '--threads=1']).must_equal HammerCLI::EX_OK
27
      end
28
    end
29
  end
30
end
test/apipie_resource_mock.rb
1
class ApipieResourceMock
2

  
3
  def initialize(resource)
4
    @return_values = {}
5
    @resource = resource
6
    @resource.doc["methods"].each do |method|
7
      stub_method(method)
8
    end
9
  end
10

  
11
  def doc
12
    @resource.doc
13
  end
14

  
15
  def new(attrs)
16
    return self
17
  end
18

  
19
  def expects_with(method_name, params)
20
    self.expects(method_name).with(params).returns(return_value_for(method_name))
21
  end
22

  
23
  private
24

  
25
  def return_value_for(method_name)
26
    @return_values[method_name.to_s]
27
  end
28

  
29
  def stub_method(method)
30
    value = get_return_value(method)
31
    self.stubs(method["name"]).returns(value)
32
    @return_values[method["name"].to_s] = value
33
  end
34

  
35
  def get_return_value(method)
36
    return [nil, nil] if method["examples"].empty?
37

  
38
    #parse actual json from the example string
39
    #examples are in format:
40
    # METHOD /api/some/route
41
    # <input params in json, multiline>
42
    # RETURN_CODE
43
    # <output in json, multiline>
44
    parse_re = /.*(\n\d+\n)(.*)/m
45
    json_string = method["examples"][0][parse_re, 2]
46
    response = JSON.parse(json_string) rescue json_string
47

  
48
    [response, nil]
49
  end
50

  
51
end
52

  
53

  
54
class ApipieDisabledResourceMock
55

  
56
  def initialize(resource)
57
    @resource = resource
58
    @resource.doc["methods"].each do |method|
59
      self.stubs(method["name"]).raises(RestClient::ResourceNotFound)
60
    end
61
  end
62

  
63
  def doc
64
    @resource.doc
65
  end
66

  
67
  def new(attrs)
68
    return self
69
  end
70

  
71
end
72

  
73
def mock_resource_method(method, response)
74
  resource_mock = ApipieResourceMock.new(cmd.class.resource.resource_class)
75
  resource_mock.stubs(method).returns(response)
76
  cmd.class.resource resource_mock
77
end
test/csv_test_helper.rb
1
require 'simplecov'
2
require 'pathname'
3

  
4
SimpleCov.use_merging true
5
SimpleCov.start do
6
  command_name 'MiniTest'
7
  add_filter 'test'
8
end
9
SimpleCov.root Pathname.new(File.dirname(__FILE__) + "../../../")
10

  
11

  
12
require 'minitest/autorun'
13
require 'minitest/spec'
14
require "minitest-spec-context"
15
require "mocha/setup"
16

  
17
require 'hammer_cli_csv'
18

  
19
def ctx 
20
  { :adapter => :silent }
21
end
22

  
23

  
24
#require File.join(File.dirname(__FILE__), 'test_output_adapter')
25
require File.join(File.dirname(__FILE__), 'apipie_resource_mock')
26
require File.join(File.dirname(__FILE__), 'helpers/command')
27
require File.join(File.dirname(__FILE__), 'helpers/resource_disabled')
test/data/activation-keys.csv
1
Name,Count,Org Label,Description,Limit,Environment,Content View,System Groups
2
damon.dials@megacorp.org,1,megacorp,"Individual account",1,Library,Default_Organization_View,"Employee"
3
jenee.jahns@megacorp.org,1,megacorp,"Individual account",1,Library,Default_Organization_View,"Employee"
4
gilbert.guerriero@megacorp.org,1,megacorp,"Individual account",1,Library,Default_Organization_View,"Employee"
5
quiana.quesnel@megacorp.org,1,megacorp,"Individual account",1,Library,Default_Organization_View,"Employee"
6
bernard.bigler@megacorp.org,1,megacorp,"Individual account",1,Library,Default_Organization_View,"Employee"
7
marietta.menzel@megacorp.org,1,megacorp,"Individual account",1,Library,Default_Organization_View,"Employee"
8
ruby.rieser@megacorp.org,1,megacorp,"Individual account",1,Library,Default_Organization_View,"Employee"
9
leonor.limberg@megacorp.org,1,megacorp,"Individual account",1,Library,Default_Organization_View,"Employee"
10
herminia.hochmuth@megacorp.org,1,megacorp,"Individual account",1,Library,Default_Organization_View,"Employee"
11
luana.larson@megacorp.org,1,megacorp,"Individual account",1,Library,Default_Organization_View,"Employee"
12
gilda.gutirrez@megacorp.org,1,megacorp,"Individual account",1,Library,Default_Organization_View,"Employee"
13
karlene.kirch@megacorp.org,1,megacorp,"Individual account",1,Library,Default_Organization_View,"Employee"
14
chelsea.calaway@megacorp.org,1,megacorp,"Individual account",1,Library,Default_Organization_View,"Employee"
15
tajuana.thies@megacorp.org,1,megacorp,"Individual account",1,Library,Default_Organization_View,"Employee"
16
dominica.dubberly@megacorp.org,1,megacorp,"Individual account",1,Library,Default_Organization_View,"Employee"
17
gregg.gault@megacorp.org,1,megacorp,"Individual account",1,Library,Default_Organization_View,"Employee"
18
boyd.buckle@megacorp.org,1,megacorp,"Individual account",1,Library,Default_Organization_View,"Employee"
19
georgeanna.griffiths@megacorp.org,1,megacorp,"Individual account",1,Library,Default_Organization_View,"Employee"
20
julio.jerabek@megacorp.org,1,megacorp,"Individual account",1,Library,Default_Organization_View,"Employee"
21
chaya.cordova@megacorp.org,1,megacorp,"Individual account",1,Library,Default_Organization_View,"Employee"
22
reinaldo.reardon@megacorp.org,1,megacorp,"Individual account",1,Library,Default_Organization_View,"Employee"
23
nancie.nassar@megacorp.org,1,megacorp,"Individual account",1,Library,Default_Organization_View,"Employee"
24
ayako.alday@megacorp.org,1,megacorp,"Individual account",1,Library,Default_Organization_View,"Employee"
25
skye.strobl@megacorp.org,1,megacorp,"Individual account",1,Library,Default_Organization_View,"Employee"
26
merle.miceli@megacorp.org,1,megacorp,"Individual account",1,Library,Default_Organization_View,"Employee"
27
sung.skipper@megacorp.org,1,megacorp,"Individual account",1,Library,Default_Organization_View,"Employee"
28
danilo.dilbeck@megacorp.org,1,megacorp,"Individual account",1,Library,Default_Organization_View,"Employee"
29
marylee.millsap@megacorp.org,1,megacorp,"Individual account",1,Library,Default_Organization_View,"Employee"
30
rolf.rueb@megacorp.org,1,megacorp,"Individual account",1,Library,Default_Organization_View,"Employee"
31
miriam.messenger@megacorp.org,1,megacorp,"Individual account",1,Library,Default_Organization_View,"Employee"
32
danae.drayer@megacorp.org,1,megacorp,"Individual account",1,Library,Default_Organization_View,"Employee"
33
stan.stokely@megacorp.org,1,megacorp,"Individual account",1,Library,Default_Organization_View,"Employee"
34
martin.magallon@megacorp.org,1,megacorp,"Individual account",1,Library,Default_Organization_View,"Employee"
35
orville.oneill@megacorp.org,1,megacorp,"Individual account",1,Library,Default_Organization_View,"Employee"
36
kourtney.kyle@megacorp.org,1,megacorp,"Individual account",1,Library,Default_Organization_View,"Employee"
37
tessa.treiber@megacorp.org,1,megacorp,"Individual account",1,Library,Default_Organization_View,"Employee"
38
kamilah.kurland@megacorp.org,1,megacorp,"Individual account",1,Library,Default_Organization_View,"Employee"
39
zelma.zemke@megacorp.org,1,megacorp,"Individual account",1,Library,Default_Organization_View,"Employee"
40
jefferson.jock@megacorp.org,1,megacorp,"Individual account",1,Library,Default_Organization_View,"Employee"
41
shirely.stowe@megacorp.org,1,megacorp,"Individual account",1,Library,Default_Organization_View,"Employee"
42
niesha.nold@megacorp.org,1,megacorp,"Individual account",1,Library,Default_Organization_View,"Employee"
43
bruce.butterworth@megacorp.org,1,megacorp,"Individual account",1,Library,Default_Organization_View,"Employee"
44
denna.debartolo@megacorp.org,1,megacorp,"Individual account",1,Library,Default_Organization_View,"Employee"
45
janay.johnson@megacorp.org,1,megacorp,"Individual account",1,Library,Default_Organization_View,"Employee"
46
kristen.kellems@megacorp.org,1,megacorp,"Individual account",1,Library,Default_Organization_View,"Employee"
47
tiny.tacy@megacorp.org,1,megacorp,"Individual account",1,Library,Default_Organization_View,"Employee"
48
dolores.delay@megacorp.org,1,megacorp,"Individual account",1,Library,Default_Organization_View,"Employee"
49
shira.sitzes@megacorp.org,1,megacorp,"Individual account",1,Library,Default_Organization_View,"Employee"
50
aron.askew@megacorp.org,1,megacorp,"Individual account",1,Library,Default_Organization_View,"Employee"
51
nydia.neil@megacorp.org,1,megacorp,"Individual account",1,Library,Default_Organization_View,"Employee"
52
theodore.talbert@megacorp.org,1,megacorp,"Individual account",1,Library,Default_Organization_View,"Employee"
53
shani.spinks@megacorp.org,1,megacorp,"Individual account",1,Library,Default_Organization_View,"Employee"
54
diedra.darrow@megacorp.org,1,megacorp,"Individual account",1,Library,Default_Organization_View,"Employee"
55
judith.joachim@megacorp.org,1,megacorp,"Individual account",1,Library,Default_Organization_View,"Employee"
56
melda.metheny@megacorp.org,1,megacorp,"Individual account",1,Library,Default_Organization_View,"Employee"
57
nannie.nobles@megacorp.org,1,megacorp,"Individual account",1,Library,Default_Organization_View,"Employee"
58
annamae.audie@megacorp.org,1,megacorp,"Individual account",1,Library,Default_Organization_View,"Employee"
59
kalyn.kimzey@megacorp.org,1,megacorp,"Individual account",1,Library,Default_Organization_View,"Employee"
60
hsiu.henningsen@megacorp.org,1,megacorp,"Individual account",1,Library,Default_Organization_View,"Employee"
61
delcie.diez@megacorp.org,1,megacorp,"Individual account",1,Library,Default_Organization_View,"Employee"
62
edris.ekhoff@megacorp.org,1,megacorp,"Individual account",1,Library,Default_Organization_View,"Employee"
63
monique.maly@megacorp.org,1,megacorp,"Individual account",1,Library,Default_Organization_View,"Employee"
64
robbi.rosendahl@megacorp.org,1,megacorp,"Individual account",1,Library,Default_Organization_View,"Employee"
65
lakeesha.loiacono@megacorp.org,1,megacorp,"Individual account",1,Library,Default_Organization_View,"Employee"
66
coralee.culbert@megacorp.org,1,megacorp,"Individual account",1,Library,Default_Organization_View,"Employee"
67
danette.dewitt@megacorp.org,1,megacorp,"Individual account",1,Library,Default_Organization_View,"Employee"
68
cinthia.cadieux@megacorp.org,1,megacorp,"Individual account",1,Library,Default_Organization_View,"Employee"
69
myron.mclawhorn@megacorp.org,1,megacorp,"Individual account",1,Library,Default_Organization_View,"Employee"
70
madeleine.magers@megacorp.org,1,megacorp,"Individual account",1,Library,Default_Organization_View,"Employee"
71
evita.epting@megacorp.org,1,megacorp,"Individual account",1,Library,Default_Organization_View,"Employee"
72
karrie.kindel@megacorp.org,1,megacorp,"Individual account",1,Library,Default_Organization_View,"Employee"
73
moses.modisette@megacorp.org,1,megacorp,"Individual account",1,Library,Default_Organization_View,"Employee"
74
winifred.wessels@megacorp.org,1,megacorp,"Individual account",1,Library,Default_Organization_View,"Employee"
75
ashton.aumann@megacorp.org,1,megacorp,"Individual account",1,Library,Default_Organization_View,"Employee"
76
guillermina.gloster@megacorp.org,1,megacorp,"Individual account",1,Library,Default_Organization_View,"Employee"
77
jeremy.jong@megacorp.org,1,megacorp,"Individual account",1,Library,Default_Organization_View,"Employee"
78
marilou.mcintosh@megacorp.org,1,megacorp,"Individual account",1,Library,Default_Organization_View,"Employee"
79
rubin.ravenscroft@megacorp.org,1,megacorp,"Individual account",1,Library,Default_Organization_View,"Employee"
80
peggie.phillips@megacorp.org,1,megacorp,"Individual account",1,Library,Default_Organization_View,"Employee"
81
evelina.elders@megacorp.org,1,megacorp,"Individual account",1,Library,Default_Organization_View,"Employee"
82
edda.elam@megacorp.org,1,megacorp,"Individual account",1,Library,Default_Organization_View,"Employee"
83
fausto.fortino@megacorp.org,1,megacorp,"Individual account",1,Library,Default_Organization_View,"Employee"
84
elena.eisert@megacorp.org,1,megacorp,"Individual account",1,Library,Default_Organization_View,"Employee"
85
mariella.molock@megacorp.org,1,megacorp,"Individual account",1,Library,Default_Organization_View,"Employee"
86
starla.scheiber@megacorp.org,1,megacorp,"Individual account",1,Library,Default_Organization_View,"Employee"
87
parker.paetzold@megacorp.org,1,megacorp,"Individual account",1,Library,Default_Organization_View,"Employee"
88
vallie.vizcaino@megacorp.org,1,megacorp,"Individual account",1,Library,Default_Organization_View,"Employee"
89
renea.rubenstein@megacorp.org,1,megacorp,"Individual account",1,Library,Default_Organization_View,"Employee"
90
lien.lipscomb@megacorp.org,1,megacorp,"Individual account",1,Library,Default_Organization_View,"Employee"
91
debby.dupuy@megacorp.org,1,megacorp,"Individual account",1,Library,Default_Organization_View,"Employee"
92
carolann.corbo@megacorp.org,1,megacorp,"Individual account",1,Library,Default_Organization_View,"Employee"
93
lee.litchfield@megacorp.org,1,megacorp,"Individual account",1,Library,Default_Organization_View,"Employee"
94
lashon.locker@megacorp.org,1,megacorp,"Individual account",1,Library,Default_Organization_View,"Employee"
95
caroll.colquitt@megacorp.org,1,megacorp,"Individual account",1,Library,Default_Organization_View,"Employee"
96
lillian.louviere@megacorp.org,1,megacorp,"Individual account",1,Library,Default_Organization_View,"Employee"
97
rafaela.rasco@megacorp.org,1,megacorp,"Individual account",1,Library,Default_Organization_View,"Employee"
98
mandie.mcquinn@megacorp.org,1,megacorp,"Individual account",1,Library,Default_Organization_View,"Employee"
99
bambi.bivona@megacorp.org,1,megacorp,"Individual account",1,Library,Default_Organization_View,"Employee"
100
jacques.joaquin@megacorp.org,1,megacorp,"Individual account",1,Library,Default_Organization_View,"Employee"
101
wes.wallner@megacorp.org,1,megacorp,"Individual account",1,Library,Default_Organization_View,"Employee"
102
retta.rosso@megacorp.org,1,megacorp,"Individual account",1,Library,Default_Organization_View,"Employee"
103
melia.meche@megacorp.org,1,megacorp,"Individual account",1,Library,Default_Organization_View,"Employee"
104
nga.nordquist@megacorp.org,1,megacorp,"Individual account",1,Library,Default_Organization_View,"Employee"
105
georgine.grimmett@megacorp.org,1,megacorp,"Individual account",1,Library,Default_Organization_View,"Employee"
106
elden.easley@megacorp.org,1,megacorp,"Individual account",1,Library,Default_Organization_View,"Employee"
107
van.villanveva@megacorp.org,1,megacorp,"Individual account",1,Library,Default_Organization_View,"Employee"
108
shemika.spikes@megacorp.org,1,megacorp,"Individual account",1,Library,Default_Organization_View,"Employee"
109
bettina.budniewski@megacorp.org,1,megacorp,"Individual account",1,Library,Default_Organization_View,"Employee"
110
yun.yarberry@megacorp.org,1,megacorp,"Individual account",1,Library,Default_Organization_View,"Employee"
111
mac.malmberg@megacorp.org,1,megacorp,"Individual account",1,Library,Default_Organization_View,"Employee"
112
rory.rollinson@megacorp.org,1,megacorp,"Individual account",1,Library,Default_Organization_View,"Employee"
113
silva.sotelo@megacorp.org,1,megacorp,"Individual account",1,Library,Default_Organization_View,"Contractor"
114
le.leggett@megacorp.org,1,megacorp,"Individual account",1,Library,Default_Organization_View,"Contractor"
115
eartha.edie@megacorp.org,1,megacorp,"Individual account",1,Library,Default_Organization_View,"Contractor"
116
tenisha.tinajero@megacorp.org,1,megacorp,"Individual account",1,Library,Default_Organization_View,"Contractor"
117
hien.hamby@megacorp.org,1,megacorp,"Individual account",1,Library,Default_Organization_View,"Contractor"
118
milford.mize@megacorp.org,1,megacorp,"Individual account",1,Library,Default_Organization_View,"Contractor"
119
elnora.efaw@megacorp.org,1,megacorp,"Individual account",1,Library,Default_Organization_View,"Contractor"
test/data/system-groups.csv
1
Name,Count,Org Label,Limit,Description
2
Mega Corp HQ,1,megacorp,Unlimited,Downtown headquarters
3
Engineering,1,megacorp,Unlimited,,
4
Quality,1,megacorp,Unlimited,,
5
Accounting,1,megacorp,Unlimited,,
6
Facilities,1,megacorp,Unlimited,,
7
Shipping,1,megacorp,Unlimited,,
8
Lobby,1,megacorp,Unlimited,,
9
Customer Service,1,megacorp,Unlimited,,
10
Marketing,1,megacorp,Unlimited,,
11
HR,1,megacorp,Unlimited,,
12
Sales,1,megacorp,Unlimited,,
13
Legal,1,megacorp,Unlimited,,
14
Senior Leadership,1,megacorp,Unlimited,,
15
Employee,1,megacorp,Unlimited,,
16
Contractor,1,megacorp,Unlimited,,
test/data/systems.csv
1
Name,Count,Org Label,Environment Label,Groups,Virtual,Host,OS,Arch,Sockets,RAM,Cores,SLA,Products,Subscriptions
2
one%d,1,shippingreceiving,Library,,Yes,four1,RHEL 6.4,x86_64,1,4,1,Standard,"69|Red Hat Enterprise Linux Server,79|Red Hat Enterprise Linux Server",RH0103708|Red Hat Enterprise Linux Server Premium (8 sockets) (Up to 4 guests)
3
two%d,2,shippingreceiving,Library,,Yes,four2,RHEL 6.4,x86_64,1,4,1,Standard,69|Red Hat Enterprise Linux Server,RH0103708|Red Hat Enterprise Linux Server Premium (8 sockets) (Up to 4 guests)
4
#three%d,3,shippingreceiving,Library,,Yes,,RHEL 6.4,x86_64,1,4,1,Standard,69|Red Hat Enterprise Linux Server,RH0103708|Red Hat Enterprise Linux Server Premium (8 sockets) (Up to 4 guests)
5
four%d,4,shippingreceiving,Library,,No,,RHEL 6.4,x86_64,1,4,1,Standard,69|Red Hat Enterprise Linux Server,RH0103708|Red Hat Enterprise Linux Server Premium (8 sockets) (Up to 4 guests)
test/data/users.csv
1
Login,Count,First Name,Last Name,Email
2
damon.dials@megacorp.org,1,damon,dials,damon.dials@megacorp.org
3
jenee.jahns@megacorp.org,1,Jenee,Jahns,Jenee.Jahns@megacorp.org
4
gilbert.guerriero@megacorp.org,1,Gilbert,Guerriero,Gilbert.Guerriero@megacorp.org
5
quiana.quesnel@megacorp.org,1,Quiana,Quesnel,Quiana.Quesnel@megacorp.org
6
bernard.bigler@megacorp.org,1,Bernard,Bigler,Bernard.Bigler@megacorp.org
7
marietta.menzel@megacorp.org,1,Marietta,Menzel,Marietta.Menzel@megacorp.org
8
ruby.rieser@megacorp.org,1,Ruby,Rieser,Ruby.Rieser@megacorp.org
9
leonor.limberg@megacorp.org,1,Leonor,Limberg,Leonor.Limberg@megacorp.org
10
herminia.hochmuth@megacorp.org,1,Herminia,Hochmuth,Herminia.Hochmuth@megacorp.org
11
luana.larson@megacorp.org,1,Luana,Larson,Luana.Larson@megacorp.org
12
gilda.gutirrez@megacorp.org,1,Gilda,Gutirrez,Gilda.Gutirrez@megacorp.org
13
karlene.kirch@megacorp.org,1,Karlene,Kirch,Karlene.Kirch@megacorp.org
14
chelsea.calaway@megacorp.org,1,Chelsea,Calaway,Chelsea.Calaway@megacorp.org
15
tajuana.thies@megacorp.org,1,Tajuana,Thies,Tajuana.Thies@megacorp.org
16
dominica.dubberly@megacorp.org,1,Dominica,Dubberly,Dominica.Dubberly@megacorp.org
17
gregg.gault@megacorp.org,1,Gregg,Gault,Gregg.Gault@megacorp.org
18
boyd.buckle@megacorp.org,1,Boyd,Buckle,Boyd.Buckle@megacorp.org
19
georgeanna.griffiths@megacorp.org,1,Georgeanna,Griffiths,Georgeanna.Griffiths@megacorp.org
20
julio.jerabek@megacorp.org,1,Julio,Jerabek,Julio.Jerabek@megacorp.org
21
chaya.cordova@megacorp.org,1,Chaya,Cordova,Chaya.Cordova@megacorp.org
22
reinaldo.reardon@megacorp.org,1,Reinaldo,Reardon,Reinaldo.Reardon@megacorp.org
23
nancie.nassar@megacorp.org,1,Nancie,Nassar,Nancie.Nassar@megacorp.org
24
ayako.alday@megacorp.org,1,Ayako,Alday,Ayako.Alday@megacorp.org
25
skye.strobl@megacorp.org,1,Skye,Strobl,Skye.Strobl@megacorp.org
26
merle.miceli@megacorp.org,1,Merle,Miceli,Merle.Miceli@megacorp.org
27
sung.skipper@megacorp.org,1,Sung,Skipper,Sung.Skipper@megacorp.org
28
danilo.dilbeck@megacorp.org,1,Danilo,Dilbeck,Danilo.Dilbeck@megacorp.org
29
marylee.millsap@megacorp.org,1,Marylee,Millsap,Marylee.Millsap@megacorp.org
30
rolf.rueb@megacorp.org,1,Rolf,Rueb,Rolf.Rueb@megacorp.org
31
miriam.messenger@megacorp.org,1,Miriam,Messenger,Miriam.Messenger@megacorp.org
32
danae.drayer@megacorp.org,1,Danae,Drayer,Danae.Drayer@megacorp.org
33
stan.stokely@megacorp.org,1,Stan,Stokely,Stan.Stokely@megacorp.org
34
martin.magallon@megacorp.org,1,Martin,Magallon,Martin.Magallon@megacorp.org
35
orville.oneill@megacorp.org,1,Orville,Oneill,Orville.Oneill@megacorp.org
36
kourtney.kyle@megacorp.org,1,Kourtney,Kyle,Kourtney.Kyle@megacorp.org
37
tessa.treiber@megacorp.org,1,Tessa,Treiber,Tessa.Treiber@megacorp.org
38
kamilah.kurland@megacorp.org,1,Kamilah,Kurland,Kamilah.Kurland@megacorp.org
39
zelma.zemke@megacorp.org,1,Zelma,Zemke,Zelma.Zemke@megacorp.org
40
jefferson.jock@megacorp.org,1,Jefferson,Jock,Jefferson.Jock@megacorp.org
41
shirely.stowe@megacorp.org,1,Shirely,Stowe,Shirely.Stowe@megacorp.org
42
niesha.nold@megacorp.org,1,Niesha,Nold,Niesha.Nold@megacorp.org
43
bruce.butterworth@megacorp.org,1,Bruce,Butterworth,Bruce.Butterworth@megacorp.org
44
denna.debartolo@megacorp.org,1,Denna,Debartolo,Denna.Debartolo@megacorp.org
45
janay.johnson@megacorp.org,1,Janay,Johnson,Janay.Johnson@megacorp.org
46
kristen.kellems@megacorp.org,1,Kristen,Kellems,Kristen.Kellems@megacorp.org
47
tiny.tacy@megacorp.org,1,Tiny,Tacy,Tiny.Tacy@megacorp.org
48
dolores.delay@megacorp.org,1,Dolores,Delay,Dolores.Delay@megacorp.org
49
shira.sitzes@megacorp.org,1,Shira,Sitzes,Shira.Sitzes@megacorp.org
50
aron.askew@megacorp.org,1,Aron,Askew,Aron.Askew@megacorp.org
51
nydia.neil@megacorp.org,1,Nydia,Neil,Nydia.Neil@megacorp.org@megacorp.org
52
theodore.talbert@megacorp.org,1,Theodore,Talbert,Theodore.Talbert@megacorp.org
53
shani.spinks@megacorp.org,1,Shani,Spinks,Shani.Spinks@megacorp.org
54
diedra.darrow@megacorp.org,1,Diedra,Darrow,Diedra.Darrow@megacorp.org
55
judith.joachim@megacorp.org,1,Judith,Joachim,Judith.Joachim@megacorp.org
56
melda.metheny@megacorp.org,1,Melda,Metheny,Melda.Metheny@megacorp.org
57
nannie.nobles@megacorp.org,1,Nannie,Nobles,Nannie.Nobles@megacorp.org
58
annamae.audie@megacorp.org,1,Annamae,Audie,Annamae.Audie@megacorp.org
59
kalyn.kimzey@megacorp.org,1,Kalyn,Kimzey,Kalyn.Kimzey@megacorp.org
60
hsiu.henningsen@megacorp.org,1,Hsiu,Henningsen,Hsiu.Henningsen@megacorp.org
61
delcie.diez@megacorp.org,1,Delcie,Diez,Delcie.Diez@megacorp.org
62
edris.ekhoff@megacorp.org,1,Edris,Ekhoff,Edris.Ekhoff@megacorp.org
63
monique.maly@megacorp.org,1,Monique,Maly,Monique.Maly@megacorp.org
64
robbi.rosendahl@megacorp.org,1,Robbi,Rosendahl,Robbi.Rosendahl@megacorp.org
65
lakeesha.loiacono@megacorp.org,1,Lakeesha,Loiacono,Lakeesha.Loiacono@megacorp.org
66
coralee.culbert@megacorp.org,1,Coralee,Culbert,Coralee.Culbert@megacorp.org
67
danette.dewitt@megacorp.org,1,Danette,Dewitt,Danette.Dewitt@megacorp.org
68
cinthia.cadieux@megacorp.org,1,Cinthia,Cadieux,Cinthia.Cadieux@megacorp.org
69
myron.mclawhorn@megacorp.org,1,Myron,Mclawhorn,Myron.Mclawhorn@megacorp.org
70
madeleine.magers@megacorp.org,1,Madeleine,Magers,Madeleine.Magers@megacorp.org
71
evita.epting@megacorp.org,1,Evita,Epting,Evita.Epting@megacorp.org
72
karrie.kindel@megacorp.org,1,Karrie,Kindel,Karrie.Kindel@megacorp.org
73
moses.modisette@megacorp.org,1,Moses,Modisette,Moses.Modisette@megacorp.org
74
winifred.wessels@megacorp.org,1,Winifred,Wessels,Winifred.Wessels@megacorp.org
75
ashton.aumann@megacorp.org,1,Ashton,Aumann,Ashton.Aumann@megacorp.org
76
guillermina.gloster@megacorp.org,1,Guillermina,Gloster,Guillermina.Gloster@megacorp.org
77
jeremy.jong@megacorp.org,1,Jeremy,Jong,Jeremy.Jong@megacorp.org
78
marilou.mcintosh@megacorp.org,1,Marilou,Mcintosh,Marilou.Mcintosh@megacorp.org
79
rubin.ravenscroft@megacorp.org,1,Rubin,Ravenscroft,Rubin.Ravenscroft@megacorp.org
80
peggie.phillips@megacorp.org,1,Peggie,Phillips,Peggie.Phillips@megacorp.org
81
evelina.elders@megacorp.org,1,Evelina,Elders,Evelina.Elders@megacorp.org
82
edda.elam@megacorp.org,1,Edda,Elam,Edda.Elam@megacorp.org
83
fausto.fortino@megacorp.org,1,Fausto,Fortino,Fausto.Fortino@megacorp.org
84
elena.eisert@megacorp.org,1,Elena,Eisert,Elena.Eisert@megacorp.org
85
mariella.molock@megacorp.org,1,Mariella,Molock,Mariella.Molock@megacorp.org
86
starla.scheiber@megacorp.org,1,Starla,Scheiber,Starla.Scheiber@megacorp.org
87
parker.paetzold@megacorp.org,1,Parker,Paetzold,Parker.Paetzold@megacorp.org
88
vallie.vizcaino@megacorp.org,1,Vallie,Vizcaino,Vallie.Vizcaino@megacorp.org
89
renea.rubenstein@megacorp.org,1,Renea,Rubenstein,Renea.Rubenstein@megacorp.org
90
lien.lipscomb@megacorp.org,1,Lien,Lipscomb,Lien.Lipscomb@megacorp.org
91
debby.dupuy@megacorp.org,1,Debby,Dupuy,Debby.Dupuy@megacorp.org
92
carolann.corbo@megacorp.org,1,Carolann,Corbo,Carolann.Corbo@megacorp.org
93
lee.litchfield@megacorp.org,1,Lee,Litchfield,Lee.Litchfield@megacorp.org
94
lashon.locker@megacorp.org,1,Lashon,Locker,Lashon.Locker@megacorp.org
95
caroll.colquitt@megacorp.org,1,Caroll,Colquitt,Caroll.Colquitt@megacorp.org
96
lillian.louviere@megacorp.org,1,Lillian,Louviere,Lillian.Louviere@megacorp.org
97
rafaela.rasco@megacorp.org,1,Rafaela,Rasco,Rafaela.Rasco@megacorp.org
98
mandie.mcquinn@megacorp.org,1,Mandie,Mcquinn,Mandie.Mcquinn@megacorp.org
99
bambi.bivona@megacorp.org,1,Bambi,Bivona,Bambi.Bivona@megacorp.org
100
jacques.joaquin@megacorp.org,1,Jacques,Joaquin,Jacques.Joaquin@megacorp.org
101
wes.wallner@megacorp.org,1,Wes,Wallner,Wes.Wallner@megacorp.org
102
retta.rosso@megacorp.org,1,Retta,Rosso,Retta.Rosso@megacorp.org
103
melia.meche@megacorp.org,1,Melia,Meche,Melia.Meche@megacorp.org
104
nga.nordquist@megacorp.org,1,Nga,Nordquist,Nga.Nordquist@megacorp.org
105
georgine.grimmett@megacorp.org,1,Georgine,Grimmett,Georgine.Grimmett@megacorp.org
106
elden.easley@megacorp.org,1,Elden,Easley,Elden.Easley@megacorp.org
107
van.villanveva@megacorp.org,1,Van,Villanveva,Van.Villanveva@megacorp.org
108
shemika.spikes@megacorp.org,1,Shemika,Spikes,Shemika.Spikes@megacorp.org
109
bettina.budniewski@megacorp.org,1,Bettina,Budniewski,Bettina.Budniewski@megacorp.org
110
yun.yarberry@megacorp.org,1,Yun,Yarberry,Yun.Yarberry@megacorp.org
111
mac.malmberg@megacorp.org,1,Mac,Malmberg,Mac.Malmberg@megacorp.org
112
rory.rollinson@megacorp.org,1,Rory,Rollinson,Rory.Rollinson@megacorp.org
113
silva.sotelo@megacorp.org,1,Silva,Sotelo,Silva.Sotelo@megacorp.org
114
le.leggett@megacorp.org,1,Le,Leggett,Le.Leggett@megacorp.org
115
eartha.edie@megacorp.org,1,Eartha,Edie,Eartha.Edie@megacorp.org
116
tenisha.tinajero@megacorp.org,1,Tenisha,Tinajero,Tenisha.Tinajero@megacorp.org
117
hien.hamby@megacorp.org,1,Hien,Hamby,Hien.Hamby@megacorp.org
118
milford.mize@megacorp.org,1,Milford,Mize,Milford.Mize@megacorp.org
119
elnora.efaw@megacorp.org,1,Elnora,Efaw,Elnora.Efaw@megacorp.org
120

  
test/helpers/command.rb
1
# TODO: needed? require File.join(File.dirname(__FILE__), '../test_output_adapter')
2

  
3

  
4
module CommandTestHelper
5

  
6
  def with_params(params, &block)
7
    context "with params "+params.to_s do
8
      let(:with_params) { params }
9
      self.instance_eval &block
10
    end
11
  end
12

  
13
  def it_should_call_action(action, params)
14
    it "should call action "+action.to_s do
15
      arguments ||= respond_to?(:with_params) ? with_params : []
16
      cmd.resource.resource_class.expects_with(action, params)
17
      cmd.run(arguments)
18
    end
19
  end
20

  
21
  def it_should_fail_with(message, arguments=[])
22
    it "should fail with " + message.to_s do
23
      proc { cmd.run(arguments) }.must_raise Clamp::UsageError
24
    end
25
  end
26

  
27
  def it_should_accept(message, arguments=[])
28
    it "should accept " + message.to_s do
29
      cmd.run(arguments).must_equal HammerCLI::EX_OK
30
    end
31
  end
32

  
33
  def it_should_print_column(column_name, arguments=nil)
34
    it "should print column " + column_name do
35
      arguments ||= respond_to?(:with_params) ? with_params : []
36

  
37
      cmd.stubs(:context).returns({ :adapter => :test })
38
      proc { cmd.run(arguments) }.must_output /.*##{column_name}#.*/
39
    end
40
  end
41

  
42
  def it_should_print_columns(column_names, arguments=nil)
43
    column_names.each do |name|
44
      it_should_print_column name, arguments
45
    end
46
  end
47

  
48
  def it_should_print_n_records(count=nil, arguments=nil)
49
    it "should print correct count of records" do
50
      arguments ||= respond_to?(:with_params) ? with_params : []
51

  
52
      cmd.stubs(:context).returns({ :adapter => :test })
53
      count ||= expected_record_count rescue 0
54
      out, err = capture_io do
55
        cmd.run(arguments)
56
      end
57

  
58
      out.split(/\n/).length.must_equal count+1 # plus 1 for line with column headers
59
    end
60
  end
61

  
62
  def it_should_accept_search_params
63
    it_should_accept "search", ["--search=some_search"]
64
    it_should_accept "per page", ["--per-page=1"]
65
    it_should_accept "page", ["--page=2"]
66
    it_should_accept "order", ["--order=order"]
67
  end
68

  
69
end
test/helpers/resource_disabled.rb
1
#require File.join(File.dirname(__FILE__), '../test_output_adapter')
2

  
3

  
4
module CommandTestHelper
5

  
6
  def with_params(params, &block)
7
    context "with params "+params.to_s do
8
      let(:with_params) { params }
9
      self.instance_eval &block
10
    end
11
  end
12

  
13
  def it_should_call_action(action, params)
14
    it "should call action "+action.to_s do
15
      arguments ||= respond_to?(:with_params) ? with_params : []
16
      cmd.resource.resource_class.expects_with(action, params)
17
      cmd.run(arguments)
18
    end
19
  end
20

  
21
  def it_should_fail_with(message, arguments=[])
22
    it "should fail with " + message.to_s do
23
      proc { cmd.run(arguments) }.must_raise Clamp::UsageError
24
    end
25
  end
26

  
27
  def it_should_accept(message, arguments=[])
28
    it "should accept " + message.to_s do
29
      cmd.run(arguments).must_equal HammerCLI::EX_OK
30
    end
31
  end
32

  
33
  def it_should_print_column(column_name, arguments=nil)
34
    it "should print column " + column_name do
35
      arguments ||= respond_to?(:with_params) ? with_params : []
36

  
37
      cmd.stubs(:context).returns({ :adapter => :test })
38
      proc { cmd.run(arguments) }.must_output /.*##{column_name}#.*/
39
    end
40
  end
41

  
42
  def it_should_print_columns(column_names, arguments=nil)
43
    column_names.each do |name|
44
      it_should_print_column name, arguments
45
    end
46
  end
47

  
48
  def it_should_print_n_records(count=nil, arguments=nil)
49
    it "should print correct count of records" do
50
      arguments ||= respond_to?(:with_params) ? with_params : []
51

  
52
      cmd.stubs(:context).returns({ :adapter => :test })
53
      count ||= expected_record_count rescue 0
54
      out, err = capture_io do
55
        cmd.run(arguments)
56
      end
57

  
58
      out.split(/\n/).length.must_equal count+1 # plus 1 for line with column headers
59
    end
60
  end
61

  
62
  def it_should_accept_search_params
63
    it_should_accept "search", ["--search=some_search"]
64
    it_should_accept "per page", ["--per-page=1"]
65
    it_should_accept "page", ["--page=2"]
66
    it_should_accept "order", ["--order=order"]
67
  end
68

  
69
end

Also available in: Unified diff