Project

General

Profile

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

hammer-cli-csv / test / csv_test_helper.rb @ 561a8ac9

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 'hammer_cli'
20
require 'hammer_cli_foreman/commands'
21

    
22
HammerCLI::Settings.load_from_file 'test/config.yml'
23

    
24
require 'hammer_cli_csv'
25
require 'hammer_cli_foreman'
26
require 'hammer_cli_katello'
27

    
28
module HammerCLIForeman
29
  def self.clear_credentials
30
    @credentials = nil
31
  end
32
end
33

    
34

    
35
def hammer(context=nil)
36
  HammerCLI::MainCommand.new("", context || HammerCLI::Settings.dump)
37
end
38

    
39
def capture
40
  old_stdout = $stdout
41
  old_stderr = $stderr
42
  $stdout = stdout = StringIO.new
43
  $stderr = stderr = StringIO.new
44
  yield
45
  [stdout.string, stderr.string]
46
ensure
47
  $stdout = old_stdout
48
  $stderr = old_stderr
49
end
50

    
51
def set_user(username, password='changeme')
52
  HammerCLI::Connection.drop_all
53
  HammerCLIForeman.clear_credentials
54
  HammerCLI::Settings.load({
55
                               :_params => {
56
                                   :username => username,
57
                                   :password => password
58
                               },
59
                               :foreman => {
60
                                   :username => username,
61
                                   :password => password
62
                               },
63
                               :csv => {
64
                                   :username => username,
65
                                   :password => password
66
                               }
67
                           })
68
end
69

    
70

    
71
#require File.join(File.dirname(__FILE__), 'test_output_adapter')
72
require File.join(File.dirname(__FILE__), 'apipie_resource_mock')
73
require File.join(File.dirname(__FILE__), 'helpers/command')
74
require File.join(File.dirname(__FILE__), 'helpers/resource_disabled')