Project

General

Profile

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

hammer-cli-csv / test / resources / activation_keys_test.rb @ f370cc85

1 611959a3 Tom McKay
require './test/csv_test_helper'
2
require './lib/hammer_cli_csv'
3
4
module Resources
5
  class TestActivationKeysUsage < MiniTest::Unit::TestCase
6
    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
  end
30
31
  class TestActivationKeysImport < MiniTest::Unit::TestCase
32
    def test_create_and_update
33
      start_vcr
34
      set_user 'admin'
35
36
      @name = "testakey1"
37
38
      file = Tempfile.new('activation_keys_test')
39
      file.write("Name,Organization,Description,Limit,Environment,Content View,Host Collections,Auto-Attach,Service Level,Release Version,Subscriptions\n")
40
      file.write("#{@name},Test Corporation,,,,Default Organization View,"",No,,,\n")
41
      file.rewind
42
43
      stdout,stderr = capture {
44 f370cc85 Tom McKay
        hammer.run(%W{--reload-cache csv activation-keys --verbose --file #{file.path}})
45 611959a3 Tom McKay
      }
46
      assert_equal '', stderr
47
      assert_equal stdout[0..-2], "Creating activation key '#{@name}'...done"
48
49
      file.rewind
50
51
      stdout,stderr = capture {
52 f370cc85 Tom McKay
        hammer.run(%W{--reload-cache csv activation-keys --verbose --file #{file.path}})
53 611959a3 Tom McKay
      }
54
      assert_equal '', stderr
55
      assert_equal stdout[0..-2], "Updating activation key '#{@name}'...done"
56
      file.unlink
57
58
      stdout,stderr = capture {
59 f370cc85 Tom McKay
        hammer.run(%W(--reload-cache activation-key list --organization Test\ Corporation --search name=#{@name}))
60 611959a3 Tom McKay
      }
61
      assert_equal '', stderr
62
      assert_equal stdout.split("\n").length, 5
63
64
      id = stdout.split("\n")[3].split(" ")[0]
65
      stdout,stderr = capture {
66 f370cc85 Tom McKay
        hammer.run(%W(--reload-cache activation-key delete --id #{id}))
67 611959a3 Tom McKay
      }
68
69
      stop_vcr
70
    end
71
  end
72
end