Project

General

Profile

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

hammer-cli-csv / test / resources / subscriptions_test.rb @ 3061c66a

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

    
4
module Resources
5
  class TestSubscriptions < 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

    
29
    def test_manifest_does_not_exist
30
      start_vcr
31
      set_user 'admin'
32

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

    
43
      stdout,stderr = capture {
44
        hammer.run(%W{--reload-cache csv subscriptions --verbose --file #{file.path}})
45
      }
46
      assert_equal "Importing manifest './test/data/doesnotexist.zip' into organization 'Test Corporation'...done\n", stdout
47
      lines = stderr.split("\n")
48
      assert_equal "Manifest upload failed:", lines[0]
49
      assert_match(/.*Error: No such file or directory.*/, lines[1])
50
      file.unlink
51
      stop_vcr
52
    end
53

    
54
    def test_portal_incorrect_login
55
      start_vcr
56
      set_user 'admin'
57

    
58
      file = Tempfile.new('subscriptions_test')
59
      # rubocop:disable LineLength
60
      file.write <<-FILE
61
Name,Organization,Manifest File,Subscription Name,Quantity,Product SKU,Contract Number,Account Number
62
Manifest,Test Corporation,./test/data/doesnotexist.zip
63
Manifest Name,Test Corporation,TestCorp
64
Manifest URL,Test Corporation,https://access.stage.redhat.com/management/distributors/1234
65
FILE
66
      # rubocop:enable LineLength
67
      file.rewind
68

    
69
      stdout,stderr = capture {
70
        hammer.run(%W{--reload-cache csv subscriptions --verbose --file #{file.path}
71
                      --in-portal --portal-username username --portal-password password})
72
      }
73
      assert_equal "Checking manifest 'TestCorp'...", stdout
74
      lines = stderr.split("\n")
75
      assert_equal "Error: 401 Unauthorized", lines[0]
76
      file.unlink
77
      stop_vcr
78
    end
79

    
80
    def test_portal_existing_subscription
81
      start_vcr
82
      set_user 'admin'
83

    
84
      username = ENV['PORTALUSERNAME'] || 'username'
85
      password = ENV['PORTALPASSWORD'] || 'password'
86

    
87
      manifestfile = Tempfile.new('subscriptions_test')
88
      file = Tempfile.new('subscriptions_test')
89
      # rubocop:disable LineLength
90
      file.write <<-FILE
91
Name,Organization,Manifest File,Subscription Name,Subscription Quantity,Subscription SKU,Subscription Contract,Subscription Account
92
Manifest,Test Corporation,#{manifestfile.path}
93
Manifest Name,Test Corporation,TestCorp
94
Manifest URL,Test Corporation,https://access.stage.redhat.com/management/distributors/1234
95
Subscription,Test Corporation,,"Red Hat Enterprise Linux Server, Standard (Physical or Virtual Nodes)",200,RH00004,10999113,5700573,2016-06-20T04:00:00.000+0000,2017-06-20T03:59:59.000+0000
96
FILE
97
      # rubocop:enable LineLength
98
      file.rewind
99

    
100
      stdout,stderr = capture {
101
        hammer.run(%W{--reload-cache csv subscriptions --verbose --file #{file.path}
102
                      --in-portal --portal-username #{username} --portal-password #{password}
103
                      --portal https://subscription.rhn.stage.redhat.com:443})
104
      }
105
      lines = stdout.split("\n")
106
      assert_equal "Checking manifest 'TestCorp'...done", lines[0]
107
      assert_equal "'Red Hat Enterprise Linux Server, Standard (Physical or Virtual Nodes)' of quantity 200 already attached", lines[1]
108
      assert_equal "Downloading manifest for organization 'Test Corporation...writing to file '#{manifestfile.path}'...done", lines[2]
109
      assert_equal "Importing manifest '#{manifestfile.path}' into organization 'Test Corporation'...done", lines[3]
110
      file.unlink
111
      manifestfile.unlink
112
      stop_vcr
113
    end
114
  end
115
end