Project

General

Profile

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

hammer-cli-csv / test / resources / content_views_test.rb @ ebb00443

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

    
4
# rubocop:disable LineLength
5
module Resources
6
  class TestContentViews < MiniTest::Unit::TestCase
7
    def test_usage
8
      start_vcr
9
      set_user 'admin'
10

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

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

    
32
    def test_create_and_update
33
      start_vcr
34
      set_user 'admin'
35

    
36
      name = "testcv1"
37

    
38
      file = Tempfile.new('content_views_test')
39
      file.write("Name,Label,Organization,Composite,Repositories or Composites,Lifecycle Environments\n")
40
      file.write("#{name},#{name},Test Corporation,No,"",Library\n")
41
      file.rewind
42

    
43
      stdout,stderr = capture {
44
        hammer.run(%W{--reload-cache csv content-views --verbose --file #{file.path}})
45
      }
46
      refute_equal '', stderr
47
      assert_equal stdout[0..-2], "Creating content view '#{name}'...done"
48

    
49
      file.rewind
50

    
51
      stdout,stderr = capture {
52
        hammer.run(%W{--reload-cache csv content-views --verbose --file #{file.path}})
53
      }
54
      assert_equal '', stderr
55
      assert_equal stdout[0..-2], "Updating content view '#{name}'...done"
56
      file.unlink
57

    
58
      stdout,stderr = capture {
59
        hammer.run(%W(--reload-cache content-view list --search name=#{name}))
60
      }
61
      assert_equal '', stderr
62
      assert_equal stdout.split("\n").length, 5
63
      content_view_delete(name)
64

    
65
      stop_vcr
66
    end
67

    
68
    def test_export
69
      start_vcr
70
      set_user 'admin'
71

    
72
      stdout,stderr = capture {
73
        hammer.run(%W{--reload-cache csv content-views --export --organization Test\ Corporation})
74
      }
75
      assert_equal '', stderr
76
      assert_equal stdout.split("\n")[0], "Name,Label,Organization,Composite,Repositories or Composites,Lifecycle Environments"
77
      stop_vcr
78
    end
79
  end
80
end
81
# rubocop:enable LineLength