Project

General

Profile

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

hammer-cli-csv / test / resources / content_view_filters_test.rb @ f92e695a

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

    
4
# rubocop:disable LineLength
5
module Resources
6
  class TestContentViewFilters < MiniTest::Unit::TestCase
7
    CONTENT_VIEW = "Test Puppet Modules"
8
    ORG = "Test Corporation"
9

    
10
    def test_usage
11
      start_vcr
12
      set_user 'admin'
13

    
14
      stdout,stderr = capture {
15
        hammer.run(%W{--reload-cache csv content-view-filters --help})
16
      }
17
      assert_equal '', stderr
18
      assert_equal stdout, <<-HELP
19
**** This command is unsupported and is provided as tech preview. ****
20
Usage:
21
     csv content-view-filters [OPTIONS]
22

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

    
35
    def test_create_and_update
36
      start_vcr
37
      set_user 'admin'
38

    
39
      name = "testfilter1"
40

    
41
      file = Tempfile.new('content_view_filters_test')
42
      file.write("Name,Content View,Organization,Type,Description,Repositories,Rules\n")
43
      file.write("#{name},#{CONTENT_VIEW},#{ORG},Exclude Packages,,"",jekyll|=|3.0\n")
44
      file.rewind
45

    
46
      stdout,stderr = capture {
47
        hammer.run(%W{--reload-cache csv content-view-filters --verbose --file #{file.path}})
48
      }
49
      assert_equal '', stderr
50
      assert_equal stdout[0..-2], "Creating filter '#{name}' for content view filter '#{CONTENT_VIEW}'....done"
51

    
52
      file.rewind
53

    
54
      stdout,stderr = capture {
55
        hammer.run(%W{--reload-cache csv content-view-filters --verbose --file #{file.path}})
56
      }
57
      assert_equal '', stderr
58
      assert_equal stdout[0..-2], "Updating filter '#{name}' for content view filter '#{CONTENT_VIEW}'....done"
59
      file.unlink
60

    
61
      stdout,stderr = capture {
62
        hammer.run(%W(--reload-cache content-view filter list --search name=#{name} --content-view #{CONTENT_VIEW} --organization #{ORG}))
63
      }
64
      assert_equal '', stderr
65
      assert_equal 5, stdout.split("\n").length
66
      content_view_filter_delete(ORG, CONTENT_VIEW, name)
67

    
68
      stop_vcr
69
    end
70

    
71
    def test_rule_name_change
72
      start_vcr
73
      set_user 'admin'
74

    
75
      name = "testfilter1"
76

    
77
      file = Tempfile.new('content_view_filters_test')
78
      file.write("Name,Content View,Organization,Type,Description,Repositories,Rules\n")
79
      file.write("#{name},#{CONTENT_VIEW},#{ORG},Exclude Packages,,"",jekyll|=|3.0\n")
80
      file.rewind
81

    
82
      stdout,stderr = capture {
83
        hammer.run(%W{--reload-cache csv content-view-filters --verbose --file #{file.path}})
84
      }
85
      assert_equal '', stderr
86
      assert_equal stdout[0..-2], "Creating filter '#{name}' for content view filter '#{CONTENT_VIEW}'....done"
87
      file.unlink
88

    
89
      # simulate a change in the rule from jekyll to hyde
90
      file = Tempfile.new('content_view_filters_test')
91
      file.write("Name,Content View,Organization,Type,Description,Repositories,Rules\n")
92
      file.write("#{name},#{CONTENT_VIEW},#{ORG},Exclude Packages,,"",hyde|=|3.0\n")
93
      file.rewind
94

    
95
      stdout,stderr = capture {
96
        hammer.run(%W{--reload-cache csv content-view-filters --verbose --file #{file.path}})
97
      }
98
      assert_equal '', stderr
99
      assert_equal stdout[0..-2], "Updating filter '#{name}' for content view filter '#{CONTENT_VIEW}'....done"
100
      file.unlink
101

    
102
      stdout,stderr = capture {
103
        hammer.run(%W(--reload-cache content-view filter list --search name=#{name} --content-view #{CONTENT_VIEW} --organization #{ORG}))
104
      }
105
      lines = stdout.split("\n")
106
      assert_equal '', stderr
107
      assert_equal 5, lines.length
108
      id = lines[3].split(" ")[0]
109

    
110
      stdout,stderr = capture {
111
        hammer.run(%W(--reload-cache content-view filter rule list --content-view-filter-id #{id}))
112
      }
113
      lines = stdout.split("\n")
114
      assert_equal 5, lines.length
115
      assert_match(/hyde/, lines[3])
116

    
117
      content_view_filter_delete(ORG, CONTENT_VIEW, name)
118
      stop_vcr
119
    end
120
  end
121
end
122
# rubocop:enable LineLength