Project

General

Profile

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

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

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
 --search SEARCH               Only export search results
24
 -h, --help                    print help
25
 -v, --verbose                 be verbose
26
HELP
27
      stop_vcr
28
    end
29

    
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,TestCorp
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{--reload-cache csv subscriptions --verbose --file #{file.path}})
46
      }
47
      assert_equal "Importing manifest './test/data/doesnotexist.zip' into organization 'Test Corporation'...done\n", 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

    
55
    def test_portal_incorrect_login
56
      start_vcr
57
      set_user 'admin'
58

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

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

    
81
    def test_portal_existing_subscription
82
      start_vcr
83
      set_user 'admin'
84

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

    
88
      manifestfile = Tempfile.new('subscriptions_test')
89
      file = Tempfile.new('subscriptions_test')
90
      # rubocop:disable LineLength
91
      file.write <<-FILE
92
Name,Organization,Manifest File,Subscription Name,Subscription Quantity,Subscription SKU,Subscription Contract,Subscription Account
93
Manifest,Test Corporation,#{manifestfile.path}
94
Manifest Name,Test Corporation,TestCorp
95
Manifest URL,Test Corporation,https://access.stage.redhat.com/management/distributors/1234
96
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
97
FILE
98
      # rubocop:enable LineLength
99
      file.rewind
100

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