Project

General

Profile

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

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

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{csv subscriptions --help})
12
      }
13
      assert_equal '', stderr
14
      assert_equal stdout, <<-HELP
15
Usage:
16
     csv subscriptions [OPTIONS]
17

18
Options:
19
 --export                      Export current data instead of importing
20
 --file FILE_NAME              CSV file (default to /dev/stdout with --export, otherwise required)
21
 --organization ORGANIZATION   Only process organization matching this name
22
 -h, --help                    print help
23
 -v, --verbose                 be verbose
24
HELP
25
      stop_vcr
26
    end
27
  end
28

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

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

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