1
|
require File.join(File.dirname(__FILE__), 'csv_test_helper')
|
2
|
|
3
|
describe 'organizations' do
|
4
|
|
5
|
extend CommandTestHelper
|
6
|
|
7
|
before :each do
|
8
|
HammerCLI::Settings.load_from_file 'test/config.yml'
|
9
|
|
10
|
@api = ApipieBindings::API.new({
|
11
|
:uri => HammerCLI::Settings.get(:csv, :host),
|
12
|
:username => HammerCLI::Settings.get(:csv, :username),
|
13
|
:password => HammerCLI::Settings.get(:csv, :password),
|
14
|
:api_version => 2
|
15
|
})
|
16
|
|
17
|
end
|
18
|
|
19
|
context "organizations CRUD" do
|
20
|
|
21
|
it "create, update, delete" do
|
22
|
|
23
|
name = "host#{rand(10000)}"
|
24
|
|
25
|
|
26
|
file = Tempfile.new('organizations_test')
|
27
|
file.write("Name,Count,Org Label,Description\n")
|
28
|
file.write("#{name},1,#{name},A test organization\n")
|
29
|
file.rewind
|
30
|
|
31
|
stdout,stderr = capture {
|
32
|
hammer.run(%W{csv organizations -v --csv-file #{file.path}})
|
33
|
}
|
34
|
stderr.must_equal ''
|
35
|
stdout[0..-2].must_equal "Creating organization '#{name}'... done"
|
36
|
file.unlink
|
37
|
|
38
|
|
39
|
file = Tempfile.new('organizations_test')
|
40
|
file.write("Name,Count,Org Label,Description\n")
|
41
|
file.write("#{name},1,#{name},An updated test organization\n")
|
42
|
file.rewind
|
43
|
|
44
|
stdout,stderr = capture {
|
45
|
hammer.run(%W{csv organizations -v --csv-file #{file.path}})
|
46
|
}
|
47
|
stderr.must_equal ''
|
48
|
stdout[0..-2].must_equal "Updating organization '#{name}'... done"
|
49
|
file.unlink
|
50
|
|
51
|
|
52
|
organization = @api.resource(:organizations).call(:index, {
|
53
|
'search' => "name=\"#{name}\""
|
54
|
})['results']
|
55
|
organization.wont_be_nil
|
56
|
organization.wont_be_empty
|
57
|
organization[0]['name'].must_equal name
|
58
|
|
59
|
|
60
|
@api.resource(:organizations).call(:destroy, {
|
61
|
'id' => organization[0]['id']
|
62
|
})
|
63
|
|
64
|
|
65
|
organization = @api.resource(:organizations).call(:index, {
|
66
|
'search' => "name=\"#{name}\""
|
67
|
})['results']
|
68
|
organization.wont_be_nil
|
69
|
organization.will_be_empty
|
70
|
|
71
|
end
|
72
|
|
73
|
end
|
74
|
end
|