MuranoCLI 2.2.4 → 3.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.agignore +3 -0
- data/.gitignore +18 -1
- data/.rubocop.yml +222 -0
- data/.trustme.sh +185 -0
- data/.trustme.vim +24 -0
- data/Gemfile +23 -4
- data/LICENSE.txt +1 -1
- data/MuranoCLI.gemspec +43 -8
- data/README.markdown +9 -11
- data/Rakefile +187 -143
- data/TODO.taskpaper +2 -2
- data/bin/murano +51 -52
- data/docs/basic_example.rst +436 -0
- data/docs/completions/murano_completion-bash +3484 -0
- data/docs/demo.md +32 -32
- data/docs/develop.rst +391 -0
- data/lib/MrMurano.rb +21 -7
- data/lib/MrMurano/Account.rb +159 -174
- data/lib/MrMurano/Business.rb +381 -0
- data/lib/MrMurano/Config-Migrate.rb +32 -26
- data/lib/MrMurano/Config.rb +407 -128
- data/lib/MrMurano/Content.rb +191 -0
- data/lib/MrMurano/Gateway.rb +489 -0
- data/lib/MrMurano/Keystore.rb +48 -0
- data/lib/MrMurano/Passwords.rb +103 -0
- data/lib/MrMurano/ProjectFile.rb +121 -79
- data/lib/MrMurano/ReCommander.rb +114 -10
- data/lib/MrMurano/Setting.rb +90 -0
- data/lib/MrMurano/Solution-ServiceConfig.rb +89 -45
- data/lib/MrMurano/Solution-Services.rb +461 -166
- data/lib/MrMurano/Solution-Users.rb +70 -31
- data/lib/MrMurano/Solution.rb +372 -13
- data/lib/MrMurano/SolutionId.rb +73 -0
- data/lib/MrMurano/SyncRoot.rb +137 -0
- data/lib/MrMurano/SyncUpDown.rb +594 -284
- data/lib/MrMurano/Webservice-Cors.rb +71 -0
- data/lib/MrMurano/Webservice-Endpoint.rb +234 -0
- data/lib/MrMurano/Webservice-File.rb +193 -0
- data/lib/MrMurano/Webservice.rb +51 -0
- data/lib/MrMurano/commands.rb +18 -15
- data/lib/MrMurano/commands/business.rb +300 -6
- data/lib/MrMurano/commands/completion-bash.erb +166 -0
- data/lib/MrMurano/commands/{zshcomplete.erb → completion-zsh.erb} +0 -0
- data/lib/MrMurano/commands/completion.rb +76 -39
- data/lib/MrMurano/commands/config.rb +108 -44
- data/lib/MrMurano/commands/content.rb +115 -72
- data/lib/MrMurano/commands/cors.rb +29 -14
- data/lib/MrMurano/commands/devices.rb +286 -0
- data/lib/MrMurano/commands/domain.rb +52 -12
- data/lib/MrMurano/commands/gb.rb +24 -9
- data/lib/MrMurano/commands/globals.rb +64 -0
- data/lib/MrMurano/commands/init.rb +377 -155
- data/lib/MrMurano/commands/keystore.rb +92 -82
- data/lib/MrMurano/commands/link.rb +300 -0
- data/lib/MrMurano/commands/login.rb +74 -11
- data/lib/MrMurano/commands/logs.rb +63 -32
- data/lib/MrMurano/commands/mock.rb +57 -29
- data/lib/MrMurano/commands/password.rb +57 -39
- data/lib/MrMurano/commands/postgresql.rb +127 -94
- data/lib/MrMurano/commands/settings.rb +203 -0
- data/lib/MrMurano/commands/show.rb +79 -38
- data/lib/MrMurano/commands/solution.rb +423 -5
- data/lib/MrMurano/commands/solution_picker.rb +547 -0
- data/lib/MrMurano/commands/status.rb +195 -61
- data/lib/MrMurano/commands/sync.rb +78 -39
- data/lib/MrMurano/commands/timeseries.rb +71 -55
- data/lib/MrMurano/commands/tsdb.rb +113 -87
- data/lib/MrMurano/commands/usage.rb +57 -15
- data/lib/MrMurano/hash.rb +100 -10
- data/lib/MrMurano/http.rb +187 -43
- data/lib/MrMurano/makePretty.rb +16 -14
- data/lib/MrMurano/optparse.rb +2178 -0
- data/lib/MrMurano/progress.rb +138 -0
- data/lib/MrMurano/schema/resource-v1.0.0.yaml +32 -0
- data/lib/MrMurano/template/projectFile.murano.erb +16 -13
- data/lib/MrMurano/verbosing.rb +166 -29
- data/lib/MrMurano/version.rb +30 -1
- data/spec/Account-Passwords_spec.rb +21 -4
- data/spec/Account_spec.rb +69 -146
- data/spec/Business_spec.rb +290 -0
- data/spec/ConfigFile_spec.rb +1 -0
- data/spec/ConfigMigrate_spec.rb +12 -8
- data/spec/Config_spec.rb +40 -34
- data/spec/Content_spec.rb +363 -0
- data/spec/GatewayBase_spec.rb +54 -0
- data/spec/GatewayDevice_spec.rb +321 -0
- data/spec/GatewayResource_spec.rb +266 -0
- data/spec/GatewaySettings_spec.rb +120 -0
- data/spec/Http_spec.rb +18 -8
- data/spec/Mock_spec.rb +2 -2
- data/spec/ProjectFile_spec.rb +25 -14
- data/spec/Setting_spec.rb +110 -0
- data/spec/Solution-ServiceConfig_spec.rb +44 -5
- data/spec/Solution-ServiceEventHandler_spec.rb +23 -14
- data/spec/Solution-ServiceModules_spec.rb +47 -37
- data/spec/Solution-UsersRoles_spec.rb +10 -8
- data/spec/Solution_spec.rb +17 -8
- data/spec/SyncRoot_spec.rb +46 -20
- data/spec/SyncUpDown_spec.rb +437 -201
- data/spec/Verbosing_spec.rb +12 -4
- data/spec/{Solution-Cors_spec.rb → Webservice-Cors_spec.rb} +23 -20
- data/spec/{Solution-Endpoint_spec.rb → Webservice-Endpoint_spec.rb} +43 -41
- data/spec/{Solution-File_spec.rb → Webservice-File_spec.rb} +44 -33
- data/spec/Webservice-Setting_spec.rb +89 -0
- data/spec/_workspace.rb +4 -4
- data/spec/cmd_business_spec.rb +9 -4
- data/spec/cmd_common.rb +44 -1
- data/spec/cmd_content_spec.rb +43 -17
- data/spec/cmd_cors_spec.rb +4 -4
- data/spec/cmd_device_spec.rb +61 -16
- data/spec/cmd_domain_spec.rb +29 -6
- data/spec/cmd_init_spec.rb +281 -126
- data/spec/cmd_keystore_spec.rb +3 -3
- data/spec/cmd_link_spec.rb +98 -0
- data/spec/cmd_password_spec.rb +1 -1
- data/spec/cmd_setting_application_spec.rb +260 -0
- data/spec/cmd_setting_product_spec.rb +220 -0
- data/spec/cmd_status_spec.rb +223 -114
- data/spec/cmd_syncdown_spec.rb +115 -35
- data/spec/cmd_syncup_spec.rb +68 -15
- data/spec/cmd_usage_spec.rb +35 -8
- data/spec/fixtures/dumped_config +6 -4
- data/spec/fixtures/gateway_resource_files/resources.notyaml +12 -0
- data/spec/fixtures/gateway_resource_files/resources.yaml +13 -0
- data/spec/fixtures/gateway_resource_files/resources_invalid.yaml +13 -0
- data/spec/fixtures/mrmuranorc_deleted_bob +0 -2
- data/spec/fixtures/product_spec_files/lightbulb.yaml +20 -13
- data/spec/fixtures/{syncable_content → syncable_conflict}/services/devdata.lua +1 -1
- data/spec/fixtures/{syncable_content → syncable_conflict}/services/timers.lua +0 -0
- data/spec/spec_helper.rb +5 -0
- metadata +262 -171
- data/bin/mr +0 -8
- data/lib/MrMurano/Product-1P-Device.rb +0 -145
- data/lib/MrMurano/Product-Resources.rb +0 -205
- data/lib/MrMurano/Product.rb +0 -358
- data/lib/MrMurano/Solution-Cors.rb +0 -47
- data/lib/MrMurano/Solution-Endpoint.rb +0 -191
- data/lib/MrMurano/Solution-File.rb +0 -166
- data/lib/MrMurano/commands/assign.rb +0 -57
- data/lib/MrMurano/commands/businessList.rb +0 -45
- data/lib/MrMurano/commands/product.rb +0 -14
- data/lib/MrMurano/commands/productCreate.rb +0 -39
- data/lib/MrMurano/commands/productDelete.rb +0 -33
- data/lib/MrMurano/commands/productDevice.rb +0 -87
- data/lib/MrMurano/commands/productDeviceIdCmds.rb +0 -89
- data/lib/MrMurano/commands/productList.rb +0 -45
- data/lib/MrMurano/commands/productWrite.rb +0 -27
- data/lib/MrMurano/commands/solutionCreate.rb +0 -41
- data/lib/MrMurano/commands/solutionDelete.rb +0 -34
- data/lib/MrMurano/commands/solutionList.rb +0 -45
- data/spec/ProductBase_spec.rb +0 -113
- data/spec/ProductContent_spec.rb +0 -162
- data/spec/ProductResources_spec.rb +0 -329
- data/spec/Product_1P_Device_spec.rb +0 -202
- data/spec/Product_1P_RPC_spec.rb +0 -175
- data/spec/Product_spec.rb +0 -153
- data/spec/Solution-ServiceDevice_spec.rb +0 -176
- data/spec/cmd_assign_spec.rb +0 -51
data/lib/MrMurano/version.rb
CHANGED
@@ -1,4 +1,33 @@
|
|
1
|
+
# Last Modified: 2017.08.18 /coding: utf-8
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
# Copyright © 2016-2017 Exosite LLC.
|
5
|
+
# License: MIT. See LICENSE.txt.
|
6
|
+
# vim:tw=0:ts=2:sw=2:et:ai
|
7
|
+
|
1
8
|
module MrMurano
|
2
|
-
|
9
|
+
# USAGE: Use 'beta.' and 'pre.' to label beta releases and dev builds.
|
10
|
+
# For example, the first beta for a 3.0.0 release would be:
|
11
|
+
# 3.0.0.beta.1
|
12
|
+
# After the beta release, developers would want to use a pre-build:
|
13
|
+
# 3.0.0.beta.2.pre.1
|
14
|
+
# And then the next beta release drops the 'pre'-postfix:
|
15
|
+
# 3.0.0.beta.2
|
16
|
+
# And finally the general release drops the 'beta'-postfix:
|
17
|
+
# 3.0.0
|
18
|
+
# This works because of how versions are ordered, e.g.,
|
19
|
+
# 3.0.0.beta.1 < 3.0.0.beta.2.pre.1 < 3.0.0.beta.2 < 3.0.0
|
20
|
+
#
|
21
|
+
# Note that we cannot follow the Semantic Version guidelines
|
22
|
+
# from http://semver.org/. The guidelines say to use a dash to
|
23
|
+
# separate the pre-release version, and a plus to separate the
|
24
|
+
# build metadata, e.g., '3.0.0-beta.2+1'. However, the `rake build`
|
25
|
+
# task replaces a dash in the version with the text, 'pre.', e.g.,
|
26
|
+
# '3.0.0-beta.2' is changed to '3.0.0.pre.beta.2'
|
27
|
+
# which breaks our build (which expects the version to match herein).
|
28
|
+
# So stick to using the '.pre.X' syntax, which ruby/gems knows.
|
29
|
+
VERSION = '3.0.0'
|
30
|
+
EXE_NAME = File.basename($PROGRAM_NAME)
|
31
|
+
SIGN_UP_URL = 'https://exosite.com/signup/'
|
3
32
|
end
|
4
33
|
|
@@ -1,14 +1,34 @@
|
|
1
|
+
# Last Modified: 2017.07.05 /coding: utf-8
|
2
|
+
|
3
|
+
# Copyright © 2016-2017 Exosite LLC.
|
4
|
+
# License: MIT. See LICENSE.txt.
|
5
|
+
# vim:tw=0:ts=2:sw=2:et:ai
|
6
|
+
|
7
|
+
require 'tempfile'
|
1
8
|
require 'MrMurano/version'
|
2
9
|
require 'MrMurano/Account'
|
3
|
-
require '
|
10
|
+
require '_workspace'
|
4
11
|
|
5
12
|
RSpec.describe MrMurano::Passwords, "#pwd" do
|
13
|
+
# Weird: This tests works on its own without the "WORKSPACE",
|
14
|
+
# but when run with other tests, it fails. (2017-07-05: I think
|
15
|
+
# I just added the $cfg lines, because MrMurano::Passwords
|
16
|
+
# expects $cfg to be loaded... [lb].)
|
17
|
+
include_context "WORKSPACE"
|
18
|
+
|
6
19
|
before(:example) do
|
20
|
+
@saved_cfg = ENV['MURANO_CONFIGFILE']
|
21
|
+
ENV['MURANO_CONFIGFILE'] = nil
|
22
|
+
$cfg = MrMurano::Config.new
|
23
|
+
$cfg.load
|
24
|
+
|
7
25
|
@saved_pwd = ENV['MURANO_PASSWORD']
|
8
26
|
ENV['MURANO_PASSWORD'] = nil
|
9
27
|
end
|
10
28
|
after(:example) do
|
11
29
|
ENV['MURANO_PASSWORD'] = @saved_pwd
|
30
|
+
|
31
|
+
ENV['MURANO_CONFIGFILE'] = @saved_cfg
|
12
32
|
end
|
13
33
|
|
14
34
|
it "Creates a file " do
|
@@ -235,8 +255,5 @@ this.is.a.host:
|
|
235
255
|
end
|
236
256
|
end
|
237
257
|
end
|
238
|
-
|
239
|
-
|
240
258
|
end
|
241
259
|
|
242
|
-
# vim: set ai et sw=2 ts=2 :
|
data/spec/Account_spec.rb
CHANGED
@@ -1,7 +1,14 @@
|
|
1
|
+
# Last Modified: 2017.08.16 /coding: utf-8
|
2
|
+
|
3
|
+
# Copyright © 2016-2017 Exosite LLC.
|
4
|
+
# License: MIT. See LICENSE.txt.
|
5
|
+
# vim:tw=0:ts=2:sw=2:et:ai
|
6
|
+
|
7
|
+
require 'highline/import'
|
1
8
|
require 'MrMurano/version'
|
2
|
-
require 'MrMurano/Config'
|
3
9
|
require 'MrMurano/Account'
|
4
|
-
require '
|
10
|
+
require 'MrMurano/Config'
|
11
|
+
require 'MrMurano/ProjectFile'
|
5
12
|
require '_workspace'
|
6
13
|
|
7
14
|
RSpec.describe MrMurano::Account, "token" do
|
@@ -15,7 +22,10 @@ RSpec.describe MrMurano::Account, "token" do
|
|
15
22
|
$cfg['business.id'] = 'XYZxyz'
|
16
23
|
$cfg['product.id'] = 'XYZ'
|
17
24
|
|
18
|
-
|
25
|
+
$project = MrMurano::ProjectFile.new
|
26
|
+
$project.load
|
27
|
+
|
28
|
+
@acc = MrMurano::Account.instance
|
19
29
|
end
|
20
30
|
|
21
31
|
after(:example) do
|
@@ -35,7 +45,7 @@ RSpec.describe MrMurano::Account, "token" do
|
|
35
45
|
$cfg['user.name'] = "bob"
|
36
46
|
expect(@pswd).to receive(:get).once.and_return("built")
|
37
47
|
|
38
|
-
ret = @acc.
|
48
|
+
ret = @acc.login_info
|
39
49
|
expect(ret).to eq({
|
40
50
|
:email => "bob", :password=>"built"
|
41
51
|
})
|
@@ -48,7 +58,7 @@ RSpec.describe MrMurano::Account, "token" do
|
|
48
58
|
expect($cfg).to receive(:set).with('user.name', 'bob', :user).once.and_call_original
|
49
59
|
expect(@pswd).to receive(:get).once.and_return("built")
|
50
60
|
|
51
|
-
ret = @acc.
|
61
|
+
ret = @acc.login_info
|
52
62
|
expect(ret).to eq({
|
53
63
|
:email => "bob", :password=>"built"
|
54
64
|
})
|
@@ -56,27 +66,30 @@ RSpec.describe MrMurano::Account, "token" do
|
|
56
66
|
|
57
67
|
it "Asks for password" do
|
58
68
|
$cfg['user.name'] = "bob"
|
59
|
-
expect(@pswd).to receive(:get).with('bizapi.hosted.exosite.io','bob').once.and_return(nil)
|
69
|
+
expect(@pswd).to receive(:get).with('bizapi.hosted.exosite.io', 'bob').once.and_return(nil)
|
60
70
|
expect(@acc).to receive(:error).once
|
61
71
|
expect($terminal).to receive(:ask).once.and_return('dog')
|
62
72
|
expect(@pswd).to receive(:set).once.with('bizapi.hosted.exosite.io','bob','dog')
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
73
|
+
# 2017-07-31: login_info may exit unless the command okays prompting for the password.
|
74
|
+
# (If we don't set this, login_info exits, which we'd want to
|
75
|
+
# catch with
|
76
|
+
# expect {@acc.login_info }.to raise_error(SystemExit).and output('...')
|
77
|
+
expect($cfg).to receive(:prompt_if_logged_off).and_return(true)
|
78
|
+
|
79
|
+
ret = @acc.login_info
|
80
|
+
expect(ret).to eq(email: "bob", password: "dog")
|
68
81
|
end
|
69
82
|
end
|
70
83
|
|
71
84
|
context "token" do
|
72
85
|
before(:example) do
|
73
|
-
allow(@acc).to receive(:
|
86
|
+
allow(@acc).to receive(:login_info).and_return({:email=>'bob',:password=>'v'})
|
74
87
|
end
|
75
88
|
|
76
89
|
it "gets a token" do
|
77
90
|
stub_request(:post, "https://bizapi.hosted.exosite.io/api:1/token/").
|
78
91
|
with(:body => {:email=>'bob', :password=>'v'}.to_json).
|
79
|
-
to_return(body: {:token=>"ABCDEFGHIJKLMNOP"}.to_json
|
92
|
+
to_return(body: {:token=>"ABCDEFGHIJKLMNOP"}.to_json)
|
80
93
|
|
81
94
|
ret = @acc.token
|
82
95
|
expect(ret).to eq("ABCDEFGHIJKLMNOP")
|
@@ -85,11 +98,17 @@ RSpec.describe MrMurano::Account, "token" do
|
|
85
98
|
it "gets an error" do
|
86
99
|
stub_request(:post, "https://bizapi.hosted.exosite.io/api:1/token/").
|
87
100
|
with(:body => {:email=>'bob', :password=>'v'}.to_json).
|
88
|
-
to_return(status: 401, body: {}.to_json
|
101
|
+
to_return(status: 401, body: {}.to_json)
|
89
102
|
|
90
103
|
expect(@acc).to receive(:error).twice.and_return(nil)
|
91
104
|
ret = @acc.token
|
92
105
|
expect(ret).to be_nil
|
106
|
+
# MAYBE/2017-07-13: Change Account.token method to put error and exit,
|
107
|
+
# just like Http.token method. ([lb] concerned that MurCLI might keep
|
108
|
+
# running without a valid token and then fail unexpectedly later.)
|
109
|
+
#expect {
|
110
|
+
# @acc.token
|
111
|
+
#}.to raise_error(SystemExit).and output("\e[31mNot logged in!\e[0m\n").to_stderr
|
93
112
|
end
|
94
113
|
|
95
114
|
it "uses existing token" do
|
@@ -100,7 +119,7 @@ RSpec.describe MrMurano::Account, "token" do
|
|
100
119
|
|
101
120
|
it "uses existing token, even with new instance" do
|
102
121
|
@acc.token_reset("quxx")
|
103
|
-
acc = MrMurano::Account.
|
122
|
+
acc = MrMurano::Account.instance
|
104
123
|
ret = acc.token
|
105
124
|
expect(ret).to eq("quxx")
|
106
125
|
end
|
@@ -118,7 +137,7 @@ RSpec.describe MrMurano::Account do
|
|
118
137
|
$cfg['business.id'] = 'XYZxyz'
|
119
138
|
$cfg['product.id'] = 'XYZ'
|
120
139
|
|
121
|
-
@acc = MrMurano::Account.
|
140
|
+
@acc = MrMurano::Account.instance
|
122
141
|
allow(@acc).to receive(:token).and_return("TTTTTTTTTT")
|
123
142
|
end
|
124
143
|
after(:example) do
|
@@ -126,155 +145,59 @@ RSpec.describe MrMurano::Account do
|
|
126
145
|
end
|
127
146
|
|
128
147
|
it "initializes" do
|
129
|
-
uri = @acc.
|
148
|
+
uri = @acc.endpoint('')
|
130
149
|
expect(uri.to_s).to eq("https://bizapi.hosted.exosite.io/api:1/")
|
131
150
|
end
|
132
151
|
|
133
152
|
context "lists business" do
|
134
153
|
it "for user.name" do
|
135
|
-
|
136
|
-
|
154
|
+
# http.rb::json_opts() sets :symbolize_names=>true, so use symbols, not strings.
|
155
|
+
bizlist = [
|
156
|
+
{:bizid=>"YYY",
|
157
|
+
:role=>"admin",
|
158
|
+
:name=>"MAE",
|
159
|
+
},
|
160
|
+
{:bizid=>"XXX",
|
161
|
+
:role=>"admin",
|
162
|
+
:name=>"MPS",
|
163
|
+
},
|
164
|
+
]
|
137
165
|
stub_request(:get, "https://bizapi.hosted.exosite.io/api:1/user/BoB@place.net/membership/").
|
138
|
-
to_return(body: bizlist
|
166
|
+
to_return(body: bizlist)
|
167
|
+
|
168
|
+
buslist = []
|
169
|
+
buslist << MrMurano::Business.new(bizlist[0])
|
170
|
+
buslist << MrMurano::Business.new(bizlist[1])
|
139
171
|
|
140
172
|
$cfg['user.name'] = 'BoB@place.net'
|
141
173
|
ret = @acc.businesses
|
142
|
-
expect(ret).to eq(
|
174
|
+
expect(ret).to eq(buslist)
|
143
175
|
end
|
144
176
|
|
145
|
-
it "
|
146
|
-
bizlist = [
|
147
|
-
|
177
|
+
it "asks for account when missing" do
|
178
|
+
bizlist = [
|
179
|
+
{:bizid=>"YYY",
|
180
|
+
:role=>"admin",
|
181
|
+
:name=>"MAE"},
|
182
|
+
{:bizid=>"XXX",
|
183
|
+
:role=>"admin",
|
184
|
+
:name=>"MPS"},
|
185
|
+
]
|
148
186
|
stub_request(:get, "https://bizapi.hosted.exosite.io/api:1/user/BoB@place.net/membership/").
|
149
|
-
to_return(body: bizlist
|
187
|
+
to_return(body: bizlist)
|
188
|
+
|
189
|
+
buslist = []
|
190
|
+
buslist << MrMurano::Business.new(bizlist[0])
|
191
|
+
buslist << MrMurano::Business.new(bizlist[1])
|
150
192
|
|
151
193
|
$cfg['user.name'] = nil
|
152
|
-
expect(@acc).to receive(:
|
194
|
+
expect(@acc).to receive(:login_info) do |arg|
|
153
195
|
$cfg['user.name'] = 'BoB@place.net'
|
154
196
|
end
|
155
197
|
|
156
198
|
ret = @acc.businesses
|
157
|
-
expect(ret).to eq(
|
199
|
+
expect(ret).to eq(buslist)
|
158
200
|
end
|
159
201
|
end
|
160
|
-
|
161
|
-
it "lists products" do
|
162
|
-
prdlist = [{"bizid"=>"XYZxyz","type"=>"onepModel","pid"=>"ABC","modelId"=>"cde","label"=>"fts"},
|
163
|
-
{"bizid"=>"XYZxyz","type"=>"onepModel","pid"=>"fgh","modelId"=>"ijk","label"=>"lua-test"}]
|
164
|
-
stub_request(:get, "https://bizapi.hosted.exosite.io/api:1/business/XYZxyz/product/").
|
165
|
-
to_return(body: prdlist )
|
166
|
-
|
167
|
-
ret = @acc.products
|
168
|
-
expect(ret).to eq(prdlist)
|
169
|
-
end
|
170
|
-
|
171
|
-
it "lists products; without biz.id" do
|
172
|
-
allow($cfg).to receive(:get).with('business.id').and_return(nil)
|
173
|
-
expect { @acc.products }.to raise_error("Missing Business ID")
|
174
|
-
end
|
175
|
-
|
176
|
-
it "creates product" do
|
177
|
-
stub_request(:post, "https://bizapi.hosted.exosite.io/api:1/business/XYZxyz/product/").
|
178
|
-
with(:body => {:label=>'ONe', :type=>'onepModel'}).
|
179
|
-
to_return(body: "" )
|
180
|
-
|
181
|
-
ret = @acc.new_product("ONe")
|
182
|
-
expect(ret).to eq({})
|
183
|
-
end
|
184
|
-
|
185
|
-
it "creates product; without biz.id" do
|
186
|
-
allow($cfg).to receive(:get).with('business.id').and_return(nil)
|
187
|
-
expect { @acc.new_product("ONe") }.to raise_error("Missing Business ID")
|
188
|
-
end
|
189
|
-
|
190
|
-
it "deletes product" do
|
191
|
-
stub_request(:delete, "https://bizapi.hosted.exosite.io/api:1/business/XYZxyz/product/ONe").
|
192
|
-
to_return(body: "" )
|
193
|
-
|
194
|
-
ret = @acc.delete_product("ONe")
|
195
|
-
expect(ret).to eq({})
|
196
|
-
end
|
197
|
-
|
198
|
-
it "deletes product; without biz.id" do
|
199
|
-
allow($cfg).to receive(:get).with('business.id').and_return(nil)
|
200
|
-
expect { @acc.delete_product("ONe") }.to raise_error("Missing Business ID")
|
201
|
-
end
|
202
|
-
|
203
|
-
|
204
|
-
it "lists solutions" do
|
205
|
-
sollist = [{"bizid"=>"XYZxyz",
|
206
|
-
"type"=>"dataApi",
|
207
|
-
"domain"=>"two.apps.exosite.io",
|
208
|
-
"apiId"=>"abc",
|
209
|
-
"sid"=>"def"},
|
210
|
-
{"bizid"=>"XYZxyz",
|
211
|
-
"type"=>"dataApi",
|
212
|
-
"domain"=>"one.apps.exosite.io",
|
213
|
-
"apiId"=>"ghi",
|
214
|
-
"sid"=>"jkl"}]
|
215
|
-
stub_request(:get, "https://bizapi.hosted.exosite.io/api:1/business/XYZxyz/solution/").
|
216
|
-
to_return(body: sollist )
|
217
|
-
|
218
|
-
ret = @acc.solutions
|
219
|
-
expect(ret).to eq(sollist)
|
220
|
-
end
|
221
|
-
|
222
|
-
it "lists solutions; without biz.id" do
|
223
|
-
allow($cfg).to receive(:get).with('business.id').and_return(nil)
|
224
|
-
expect { @acc.solutions }.to raise_error("Missing Business ID")
|
225
|
-
end
|
226
|
-
|
227
|
-
it "creates solution" do
|
228
|
-
stub_request(:post, "https://bizapi.hosted.exosite.io/api:1/business/XYZxyz/solution/").
|
229
|
-
with(:body => {:label=>'one', :type=>'dataApi'}).
|
230
|
-
to_return(body: "" )
|
231
|
-
|
232
|
-
ret = @acc.new_solution("one")
|
233
|
-
expect(ret).to eq({})
|
234
|
-
end
|
235
|
-
|
236
|
-
it "creates solution; with upper case" do
|
237
|
-
stub_request(:post, "https://bizapi.hosted.exosite.io/api:1/business/XYZxyz/solution/").
|
238
|
-
with(:body => {:label=>'ONe', :type=>'dataApi'}).
|
239
|
-
to_return(body: "" )
|
240
|
-
|
241
|
-
expect { @acc.new_solution("ONe") }.to_not raise_error
|
242
|
-
end
|
243
|
-
|
244
|
-
it "creates solution; with numbers and dashes" do
|
245
|
-
stub_request(:post, "https://bizapi.hosted.exosite.io/api:1/business/XYZxyz/solution/").
|
246
|
-
with(:body => {:label=>'ONe-8796-gkl', :type=>'dataApi'}).
|
247
|
-
to_return(body: "" )
|
248
|
-
|
249
|
-
expect { @acc.new_solution("ONe-8796-gkl") }.to_not raise_error
|
250
|
-
end
|
251
|
-
|
252
|
-
it "creates solution; that is too long" do
|
253
|
-
expect { @acc.new_solution("o"*70) }.to raise_error("Solution name must be a valid domain name component")
|
254
|
-
end
|
255
|
-
|
256
|
-
it "creates solution; with underscore" do
|
257
|
-
expect { @acc.new_solution("one_two") }.to raise_error("Solution name must be a valid domain name component")
|
258
|
-
end
|
259
|
-
|
260
|
-
it "creates solution; without biz.id" do
|
261
|
-
allow($cfg).to receive(:get).with('business.id').and_return(nil)
|
262
|
-
expect { @acc.new_solution("one") }.to raise_error("Missing Business ID")
|
263
|
-
end
|
264
|
-
|
265
|
-
it "deletes solution" do
|
266
|
-
stub_request(:delete, "https://bizapi.hosted.exosite.io/api:1/business/XYZxyz/solution/one").
|
267
|
-
to_return(body: "" )
|
268
|
-
|
269
|
-
ret = @acc.delete_solution("one")
|
270
|
-
expect(ret).to eq({})
|
271
|
-
end
|
272
|
-
|
273
|
-
it "deletes solution; without biz.id" do
|
274
|
-
allow($cfg).to receive(:get).with('business.id').and_return(nil)
|
275
|
-
expect { @acc.delete_solution("one") }.to raise_error("Missing Business ID")
|
276
|
-
end
|
277
|
-
|
278
202
|
end
|
279
203
|
|
280
|
-
# vim: set ai et sw=2 ts=2 :
|
@@ -0,0 +1,290 @@
|
|
1
|
+
# Last Modified: 2017.08.02 /coding: utf-8
|
2
|
+
|
3
|
+
# Copyright © 2016-2017 Exosite LLC.
|
4
|
+
# License: MIT. See LICENSE.txt.
|
5
|
+
# vim:tw=0:ts=2:sw=2:et:ai
|
6
|
+
|
7
|
+
require 'highline/import'
|
8
|
+
require 'MrMurano/version'
|
9
|
+
require 'MrMurano/Config'
|
10
|
+
require 'MrMurano/Account'
|
11
|
+
require '_workspace'
|
12
|
+
|
13
|
+
MISSING_BIZ_ID_MSG = MrMurano::Business.missing_business_id_msg
|
14
|
+
|
15
|
+
RSpec.describe MrMurano::Business do
|
16
|
+
include_context "WORKSPACE"
|
17
|
+
before(:example) do
|
18
|
+
@saved_cfg = ENV['MURANO_CONFIGFILE']
|
19
|
+
ENV['MURANO_CONFIGFILE'] = nil
|
20
|
+
$cfg = MrMurano::Config.new
|
21
|
+
$cfg.load
|
22
|
+
$cfg['net.host'] = 'bizapi.hosted.exosite.io'
|
23
|
+
$cfg['business.id'] = 'XYZxyz'
|
24
|
+
$cfg['product.id'] = 'XYZ'
|
25
|
+
|
26
|
+
@biz = MrMurano::Business.new
|
27
|
+
allow(@biz).to receive(:token).and_return("TTTTTTTTTT")
|
28
|
+
end
|
29
|
+
after(:example) do
|
30
|
+
ENV['MURANO_CONFIGFILE'] = @saved_cfg
|
31
|
+
end
|
32
|
+
|
33
|
+
it "lists products" do
|
34
|
+
prodlist = [
|
35
|
+
{bizid: "XYZxyz",
|
36
|
+
type: "product",
|
37
|
+
pid: "ABC",
|
38
|
+
modelId: "cde",
|
39
|
+
label: "fts",
|
40
|
+
sid: "XYZ",
|
41
|
+
name: "XYZ",},
|
42
|
+
{bizid: "XYZxyz",
|
43
|
+
type: "product",
|
44
|
+
pid: "fgh",
|
45
|
+
modelId: "ijk",
|
46
|
+
label: "lua-test",
|
47
|
+
sid: "XYZ",
|
48
|
+
name: "XYZ",},
|
49
|
+
]
|
50
|
+
stub_request(:get, "https://bizapi.hosted.exosite.io/api:1/business/XYZxyz/solution/").
|
51
|
+
to_return(body: prodlist)
|
52
|
+
|
53
|
+
solz = []
|
54
|
+
solz << MrMurano::Product.new(prodlist[0])
|
55
|
+
solz << MrMurano::Product.new(prodlist[1])
|
56
|
+
|
57
|
+
ret = @biz.products
|
58
|
+
expect(ret).to eq(solz)
|
59
|
+
end
|
60
|
+
|
61
|
+
it "lists products; without biz.id" do
|
62
|
+
allow($cfg).to receive(:get).with('business.id').and_return(nil)
|
63
|
+
expect(@biz).to receive(:debug).with("Getting all solutions of type product")
|
64
|
+
expect { @biz.products }.to raise_error(MISSING_BIZ_ID_MSG)
|
65
|
+
end
|
66
|
+
|
67
|
+
it "creates product" do
|
68
|
+
# LATER: Re-enable using "ONe" instead of "one" after upcase fixed in pegasus_registry.
|
69
|
+
stub_request(
|
70
|
+
:post, "https://bizapi.hosted.exosite.io/api:1/business/XYZxyz/solution/"
|
71
|
+
).with(
|
72
|
+
body: { label: 'one', type: 'product' }
|
73
|
+
).to_return(body: '{"id": "abc123def456ghi78", "name": "one"}')
|
74
|
+
|
75
|
+
prod = @biz.new_product("one")
|
76
|
+
expect(prod.valid?).to be true
|
77
|
+
end
|
78
|
+
|
79
|
+
it "creates product; without biz.id" do
|
80
|
+
allow($cfg).to receive(:get).with('business.id').and_return(nil)
|
81
|
+
# LATER: Re-enable using "ONe" instead of "one" after upcase fixed in pegasus_registry.
|
82
|
+
expect { @biz.new_product("one") }.to raise_error(MISSING_BIZ_ID_MSG)
|
83
|
+
end
|
84
|
+
|
85
|
+
it "deletes product" do
|
86
|
+
# LATER: Re-enable using "ONe" instead of "one" after upcase fixed in pegasus_registry.
|
87
|
+
stub_request(:delete, "https://bizapi.hosted.exosite.io/api:1/business/XYZxyz/solution/one").
|
88
|
+
to_return(body: "")
|
89
|
+
|
90
|
+
ret = @biz.delete_product("one")
|
91
|
+
expect(ret).to eq({})
|
92
|
+
end
|
93
|
+
|
94
|
+
it "deletes product; without biz.id" do
|
95
|
+
allow($cfg).to receive(:get).with('business.id').and_return(nil)
|
96
|
+
# LATER: Re-enable using "ONe" instead of "one" after upcase fixed in pegasus_registry.
|
97
|
+
expect { @biz.delete_product("one") }.to raise_error(MISSING_BIZ_ID_MSG)
|
98
|
+
end
|
99
|
+
|
100
|
+
# *** :applications type solutions
|
101
|
+
|
102
|
+
it "lists applications" do
|
103
|
+
# NOTE: Need to use symbols, not strings, for keys, because
|
104
|
+
# http.rb::json_opts() specifies :symbolize_names => true.
|
105
|
+
appllist = [
|
106
|
+
{bizid: "XYZxyz",
|
107
|
+
type: "application",
|
108
|
+
domain: "XYZxyz.apps.exosite.io",
|
109
|
+
apiId: "ACBabc",
|
110
|
+
sid: "ACBabc",
|
111
|
+
name: "ijk",
|
112
|
+
},
|
113
|
+
{bizid: "XYZxyz",
|
114
|
+
type: "application",
|
115
|
+
domain: "XYZxyz.apps.exosite.io",
|
116
|
+
apiId: "DEFdef",
|
117
|
+
sid: "DEFdef",
|
118
|
+
name: "lmn",
|
119
|
+
},
|
120
|
+
]
|
121
|
+
solnlist = [
|
122
|
+
{bizid: "XYZxyz",
|
123
|
+
type: "product",
|
124
|
+
pid: "ABC",
|
125
|
+
modelId: "cde",
|
126
|
+
label: "fts",
|
127
|
+
name: "fgh",
|
128
|
+
},
|
129
|
+
]
|
130
|
+
solnlist.concat appllist
|
131
|
+
stub_request(:get, "https://bizapi.hosted.exosite.io/api:1/business/XYZxyz/solution/").
|
132
|
+
to_return(body: solnlist)
|
133
|
+
|
134
|
+
solz = []
|
135
|
+
#solz << MrMurano::Product.new(solnlist[0])
|
136
|
+
solz << MrMurano::Application.new(appllist[0])
|
137
|
+
solz << MrMurano::Application.new(appllist[1])
|
138
|
+
|
139
|
+
ret = @biz.applications
|
140
|
+
expect(ret).to eq(solz)
|
141
|
+
end
|
142
|
+
|
143
|
+
it "lists applications; without biz.id" do
|
144
|
+
allow($cfg).to receive(:get).with('business.id').and_return(nil)
|
145
|
+
expect(@biz).to receive(:debug).with("Getting all solutions of type application")
|
146
|
+
expect { @biz.applications }.to raise_error(MISSING_BIZ_ID_MSG)
|
147
|
+
end
|
148
|
+
|
149
|
+
it "creates application" do
|
150
|
+
# LATER: Re-enable using "ONe" instead of "one" after upcase fixed in pegasus_registry.
|
151
|
+
stub_request(:post, "https://bizapi.hosted.exosite.io/api:1/business/XYZxyz/solution/").
|
152
|
+
with(:body => {:label=>'one', :type=>'application'}).
|
153
|
+
to_return(body: '{"id": "abc123def456ghi78", "name": "one"}')
|
154
|
+
|
155
|
+
appl = @biz.new_application("one")
|
156
|
+
expect(appl.valid?).to be true
|
157
|
+
end
|
158
|
+
|
159
|
+
it "creates application; without biz.id" do
|
160
|
+
allow($cfg).to receive(:get).with('business.id').and_return(nil)
|
161
|
+
# LATER: Re-enable using "ONe" instead of "one" after upcase fixed in pegasus_registry.
|
162
|
+
expect { @biz.new_application("one") }.to raise_error(MISSING_BIZ_ID_MSG)
|
163
|
+
end
|
164
|
+
|
165
|
+
it "deletes application" do
|
166
|
+
stub_request(:delete, "https://bizapi.hosted.exosite.io/api:1/business/XYZxyz/solution/ONe").
|
167
|
+
to_return(body: "")
|
168
|
+
|
169
|
+
ret = @biz.delete_application("ONe")
|
170
|
+
expect(ret).to eq({})
|
171
|
+
end
|
172
|
+
|
173
|
+
it "deletes application; without biz.id" do
|
174
|
+
allow($cfg).to receive(:get).with('business.id').and_return(nil)
|
175
|
+
expect { @biz.delete_application("ONe") }.to raise_error(MISSING_BIZ_ID_MSG)
|
176
|
+
end
|
177
|
+
|
178
|
+
# *** :all type solutions
|
179
|
+
|
180
|
+
it "lists solutions" do
|
181
|
+
# http.rb::json_opts() sets :symbolize_names=>true, so use symbols, not strings.
|
182
|
+
prodlist = [
|
183
|
+
{bizid: "XYZxyz",
|
184
|
+
type: "product",
|
185
|
+
domain: "ABCabc.m2.exosite.io",
|
186
|
+
apiId: "ABCabc",
|
187
|
+
sid: "ABCabc",
|
188
|
+
name: "XXX",
|
189
|
+
},
|
190
|
+
]
|
191
|
+
appllist = [
|
192
|
+
{bizid: "XYZxyz",
|
193
|
+
type: "application",
|
194
|
+
domain: "XYZxyz.apps.exosite.io",
|
195
|
+
apiId: "DEFdef",
|
196
|
+
sid: "DEFdef",
|
197
|
+
name: "XXX",
|
198
|
+
},
|
199
|
+
]
|
200
|
+
solnlist = prodlist + appllist
|
201
|
+
stub_request(:get, "https://bizapi.hosted.exosite.io/api:1/business/XYZxyz/solution/").
|
202
|
+
to_return(body: solnlist)
|
203
|
+
|
204
|
+
solz = []
|
205
|
+
solz << MrMurano::Product.new(prodlist[0])
|
206
|
+
solz << MrMurano::Application.new(appllist[0])
|
207
|
+
|
208
|
+
solz = @biz.solutions
|
209
|
+
expect(solz).to eq(solz)
|
210
|
+
end
|
211
|
+
|
212
|
+
it "lists solutions; without biz.id" do
|
213
|
+
allow($cfg).to receive(:get).with('business.id').and_return(nil)
|
214
|
+
expect(@biz).to receive(:debug).with("Getting all solutions of type all")
|
215
|
+
expect { @biz.solutions }.to raise_error(MISSING_BIZ_ID_MSG)
|
216
|
+
end
|
217
|
+
|
218
|
+
it "creates solution" do
|
219
|
+
stub_request(:post, "https://bizapi.hosted.exosite.io/api:1/business/XYZxyz/solution/").
|
220
|
+
with(body: {label: 'one', type: 'product',}).
|
221
|
+
to_return(body: '{"id": "abc123def456ghi78", "name": "one"}')
|
222
|
+
|
223
|
+
sol = @biz.new_solution!("one", :product)
|
224
|
+
expect(sol.valid?).to be true
|
225
|
+
expect(sol.sid).to eq("abc123def456ghi78")
|
226
|
+
end
|
227
|
+
|
228
|
+
# if false
|
229
|
+
if true
|
230
|
+
# LATER: Re-enable after upcase fixed in pegasus_registry.
|
231
|
+
it "creates solution; with upper case" do
|
232
|
+
# 2017-07-03: Murano appears to return the id nowadays, so added body.
|
233
|
+
stub_request(:post, "https://bizapi.hosted.exosite.io/api:1/business/XYZxyz/solution/").
|
234
|
+
with(:body => {:label=>'ONe', :type=>'product'}).
|
235
|
+
to_return(body: '{"id": "abc123def456ghi78", "name": "ONe"}')
|
236
|
+
|
237
|
+
expect { @biz.new_solution!("ONe", :product) }.to_not raise_error
|
238
|
+
end
|
239
|
+
else
|
240
|
+
it "creates solution; with uppercase" do
|
241
|
+
expect { @biz.new_solution!("oNeTWO", :product) }.to raise_error(
|
242
|
+
MrMurano::Product.new.name_validate_help)
|
243
|
+
end
|
244
|
+
end
|
245
|
+
|
246
|
+
it "creates solution; with numbers and dashes" do
|
247
|
+
stub_request(:post, "https://bizapi.hosted.exosite.io/api:1/business/XYZxyz/solution/").
|
248
|
+
with(:body => {:label=>'ONe-8796-gkl', :type=>'product'}).
|
249
|
+
to_return(body: '{"id": "abc123def456ghi78", "name": "ONe-8796-gkl"}')
|
250
|
+
|
251
|
+
# 2017-05-26: Dashes forbidden! MUR-1994
|
252
|
+
#expect { @biz.new_solution!("ONe-8796-gkl", :product) }.to_not raise_error
|
253
|
+
expect { @biz.new_solution!("ONe-8796-gkl", :product) }.to raise_error(
|
254
|
+
MrMurano::Product.new.name_validate_help)
|
255
|
+
end
|
256
|
+
|
257
|
+
it "creates solution; that is too long" do
|
258
|
+
expect { @biz.new_solution!("o"*70, :product) }.to raise_error(
|
259
|
+
MrMurano::Product.new.name_validate_help)
|
260
|
+
end
|
261
|
+
|
262
|
+
it "creates solution; with underscore" do
|
263
|
+
expect { @biz.new_solution!("one_two", :product) }.to raise_error(
|
264
|
+
MrMurano::Product.new.name_validate_help)
|
265
|
+
end
|
266
|
+
|
267
|
+
it "creates solution; with digit first" do
|
268
|
+
expect { @biz.new_solution!("1two", :product) }.to raise_error(
|
269
|
+
MrMurano::Product.new.name_validate_help)
|
270
|
+
end
|
271
|
+
|
272
|
+
it "creates solution; without biz.id" do
|
273
|
+
allow($cfg).to receive(:get).with('business.id').and_return(nil)
|
274
|
+
expect { @biz.new_solution!("one", :product) }.to raise_error(MISSING_BIZ_ID_MSG)
|
275
|
+
end
|
276
|
+
|
277
|
+
it "deletes solution" do
|
278
|
+
stub_request(:delete, "https://bizapi.hosted.exosite.io/api:1/business/XYZxyz/solution/one").
|
279
|
+
to_return(body: "")
|
280
|
+
|
281
|
+
ret = @biz.delete_solution("one")
|
282
|
+
expect(ret).to eq({})
|
283
|
+
end
|
284
|
+
|
285
|
+
it "deletes solution; without biz.id" do
|
286
|
+
allow($cfg).to receive(:get).with('business.id').and_return(nil)
|
287
|
+
expect { @biz.delete_solution("one") }.to raise_error(MISSING_BIZ_ID_MSG)
|
288
|
+
end
|
289
|
+
end
|
290
|
+
|