Project

General

Profile

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

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

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

    
4
module Resources
5
  class TestProducts < 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 products --help})
12
      }
13
      assert_equal '', stderr
14
      assert_equal stdout, <<-HELP
15
**** This command is unsupported and is provided as tech preview. ****
16
Usage:
17
     csv products [OPTIONS]
18

19
Options:
20
 --[no-]sync                   Sync product repositories (default true)
21
                               Default: true
22
 --continue-on-error           Continue processing even if individual resource error
23
 --export                      Export current data instead of importing
24
 --file FILE_NAME              CSV file (default to /dev/stdout with --export, otherwise required)
25
 --organization ORGANIZATION   Only process organization matching this name
26
 --search SEARCH               Only export search results
27
 -h, --help                    print help
28
 -v, --verbose                 be verbose
29
HELP
30
      stop_vcr
31
    end
32

    
33
    def test_create_rpm
34
      start_vcr
35
      set_user 'admin'
36
      name = "product create_rpm"
37

    
38
      file = Tempfile.new('products_test')
39
      # rubocop:disable LineLength
40
      file.write <<-FILE
41
Name,Label,Organization,Description,Repository,Repository Type,Content Set,Release,Repository Url
42
#{name},#{name},Test Corporation,,Zoo,Custom Yum,,,https://repos.fedorapeople.org/repos/pulp/pulp/demo_repos/zoo/
43
FILE
44
      # rubocop:enable LineLength
45
      file.rewind
46

    
47
      stdout,stderr = capture {
48
        hammer.run(%W{--reload-cache csv products --no-sync --verbose --file #{file.path}})
49
      }
50
      stderr.must_equal ''
51
      lines = stdout.split("\n")
52
      assert_equal "Creating product '#{name}'...Creating repository 'Zoo'...done", lines[0]
53
      file.unlink
54

    
55
      product_delete(name)
56
      stop_vcr
57
    end
58

    
59
    def test_update_rpm
60
      start_vcr
61
      set_user 'admin'
62
      name = "product update_rpm"
63

    
64
      file = Tempfile.new('products_test')
65
      # rubocop:disable LineLength
66
      file.write <<-FILE
67
Name,Label,Organization,Description,Repository,Repository Type,Content Set,Release,Repository Url
68
#{name},#{name},Test Corporation,,Zoo,Custom Yum,,,https://repos.fedorapeople.org/repos/pulp/pulp/demo_repos/zoo/
69
FILE
70
      # rubocop:enable LineLength
71
      file.rewind
72

    
73
      stdout,stderr = capture {
74
        hammer.run(%W{--reload-cache csv products --no-sync --verbose --file #{file.path}})
75
      }
76
      stderr.must_equal ''
77
      lines = stdout.split("\n")
78
      assert_equal "Creating product '#{name}'...Creating repository 'Zoo'...done", lines[0]
79

    
80
      file.rewind
81
      stdout,stderr = capture {
82
        hammer.run(%W{--reload-cache csv products --no-sync --verbose --file #{file.path}})
83
      }
84
      stderr.must_equal ''
85
      lines = stdout.split("\n")
86
      assert_equal "Updating product '#{name}'...Updating repository 'Zoo'...done", lines[0]
87

    
88
      file.unlink
89

    
90
      product_delete(name)
91
      stop_vcr
92
    end
93

    
94
    def test_create_update_rpm_docker
95
      start_vcr
96
      set_user 'admin'
97
      name = "product create_update_rpm_docker"
98

    
99
      file = Tempfile.new('products_test')
100
      # rubocop:disable LineLength
101
      file.write <<-FILE
102
Name,Label,Organization,Description,Repository,Repository Type,Content Set,Release,Repository Url,Verify SSL,Publish via HTTP,Mirror on Sync,Download Policy,Username,Password
103
#{name},#{name}label,Test Corporation,Yum Product,Zoo,Custom Yum,,,https://repos.fedorapeople.org/repos/pulp/pulp/demo_repos/zoo/,No,No,No,on_demand,,
104
#{name},#{name}label,Test Corporation,Docker Product,thomasmckay/hammer,Custom Docker,thomasmckay/hammer,,https://registry-1.docker.io/,Yes,Yes,Yes,"",,
105
FILE
106
      # rubocop:enable LineLength
107
      file.rewind
108

    
109
      stdout,stderr = capture {
110
        hammer.run(%W{--reload-cache csv products --no-sync --verbose --file #{file.path}})
111
      }
112
      stderr.must_equal ''
113
      lines = stdout.split("\n")
114
      assert_equal "Creating product '#{name}'...Creating repository 'Zoo'...done", lines[0]
115
      assert_equal "Updating product '#{name}'...Creating repository 'thomasmckay/hammer'...done", lines[1]
116

    
117
      file.rewind
118
      stdout,stderr = capture {
119
        hammer.run(%W{--reload-cache csv products --no-sync --verbose --file #{file.path}})
120
      }
121
      stderr.must_equal ''
122
      lines = stdout.split("\n")
123
      assert_equal "Updating product '#{name}'...Updating repository 'Zoo'...done", lines[0]
124
      assert_equal "Updating product '#{name}'...Updating repository 'thomasmckay/hammer'...done", lines[1]
125

    
126
      file.unlink
127

    
128
      product_delete(name)
129
      stop_vcr
130
    end
131

    
132
    def test_create_rhel_release
133
      start_vcr
134
      set_user 'admin'
135

    
136
      name = 'Red Hat Satellite Capsule 6.2 for RHEL 7 Server RPMs x86_64'
137

    
138
      file = Tempfile.new('products_test')
139
      # rubocop:disable LineLength
140
      file.write <<-FILE
141
Name,Label,Organization,Description,Repository,Repository Type,Content Set,$basearch,$releasever,Repository Url,Verify SSL,Publish via HTTP,Mirror on Sync,Download Policy,Username,Password
142
Red Hat Satellite Capsule,Red_Hat_Satellite_Capsule,Test Corporation,,Red Hat Satellite Capsule 6.2 for RHEL 7 Server RPMs x86_64,Red Hat Yum,Red Hat Satellite Capsule 6.2 (for RHEL 7 Server) (RPMs),x86_64,,https://cdn.redhat.com/content/dist/rhel/server/7/7Server/x86_64/sat-capsule/6.2/os,No,No,No,on_demand,,
143
FILE
144
      # rubocop:enable LineLength
145
      file.rewind
146

    
147
      stdout,stderr = capture {
148
        hammer.run(%W{--reload-cache csv products --no-sync --verbose --file #{file.path}})
149
      }
150
      stderr.must_equal ''
151
      lines = stdout.split("\n")
152
      assert_equal "Enabling repository Red Hat Satellite Capsule 6.2 for RHEL 7 Server RPMs x86_64...done", lines[0]
153
      assert_equal "Updating repository '#{name}'...done", lines[1]
154

    
155
      file.rewind
156
      stdout,stderr = capture {
157
        hammer.run(%W{--reload-cache csv products --no-sync --verbose --file #{file.path}})
158
      }
159
      stderr.must_equal ''
160
      lines = stdout.split("\n")
161
      assert_equal "Repository Red Hat Satellite Capsule 6.2 for RHEL 7 Server RPMs x86_64 already enabled", lines[0]
162
      assert_equal "Updating repository '#{name}'...done", lines[1]
163

    
164
      file.unlink
165

    
166
      # TODO: need to 'repository-set disable' but command is not working (test again against Sat-6.3)
167
      #       disable manually for now after the test to re-record
168
      stop_vcr
169
    end
170

    
171
    def product_delete(name)
172
      stdout,stderr = capture {
173
        hammer.run(%W(product list --organization Test\ Corporation --search #{name}))
174
      }
175
      lines = stdout.split("\n")
176
      if lines.length == 5
177
        id = stdout.split("\n")[3].split(" ")[0]
178
        stdout,stderr = capture {
179
          hammer.run(%W(product delete --organization Test\ Corporation --id #{id}))
180
        }
181
      end
182
    end
183
  end
184
end