Project

General

Profile

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

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

1
require './test/csv_test_helper'
2
require './lib/hammer_cli_csv'
3

    
4
module Resources
5
  class TestSubscriptionsUsage < MiniTest::Unit::TestCase
6
    def test_usage
7
      start_vcr
8
      set_user 'admin'
9

    
10
      stdout,stderr = capture {
11
        hammer.run(%W{--reload-cache csv subscriptions --help})
12
      }
13
      assert_equal '', stderr
14
      assert_equal stdout, <<-HELP
15
Usage:
16
     csv subscriptions [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
 --organization ORGANIZATION   Only process organization matching this name
23
 -h, --help                    print help
24
 -v, --verbose                 be verbose
25
HELP
26
      stop_vcr
27
    end
28
  end
29

    
30
  class TestSubscriptionsImport < MiniTest::Unit::TestCase
31
    def test_manifest_does_not_exist
32
      start_vcr
33
      set_user 'admin'
34

    
35
      file = Tempfile.new('subscriptions_test')
36
      # rubocop:disable LineLength
37
      file.write <<-FILE
38
Name,Organization,Manifest File,Subscription Name,Quantity,Product SKU,Contract Number,Account Number
39
Manifest,Test Corporation,./test/data/doesnotexist.zip
40
# Manifest Name,Test Corporation,ExampleCorp
41
# Manifest URL,Test Corporation,https://access.stage.redhat.com/management/distributors/1234
42
FILE
43
      file.rewind
44

    
45
      stdout,stderr = capture {
46
        hammer.run(%W{--reload-cache csv subscriptions --verbose --file #{file.path}})
47
      }
48
      assert_equal '', stdout
49
      lines = stderr.split("\n")
50
      assert_equal "Manifest upload failed:", lines[0]
51
      assert_match(/.*Error: No such file or directory.*/, lines[1])
52
      file.unlink
53
      stop_vcr
54
    end
55
  end
56
end