Project

General

Profile

Download (4 KB) Statistics
| Branch: | Tag: | Revision:

hammer-cli-csv / test / csv_test_helper.rb @ b50ceaa2

1
require 'simplecov'
2
require 'pathname'
3
require 'stringio'
4
require 'tempfile'
5

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

    
13

    
14
require 'minitest/autorun'
15
require 'minitest/spec'
16
require "minitest-spec-context"
17
require "mocha/setup"
18

    
19
require './test/test_runner'
20

    
21
require 'hammer_cli'
22
require 'hammer_cli_foreman/commands'
23

    
24
if File.exists? 'test/config.yml'
25
  HammerCLI::Settings.load_from_file 'test/config.yml'
26
else
27
  HammerCLI::Settings.load({
28
                             :ui => {
29
                               :interactive => true,
30
                               :per_page => 20,
31
                               :history_file => './log/history'
32
                             },
33
                             :watch_plain => true,
34
                             :log_dir => './log',
35
                             :log_level => 'error',
36
                             :log_api_calls => false,
37
                             :log_size => 5,
38
                             :csv => {
39
                               :enable_module => true
40
                             },
41
                             :foreman => {
42
                               :enable_module => true,
43
                               :host => 'https://localhost',
44
                               :username => 'admin',
45
                               :password => 'changeme'
46
                             },
47
                             :katello => {
48
                               :enable_module => true
49
                             }
50
                           })
51
end
52

    
53
VCR.insert_cassette("apipie", {})
54
require 'hammer_cli_csv'
55
require 'hammer_cli_foreman'
56
require 'hammer_cli_katello'
57
VCR.eject_cassette
58

    
59
module HammerCLIForeman
60
  def self.clear_credentials
61
    @credentials = nil
62
  end
63
end
64

    
65
def hammer(context=nil)
66
  HammerCLI::MainCommand.new("", context || HammerCLI::Settings.dump)
67
end
68

    
69
require 'apipie-bindings'
70
def api
71
  @server = HammerCLI::Settings.settings[:_params][:host] ||
72
    HammerCLI::Settings.get(:csv, :host) ||
73
    HammerCLI::Settings.get(:katello, :host) ||
74
    HammerCLI::Settings.get(:foreman, :host)
75
  @username = HammerCLI::Settings.settings[:_params][:username] ||
76
    HammerCLI::Settings.get(:csv, :username) ||
77
    HammerCLI::Settings.get(:katello, :username) ||
78
    HammerCLI::Settings.get(:foreman, :username)
79
  @password = HammerCLI::Settings.settings[:_params][:password] ||
80
    HammerCLI::Settings.get(:csv, :password) ||
81
    HammerCLI::Settings.get(:katello, :password) ||
82
    HammerCLI::Settings.get(:foreman, :password)
83
  @api = ApipieBindings::API.new({
84
                                   :uri => @server,
85
                                   :username => @username,
86
                                   :password => @password,
87
                                   :api_version => 2
88
                                 })
89
end
90

    
91
def capture
92
  old_stdout = $stdout
93
  old_stderr = $stderr
94
  $stdout = stdout = StringIO.new
95
  $stderr = stderr = StringIO.new
96
  yield
97
  [stdout.string, stderr.string]
98
ensure
99
  $stdout = old_stdout
100
  $stderr = old_stderr
101
end
102

    
103
def set_user(username, password='changeme')
104
  HammerCLI::Connection.drop_all
105
  HammerCLIForeman.clear_credentials
106
  HammerCLI::Settings.load({
107
                               :_params => {
108
                                   :username => username,
109
                                   :password => password
110
                               },
111
                               :foreman => {
112
                                   :username => username,
113
                                   :password => password
114
                               },
115
                               :csv => {
116
                                   :username => username,
117
                                   :password => password
118
                               }
119
                           })
120
end
121

    
122
require File.join(File.dirname(__FILE__), 'apipie_resource_mock')
123
require File.join(File.dirname(__FILE__), 'helpers/command')
124
require File.join(File.dirname(__FILE__), 'helpers/resource_disabled')