1
|
require File.join(File.dirname(__FILE__), 'csv_test_helper')
|
2
|
|
3
|
require 'stringio'
|
4
|
require 'tempfile'
|
5
|
|
6
|
describe 'import' do
|
7
|
extend CommandTestHelper
|
8
|
|
9
|
before :each do
|
10
|
HammerCLI::Settings.load_from_file 'test/config.yml'
|
11
|
end
|
12
|
|
13
|
context "--dir" do
|
14
|
it "hammer csv import --verbose --dir does-not-exist" do
|
15
|
stdout,stderr = capture {
|
16
|
hammer.run(%W{--debug csv import --verbose --dir does-not-exist})
|
17
|
}
|
18
|
stderr.must_equal ''
|
19
|
stdout.must_equal(
|
20
|
<<-eos
|
21
|
Skipping settings because 'does-not-exist/settings.csv' does not exist
|
22
|
Skipping organizations because 'does-not-exist/organizations.csv' does not exist
|
23
|
Skipping locations because 'does-not-exist/locations.csv' does not exist
|
24
|
Skipping puppet_environments because 'does-not-exist/puppet-environments.csv' does not exist
|
25
|
Skipping operating_systems because 'does-not-exist/operating-systems.csv' does not exist
|
26
|
Skipping domains because 'does-not-exist/domains.csv' does not exist
|
27
|
Skipping architectures because 'does-not-exist/architectures.csv' does not exist
|
28
|
Skipping partition_tables because 'does-not-exist/partition-tables.csv' does not exist
|
29
|
Skipping lifecycle_environments because 'does-not-exist/lifecycle-environments.csv' does not exist
|
30
|
Skipping host_collections because 'does-not-exist/host-collections.csv' does not exist
|
31
|
Skipping provisioning_templates because 'does-not-exist/provisioning-templates.csv' does not exist
|
32
|
Skipping subscriptions because 'does-not-exist/subscriptions.csv' does not exist
|
33
|
Skipping products because 'does-not-exist/products.csv' does not exist
|
34
|
Skipping content_views because 'does-not-exist/content-views.csv' does not exist
|
35
|
Skipping content_view_filters because 'does-not-exist/content-view_filters.csv' does not exist
|
36
|
Skipping activation_keys because 'does-not-exist/activation-keys.csv' does not exist
|
37
|
Skipping hosts because 'does-not-exist/hosts.csv' does not exist
|
38
|
Skipping content_hosts because 'does-not-exist/content-hosts.csv' does not exist
|
39
|
Skipping reports because 'does-not-exist/reports.csv' does not exist
|
40
|
Skipping roles because 'does-not-exist/roles.csv' does not exist
|
41
|
Skipping users because 'does-not-exist/users.csv' does not exist
|
42
|
eos
|
43
|
)
|
44
|
end
|
45
|
|
46
|
it "hammer csv import --verbose --organizations does-not-exist.csv" do
|
47
|
stdout,stderr = capture {
|
48
|
hammer.run(%W{csv import --verbose --organizations does-not-exist.csv})
|
49
|
}
|
50
|
stdout.must_equal ''
|
51
|
stderr[0..-2].must_equal 'Error: File for organizations \'does-not-exist.csv\' does not exist'
|
52
|
end
|
53
|
|
54
|
it "hammer csv import --verbose --organization unknown-org --organizations test/data/organizations.csv" do
|
55
|
stdout,stderr = capture {
|
56
|
hammer.run(%W{csv import --verbose --organization unknown-org --organizations test/data/organizations.csv})
|
57
|
}
|
58
|
stderr.must_equal ''
|
59
|
stdout[0..-2].must_equal 'Importing organizations from \'test/data/organizations.csv\''
|
60
|
end
|
61
|
|
62
|
it "hammer csv import --verbose --organization unknown-org --organizations test/data/organizations.csv" do
|
63
|
stdout,stderr = capture {
|
64
|
hammer.run(%W{csv import --verbose --organization unknown-org --organizations test/data/organizations.csv})
|
65
|
}
|
66
|
stderr.must_equal ''
|
67
|
stdout[0..-2].must_equal 'Importing organizations from \'test/data/organizations.csv\''
|
68
|
end
|
69
|
|
70
|
it "hammer csv import --verbose --prefix $rand --organizations test/data/organizations.csv" do
|
71
|
prefix = rand(10000)
|
72
|
stdout,stderr = capture {
|
73
|
hammer.run(%W{csv import --verbose --prefix #{prefix} --organizations test/data/organizations.csv})
|
74
|
}
|
75
|
stderr.must_equal ''
|
76
|
stdout[0..-2].must_equal "Importing organizations from 'test/data/organizations.csv'\nCreating organization '#{prefix}Mega Corporation'... done"
|
77
|
end
|
78
|
end
|
79
|
end
|