Project

General

Profile

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

hammer-cli-csv / test / resources / activation_keys_test.rb @ 400832c6

1 611959a3 Tom McKay
require './test/csv_test_helper'
2
require './lib/hammer_cli_csv'
3
4
module Resources
5 400832c6 Tom McKay
  class TestActivationKeys < MiniTest::Unit::TestCase
6 611959a3 Tom McKay
    def test_usage
7
      start_vcr
8
      set_user 'admin'
9
10
      stdout,stderr = capture {
11 f370cc85 Tom McKay
        hammer.run(%W{--reload-cache csv activation-keys --help})
12 611959a3 Tom McKay
      }
13
      assert_equal '', stderr
14
      assert_equal stdout, <<-HELP
15
Usage:
16
     csv activation-keys [OPTIONS]
17

18
Options:
19
 --continue-on-error           Continue processing even if individual resource error
20
 --export                      Export current data instead of importing
21
 --file FILE_NAME              CSV file (default to /dev/stdout with --export, otherwise required)
22
 --itemized-subscriptions      Export one subscription per row, only process update subscriptions on import
23
 --organization ORGANIZATION   Only process organization matching this name
24
 -h, --help                    print help
25
 -v, --verbose                 be verbose
26
HELP
27
      stop_vcr
28
    end
29
30
    def test_create_and_update
31
      start_vcr
32
      set_user 'admin'
33
34
      @name = "testakey1"
35
36
      file = Tempfile.new('activation_keys_test')
37
      file.write("Name,Organization,Description,Limit,Environment,Content View,Host Collections,Auto-Attach,Service Level,Release Version,Subscriptions\n")
38
      file.write("#{@name},Test Corporation,,,,Default Organization View,"",No,,,\n")
39
      file.rewind
40
41
      stdout,stderr = capture {
42 f370cc85 Tom McKay
        hammer.run(%W{--reload-cache csv activation-keys --verbose --file #{file.path}})
43 611959a3 Tom McKay
      }
44
      assert_equal '', stderr
45
      assert_equal stdout[0..-2], "Creating activation key '#{@name}'...done"
46
47
      file.rewind
48
49
      stdout,stderr = capture {
50 f370cc85 Tom McKay
        hammer.run(%W{--reload-cache csv activation-keys --verbose --file #{file.path}})
51 611959a3 Tom McKay
      }
52
      assert_equal '', stderr
53
      assert_equal stdout[0..-2], "Updating activation key '#{@name}'...done"
54
      file.unlink
55
56
      stdout,stderr = capture {
57 f370cc85 Tom McKay
        hammer.run(%W(--reload-cache activation-key list --organization Test\ Corporation --search name=#{@name}))
58 611959a3 Tom McKay
      }
59
      assert_equal '', stderr
60
      assert_equal stdout.split("\n").length, 5
61
62
      id = stdout.split("\n")[3].split(" ")[0]
63
      stdout,stderr = capture {
64 f370cc85 Tom McKay
        hammer.run(%W(--reload-cache activation-key delete --id #{id}))
65 611959a3 Tom McKay
      }
66
67
      stop_vcr
68
    end
69
  end
70
end