Project

General

Profile

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

hammer-cli-csv / test / import_test.rb @ 400832c6

1
require File.join(File.dirname(__FILE__), 'csv_test_helper')
2

    
3
describe 'import' do
4
  extend CommandTestHelper
5

    
6
  context "help" do
7
    it "displays supported options" do
8
      set_user 'admin'
9

    
10
      stdout,stderr = capture {
11
        hammer.run(%W{csv import --help})
12
      }
13
      stderr.must_equal ''
14
      stdout.must_equal <<-HELP
15
Usage:
16
     csv import [OPTIONS]
17

18
Options:
19
 --dir DIRECTORY               directory to import from
20
 --organization ORGANIZATION   Only process organization matching this name
21
 --settings FILE               csv file for settings
22
 -h, --help                    print help
23
 -v, --verbose                 be verbose
24
HELP
25
    end
26
  end
27

    
28
  context "--dir" do
29
    it "hammer csv import --verbose --dir does-not-exist" do
30
      stdout,stderr = capture {
31
        hammer.run(%W{--debug csv import --verbose --dir does-not-exist})
32
      }
33
      stderr.must_equal ''
34
      stdout.must_equal(
35
<<-eos
36
Skipping settings because 'does-not-exist/settings.csv' does not exist
37
eos
38
)
39
    end
40

    
41
    it "hammer csv import --verbose --organizations does-not-exist.csv" do
42
      stdout,stderr = capture {
43
        hammer.run(%W{csv import --verbose --organizations does-not-exist.csv})
44
      }
45
      stdout.must_equal ''
46
      stderr[0..-2].must_equal 'Error: File for organizations \'does-not-exist.csv\' does not exist'
47
    end
48

    
49
    it "hammer csv import --verbose --organization unknown-org --organizations test/data/organizations.csv" do
50
      stdout,stderr = capture {
51
        hammer.run(%W{csv import --verbose --organization unknown-org --organizations test/data/organizations.csv})
52
      }
53
      stderr.must_equal ''
54
      stdout[0..-2].must_equal 'Importing organizations from \'test/data/organizations.csv\''
55
    end
56

    
57
    it "hammer csv import --verbose --organization unknown-org --organizations test/data/organizations.csv" do
58
      stdout,stderr = capture {
59
        hammer.run(%W{csv import --verbose --organization unknown-org --organizations test/data/organizations.csv})
60
      }
61
      stderr.must_equal ''
62
      stdout[0..-2].must_equal 'Importing organizations from \'test/data/organizations.csv\''
63
    end
64

    
65
    it "hammer csv import --verbose --prefix $rand --organizations test/data/organizations.csv" do
66
      prefix = rand(10000)
67
      stdout,stderr = capture {
68
        hammer.run(%W{csv import --verbose --prefix #{prefix} --organizations test/data/organizations.csv})
69
      }
70
      stderr.must_equal ''
71
      stdout[0..-2].must_equal "Importing organizations from 'test/data/organizations.csv'\nCreating organization '#{prefix}Mega Corporation'... done"
72
    end
73
  end
74
end