MuranoCLI 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (151) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +28 -0
  3. data/.rspec +2 -0
  4. data/.travis.yml +21 -0
  5. data/Gemfile +27 -0
  6. data/LICENSE.txt +19 -0
  7. data/MuranoCLI.gemspec +50 -0
  8. data/MuranoCLI.iss +50 -0
  9. data/README.markdown +208 -0
  10. data/Rakefile +188 -0
  11. data/TODO.taskpaper +122 -0
  12. data/bin/mr +8 -0
  13. data/bin/murano +84 -0
  14. data/docs/demo.md +109 -0
  15. data/lib/MrMurano/Account.rb +211 -0
  16. data/lib/MrMurano/Config-Migrate.rb +47 -0
  17. data/lib/MrMurano/Config.rb +286 -0
  18. data/lib/MrMurano/Mock.rb +63 -0
  19. data/lib/MrMurano/Product-1P-Device.rb +145 -0
  20. data/lib/MrMurano/Product-Resources.rb +195 -0
  21. data/lib/MrMurano/Product.rb +358 -0
  22. data/lib/MrMurano/ProjectFile.rb +349 -0
  23. data/lib/MrMurano/Solution-Cors.rb +46 -0
  24. data/lib/MrMurano/Solution-Endpoint.rb +177 -0
  25. data/lib/MrMurano/Solution-File.rb +150 -0
  26. data/lib/MrMurano/Solution-ServiceConfig.rb +140 -0
  27. data/lib/MrMurano/Solution-Services.rb +326 -0
  28. data/lib/MrMurano/Solution-Users.rb +129 -0
  29. data/lib/MrMurano/Solution.rb +59 -0
  30. data/lib/MrMurano/SubCmdGroupContext.rb +49 -0
  31. data/lib/MrMurano/SyncUpDown.rb +565 -0
  32. data/lib/MrMurano/commands/assign.rb +57 -0
  33. data/lib/MrMurano/commands/businessList.rb +45 -0
  34. data/lib/MrMurano/commands/completion.rb +152 -0
  35. data/lib/MrMurano/commands/config.rb +67 -0
  36. data/lib/MrMurano/commands/content.rb +130 -0
  37. data/lib/MrMurano/commands/cors.rb +30 -0
  38. data/lib/MrMurano/commands/domain.rb +17 -0
  39. data/lib/MrMurano/commands/gb.rb +33 -0
  40. data/lib/MrMurano/commands/init.rb +138 -0
  41. data/lib/MrMurano/commands/keystore.rb +157 -0
  42. data/lib/MrMurano/commands/logs.rb +78 -0
  43. data/lib/MrMurano/commands/mock.rb +63 -0
  44. data/lib/MrMurano/commands/password.rb +88 -0
  45. data/lib/MrMurano/commands/postgresql.rb +41 -0
  46. data/lib/MrMurano/commands/product.rb +14 -0
  47. data/lib/MrMurano/commands/productCreate.rb +39 -0
  48. data/lib/MrMurano/commands/productDelete.rb +33 -0
  49. data/lib/MrMurano/commands/productDevice.rb +84 -0
  50. data/lib/MrMurano/commands/productDeviceIdCmds.rb +86 -0
  51. data/lib/MrMurano/commands/productList.rb +45 -0
  52. data/lib/MrMurano/commands/productWrite.rb +27 -0
  53. data/lib/MrMurano/commands/show.rb +80 -0
  54. data/lib/MrMurano/commands/solution.rb +14 -0
  55. data/lib/MrMurano/commands/solutionCreate.rb +39 -0
  56. data/lib/MrMurano/commands/solutionDelete.rb +34 -0
  57. data/lib/MrMurano/commands/solutionList.rb +45 -0
  58. data/lib/MrMurano/commands/status.rb +92 -0
  59. data/lib/MrMurano/commands/sync.rb +60 -0
  60. data/lib/MrMurano/commands/timeseries.rb +115 -0
  61. data/lib/MrMurano/commands/tsdb.rb +271 -0
  62. data/lib/MrMurano/commands/usage.rb +23 -0
  63. data/lib/MrMurano/commands/zshcomplete.erb +112 -0
  64. data/lib/MrMurano/commands.rb +32 -0
  65. data/lib/MrMurano/hash.rb +20 -0
  66. data/lib/MrMurano/http.rb +153 -0
  67. data/lib/MrMurano/makePretty.rb +75 -0
  68. data/lib/MrMurano/schema/pf-v1.0.0.yaml +114 -0
  69. data/lib/MrMurano/schema/sf-v0.2.0.yaml +77 -0
  70. data/lib/MrMurano/schema/sf-v0.3.0.yaml +78 -0
  71. data/lib/MrMurano/template/mock.erb +9 -0
  72. data/lib/MrMurano/template/projectFile.murano.erb +81 -0
  73. data/lib/MrMurano/verbosing.rb +99 -0
  74. data/lib/MrMurano/version.rb +4 -0
  75. data/lib/MrMurano.rb +20 -0
  76. data/spec/Account-Passwords_spec.rb +242 -0
  77. data/spec/Account_spec.rb +272 -0
  78. data/spec/ConfigFile_spec.rb +50 -0
  79. data/spec/ConfigMigrate_spec.rb +89 -0
  80. data/spec/Config_spec.rb +409 -0
  81. data/spec/Http_spec.rb +204 -0
  82. data/spec/MakePretties_spec.rb +118 -0
  83. data/spec/Mock_spec.rb +53 -0
  84. data/spec/ProductBase_spec.rb +113 -0
  85. data/spec/ProductContent_spec.rb +162 -0
  86. data/spec/ProductResources_spec.rb +329 -0
  87. data/spec/Product_1P_Device_spec.rb +202 -0
  88. data/spec/Product_1P_RPC_spec.rb +175 -0
  89. data/spec/Product_spec.rb +153 -0
  90. data/spec/ProjectFile_spec.rb +324 -0
  91. data/spec/Solution-Cors_spec.rb +164 -0
  92. data/spec/Solution-Endpoint_spec.rb +581 -0
  93. data/spec/Solution-File_spec.rb +212 -0
  94. data/spec/Solution-ServiceConfig_spec.rb +202 -0
  95. data/spec/Solution-ServiceDevice_spec.rb +176 -0
  96. data/spec/Solution-ServiceEventHandler_spec.rb +385 -0
  97. data/spec/Solution-ServiceModules_spec.rb +465 -0
  98. data/spec/Solution-UsersRoles_spec.rb +207 -0
  99. data/spec/Solution_spec.rb +92 -0
  100. data/spec/SyncRoot_spec.rb +83 -0
  101. data/spec/SyncUpDown_spec.rb +495 -0
  102. data/spec/Verbosing_spec.rb +279 -0
  103. data/spec/_workspace.rb +27 -0
  104. data/spec/cmd_assign_spec.rb +51 -0
  105. data/spec/cmd_business_spec.rb +59 -0
  106. data/spec/cmd_common.rb +72 -0
  107. data/spec/cmd_config_spec.rb +68 -0
  108. data/spec/cmd_content_spec.rb +71 -0
  109. data/spec/cmd_cors_spec.rb +50 -0
  110. data/spec/cmd_device_spec.rb +96 -0
  111. data/spec/cmd_domain_spec.rb +32 -0
  112. data/spec/cmd_init_spec.rb +30 -0
  113. data/spec/cmd_keystore_spec.rb +97 -0
  114. data/spec/cmd_password_spec.rb +62 -0
  115. data/spec/cmd_status_spec.rb +239 -0
  116. data/spec/cmd_syncdown_spec.rb +86 -0
  117. data/spec/cmd_syncup_spec.rb +62 -0
  118. data/spec/cmd_usage_spec.rb +36 -0
  119. data/spec/fixtures/.mrmuranorc +9 -0
  120. data/spec/fixtures/ProjectFiles/invalid.yaml +9 -0
  121. data/spec/fixtures/ProjectFiles/only_meta.yaml +24 -0
  122. data/spec/fixtures/ProjectFiles/with_routes.yaml +27 -0
  123. data/spec/fixtures/SolutionFiles/0.2.0.json +20 -0
  124. data/spec/fixtures/SolutionFiles/0.2.0_invalid.json +18 -0
  125. data/spec/fixtures/SolutionFiles/0.2.json +21 -0
  126. data/spec/fixtures/SolutionFiles/0.3.0.json +20 -0
  127. data/spec/fixtures/SolutionFiles/0.3.0_invalid.json +19 -0
  128. data/spec/fixtures/SolutionFiles/0.3.json +20 -0
  129. data/spec/fixtures/SolutionFiles/basic.json +20 -0
  130. data/spec/fixtures/SolutionFiles/secret.json +6 -0
  131. data/spec/fixtures/configfile +9 -0
  132. data/spec/fixtures/dumped_config +42 -0
  133. data/spec/fixtures/mrmuranorc_deleted_bob +8 -0
  134. data/spec/fixtures/mrmuranorc_tool_bob +3 -0
  135. data/spec/fixtures/product_spec_files/example.exoline.spec.yaml +116 -0
  136. data/spec/fixtures/product_spec_files/example.murano.spec.yaml +14 -0
  137. data/spec/fixtures/product_spec_files/gwe.exoline.spec.yaml +21 -0
  138. data/spec/fixtures/product_spec_files/gwe.murano.spec.yaml +16 -0
  139. data/spec/fixtures/product_spec_files/lightbulb-no-state.yaml +11 -0
  140. data/spec/fixtures/product_spec_files/lightbulb.yaml +14 -0
  141. data/spec/fixtures/roles-three.yaml +11 -0
  142. data/spec/fixtures/syncable_content/assets/icon.png +0 -0
  143. data/spec/fixtures/syncable_content/assets/index.html +0 -0
  144. data/spec/fixtures/syncable_content/assets/js/script.js +0 -0
  145. data/spec/fixtures/syncable_content/modules/table_util.lua +58 -0
  146. data/spec/fixtures/syncable_content/routes/manyRoutes.lua +11 -0
  147. data/spec/fixtures/syncable_content/routes/singleRoute.lua +5 -0
  148. data/spec/fixtures/syncable_content/services/devdata.lua +18 -0
  149. data/spec/fixtures/syncable_content/services/timers.lua +4 -0
  150. data/spec/spec_helper.rb +119 -0
  151. metadata +498 -0
@@ -0,0 +1,202 @@
1
+ require 'MrMurano/version'
2
+ require 'MrMurano/Config'
3
+ require 'MrMurano/Product-1P-Device'
4
+ require '_workspace'
5
+
6
+ RSpec.describe MrMurano::Product1PDevice, '#sn_rid tests' do
7
+ include_context "WORKSPACE"
8
+ before(:example) do
9
+ $cfg = MrMurano::Config.new
10
+ $cfg.load
11
+ $project = MrMurano::ProjectFile.new
12
+ $project.load
13
+ $cfg['net.host'] = 'bizapi.hosted.exosite.io'
14
+ $cfg['product.id'] = 'XYZ'
15
+ $cfg['product.spec'] = 'XYZ.yaml'
16
+
17
+ @prd = MrMurano::Product1PDevice.new
18
+ allow(@prd).to receive(:token).and_return("TTTTTTTTTT")
19
+ @mrp = instance_double("MrMurano::Product")
20
+ allow(MrMurano::Product).to receive(:new).and_return(@mrp)
21
+ end
22
+
23
+ it "gets rid from sn" do
24
+ expect(@mrp).to receive(:list).once.and_return([
25
+ {:sn=>"12",
26
+ :status=>"activated",
27
+ :rid=>"77cbf643ZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZ"}])
28
+ ret = @prd.sn_rid("12")
29
+ expect(ret).to eq("77cbf643ZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZ")
30
+ end
31
+
32
+ it "gets rid from sn on page two" do
33
+ expect(@mrp).to receive(:list).twice.and_return(
34
+ [{:sn=>"14",
35
+ :status=>"notactivated"}],
36
+ [{:sn=>"12",
37
+ :status=>"activated",
38
+ :rid=>"77cbf643ZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZ"}])
39
+
40
+ ret = @prd.sn_rid("12")
41
+ expect(ret).to eq("77cbf643ZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZ")
42
+ end
43
+
44
+ it "doesn't find the sn" do
45
+ expect(@mrp).to receive(:list).twice.and_return(
46
+ [{:sn=>"14",
47
+ :status=>"notactivated"}],
48
+ [])
49
+
50
+ expect {
51
+ @prd.sn_rid("12")
52
+ }.to raise_error "Identifier Not Found: 12"
53
+ end
54
+
55
+ it "gets model_rid" do
56
+ expect(@mrp).to receive(:info).once.and_return({:modelrid=>"1234567890"})
57
+ ret = @prd.model_rid
58
+ expect(ret).to eq("1234567890")
59
+ end
60
+ it "raises with bad model_rid" do
61
+ expect(@mrp).to receive(:info).once.and_return({:mid=>"1234567890"})
62
+ expect {
63
+ @prd.model_rid
64
+ }.to raise_error(/^Bad info; .*/)
65
+ end
66
+ end
67
+
68
+ RSpec.describe MrMurano::Product1PDevice do
69
+ include_context "WORKSPACE"
70
+ before(:example) do
71
+ $cfg = MrMurano::Config.new
72
+ $cfg.load
73
+ $project = MrMurano::ProjectFile.new
74
+ $project.load
75
+ $cfg['net.host'] = 'bizapi.hosted.exosite.io'
76
+ $cfg['product.id'] = 'XYZ'
77
+ $cfg['product.spec'] = 'XYZ.yaml'
78
+
79
+ @prd = MrMurano::Product1PDevice.new
80
+ allow(@prd).to receive(:token).and_return("TTTTTTTTTT")
81
+ allow(@prd).to receive(:sn_rid).and_return("LLLLLLLLLL")
82
+ end
83
+
84
+ it "initializes" do
85
+ uri = @prd.endPoint('')
86
+ expect(uri.to_s).to eq("https://bizapi.hosted.exosite.io/api:1/product/XYZ/proxy/onep:v1/rpc/process")
87
+ end
88
+
89
+ it "gets info" do
90
+ stub_request(:post, "https://bizapi.hosted.exosite.io/api:1/product/XYZ/proxy/onep:v1/rpc/process").
91
+ with(body: {:auth=>{:client_id=>"LLLLLLLLLL"},
92
+ :calls=>[{:id=>1,
93
+ :procedure=>"info",
94
+ :arguments=>["LLLLLLLLLL", {}]} ]}).
95
+ to_return(body: [{:id=>1, :status=>"ok", :result=>{:comments=>[]}}])
96
+
97
+ ret = @prd.info("12")
98
+ expect(ret).to eq({:comments=>[]})
99
+ end
100
+
101
+ it "lists resources" do
102
+ stub_request(:post, "https://bizapi.hosted.exosite.io/api:1/product/XYZ/proxy/onep:v1/rpc/process").
103
+ with(body: {:auth=>{:client_id=>"LLLLLLLLLL"},
104
+ :calls=>[{:id=>1,
105
+ :procedure=>"info",
106
+ :arguments=>["LLLLLLLLLL", {}]} ]}).
107
+ to_return(body: [{:id=>1, :status=>"ok", :result=>{:aliases=>{
108
+ :s2143rt4regf=>["one"],:njilh32o78rnq=>["two"]}}}])
109
+
110
+ ret = @prd.list("12")
111
+ expect(ret).to eq({"one"=>"s2143rt4regf", "two"=>"njilh32o78rnq"})
112
+ end
113
+
114
+ context "reads resources" do
115
+ it "single" do
116
+ stub_request(:post, "https://bizapi.hosted.exosite.io/api:1/product/XYZ/proxy/onep:v1/rpc/process").
117
+ with(body: {:auth=>{:client_id=>"LLLLLLLLLL"},
118
+ :calls=>[{:id=>1,
119
+ :procedure=>"read",
120
+ :arguments=>[{"alias"=>"one"}, {}]} ]}).
121
+ to_return(body: [{:id=>1, :status=>"ok", :result=>[ [12345678,10] ]}])
122
+ ret = @prd.read("12", "one")
123
+ expect(ret).to eq([10])
124
+ end
125
+
126
+ it "multiple" do
127
+ stub_request(:post, "https://bizapi.hosted.exosite.io/api:1/product/XYZ/proxy/onep:v1/rpc/process").
128
+ with(body: {:auth=>{:client_id=>"LLLLLLLLLL"},
129
+ :calls=>[{:id=>1,
130
+ :procedure=>"read",
131
+ :arguments=>[{"alias"=>"two"}, {}]},
132
+ {:id=>2,
133
+ :procedure=>"read",
134
+ :arguments=>[{"alias"=>"three"}, {}]},
135
+ {:id=>3,
136
+ :procedure=>"read",
137
+ :arguments=>[{"alias"=>"one"}, {}]},
138
+ ]}).
139
+ to_return(body: [
140
+ {:id=>1, :status=>"ok", :result=>[ [12345678,10] ]},
141
+ {:id=>2, :status=>"ok", :result=>[ [12345678,15] ]},
142
+ {:id=>3, :status=>"ok", :result=>[ [12345678,20] ]},
143
+ ])
144
+ ret = @prd.read("12", ["two","three","one"])
145
+ expect(ret).to eq([10,15,20])
146
+ end
147
+
148
+ end
149
+
150
+ it "gets tree info for device" do
151
+ # this makes three https calls, info on root, info and read on children
152
+
153
+ # root info.
154
+ stub_request(:post, "https://bizapi.hosted.exosite.io/api:1/product/XYZ/proxy/onep:v1/rpc/process").
155
+ with(body: {:auth=>{:client_id=>"LLLLLLLLLL"},
156
+ :calls=>[{:id=>1,
157
+ :procedure=>"info",
158
+ :arguments=>["LLLLLLLLLL", {}]} ]}).
159
+ to_return(body: [{:id=>1, :status=>"ok", :result=>{:aliases=>{
160
+ :s2143rt4regf=>["one"],:njilh32o78rnq=>["two"]}}}])
161
+
162
+ # children info
163
+ stub_request(:post, "https://bizapi.hosted.exosite.io/api:1/product/XYZ/proxy/onep:v1/rpc/process").
164
+ with(body: {:auth=>{:client_id=>"LLLLLLLLLL"},
165
+ :calls=>[{:id=>1,
166
+ :procedure=>"info",
167
+ :arguments=>["s2143rt4regf", {}]},
168
+ {:id=>2,
169
+ :procedure=>"info",
170
+ :arguments=>["njilh32o78rnq", {}]}
171
+ ]}).
172
+ to_return(body: [
173
+ {:id=>1, :status=>"ok", :result=>{:basic=>{:type=>"dataport"}}},
174
+ {:id=>2, :status=>"ok", :result=>{:basic=>{:type=>"dataport"}}}
175
+ ])
176
+
177
+ # children read
178
+ stub_request(:post, "https://bizapi.hosted.exosite.io/api:1/product/XYZ/proxy/onep:v1/rpc/process").
179
+ with(body: {:auth=>{:client_id=>"LLLLLLLLLL"},
180
+ :calls=>[{:id=>1,
181
+ :procedure=>"read",
182
+ :arguments=>["s2143rt4regf", {}]},
183
+ {:id=>2,
184
+ :procedure=>"read",
185
+ :arguments=>["njilh32o78rnq", {}]},
186
+ ]}).
187
+ to_return(body: [
188
+ {:id=>1, :status=>"ok", :result=>[ [12345678,10] ]},
189
+ {:id=>2, :status=>"ok", :result=>[ [12345678,15] ]},
190
+ ])
191
+
192
+ ret = @prd.twee('12')
193
+ expect(ret).to eq({:children=>[{:basic=>{:type=>"dataport"},
194
+ :rid=>:s2143rt4regf, :alias=>"one", :value=>10},
195
+ {:basic=>{:type=>"dataport"},
196
+ :rid=>:njilh32o78rnq, :alias=>"two",
197
+ :value=>15}]})
198
+ end
199
+
200
+ end
201
+
202
+ # vim: set ai et sw=2 ts=2 :
@@ -0,0 +1,175 @@
1
+ require 'MrMurano/version'
2
+ require 'MrMurano/Config'
3
+ require 'MrMurano/Product-Resources'
4
+ require '_workspace'
5
+
6
+ RSpec.describe MrMurano::ProductResources, "#1PshimTests" do
7
+ include_context "WORKSPACE"
8
+ before(:example) do
9
+ $cfg = MrMurano::Config.new
10
+ $cfg.load
11
+ $cfg['net.host'] = 'bizapi.hosted.exosite.io'
12
+ $cfg['product.id'] = 'XYZ'
13
+ $cfg['product.spec'] = 'XYZ.yaml'
14
+
15
+ @prd = MrMurano::ProductResources.new
16
+ allow(@prd).to receive(:token).and_return("TTTTTTTTTT")
17
+ allow(@prd).to receive(:model_rid).and_return("LLLLLLLLLL")
18
+ end
19
+
20
+ context "do_rpc" do
21
+ # Note, do_rpc is private.
22
+ it "Accepts an object" do
23
+ stub_request(:post, "https://bizapi.hosted.exosite.io/api:1/product/XYZ/proxy/onep:v1/rpc/process").
24
+ to_return(body: [{
25
+ :id=>1, :status=>"ok", :result=>{}
26
+ }])
27
+
28
+ ret = nil
29
+ @prd.instance_eval{ ret = do_rpc({:id=>1}) }
30
+ expect(ret).to eq({})
31
+ end
32
+
33
+ it "Accepts an Array" do
34
+ stub_request(:post, "https://bizapi.hosted.exosite.io/api:1/product/XYZ/proxy/onep:v1/rpc/process").
35
+ to_return(body: [{:id=>1, :status=>"ok", :result=>{:one=>1}},
36
+ {:id=>2, :status=>"ok", :result=>{:two=>2}}])
37
+
38
+ ret = nil
39
+ @prd.instance_eval{ ret = do_rpc([{:id=>1}, {:id=>2}]) }
40
+ expect(ret).to eq({:one=>1})
41
+ # yes it only returns first.
42
+ end
43
+
44
+ it "returns res if not Array" do
45
+ stub_request(:post, "https://bizapi.hosted.exosite.io/api:1/product/XYZ/proxy/onep:v1/rpc/process").
46
+ to_return(body: {:not=>'an array'}.to_json)
47
+
48
+ ret = nil
49
+ @prd.instance_eval{ ret = do_rpc({:id=>1}) }
50
+ expect(ret).to eq({:not=>'an array'})
51
+ end
52
+
53
+ it "returns res if count less than 1" do
54
+ stub_request(:post, "https://bizapi.hosted.exosite.io/api:1/product/XYZ/proxy/onep:v1/rpc/process").
55
+ to_return(body: [])
56
+
57
+ ret = nil
58
+ @prd.instance_eval{ ret = do_rpc({:id=>1}) }
59
+ expect(ret).to eq([])
60
+ end
61
+
62
+ it "returns res[0] if not Hash" do
63
+ stub_request(:post, "https://bizapi.hosted.exosite.io/api:1/product/XYZ/proxy/onep:v1/rpc/process").
64
+ to_return(body: ["foo"])
65
+
66
+ ret = nil
67
+ @prd.instance_eval{ ret = do_rpc({:id=>1}) }
68
+ expect(ret).to eq("foo")
69
+ end
70
+
71
+ it "returns res[0] if not status ok" do
72
+ stub_request(:post, "https://bizapi.hosted.exosite.io/api:1/product/XYZ/proxy/onep:v1/rpc/process").
73
+ to_return(body: [{:id=>1, :status=>'error'}])
74
+
75
+ ret = nil
76
+ @prd.instance_eval{ ret = do_rpc({:id=>1}) }
77
+ expect(ret).to eq({:id=>1, :status=>'error'})
78
+ end
79
+ end
80
+
81
+ context "do_mrpc" do
82
+ # Note, do_rpc is private.
83
+ it "Accepts an object" do
84
+ stub_request(:post, "https://bizapi.hosted.exosite.io/api:1/product/XYZ/proxy/onep:v1/rpc/process").
85
+ to_return(body: [{
86
+ :id=>1, :status=>"ok", :result=>{}
87
+ }])
88
+
89
+ ret = nil
90
+ @prd.instance_eval{ ret = do_mrpc({:id=>1}) }
91
+ expect(ret).to eq([{:id=>1, :status=>"ok", :result=>{}}])
92
+ end
93
+
94
+ it "Accepts an Array" do
95
+ stub_request(:post, "https://bizapi.hosted.exosite.io/api:1/product/XYZ/proxy/onep:v1/rpc/process").
96
+ to_return(body: [{:id=>1, :status=>"ok", :result=>{:one=>1}},
97
+ {:id=>2, :status=>"ok", :result=>{:two=>2}}])
98
+
99
+ ret = nil
100
+ @prd.instance_eval{ ret = do_mrpc([{:id=>1}, {:id=>2}]) }
101
+ expect(ret).to eq([{:id=>1, :status=>"ok", :result=>{:one=>1}},
102
+ {:id=>2, :status=>"ok", :result=>{:two=>2}}])
103
+ end
104
+
105
+ it "fills in all ids if missing" do
106
+ stub_request(:post, "https://bizapi.hosted.exosite.io/api:1/product/XYZ/proxy/onep:v1/rpc/process").
107
+ to_return(body: [{:id=>1, :status=>"ok", :result=>{:one=>1}},
108
+ {:id=>2, :status=>"ok", :result=>{:two=>2}},
109
+ {:id=>3, :status=>"ok", :result=>{:three=>3}}])
110
+
111
+ ret = nil
112
+ @prd.instance_eval{ ret = do_mrpc([{}, {}, {}]) }
113
+ expect(ret).to eq([{:id=>1, :status=>"ok", :result=>{:one=>1}},
114
+ {:id=>2, :status=>"ok", :result=>{:two=>2}},
115
+ {:id=>3, :status=>"ok", :result=>{:three=>3}}])
116
+ end
117
+
118
+ it "fills in missing ids" do
119
+ stub_request(:post, "https://bizapi.hosted.exosite.io/api:1/product/XYZ/proxy/onep:v1/rpc/process").
120
+ with(body: {:auth=>{:client_id=>"LLLLLLLLLL"},
121
+ :calls=>[{:id=>5, :procedure=>"info"},
122
+ {:id=>4, :procedure=>"info"},
123
+ {:id=>6, :procedure=>"info"} ]}).
124
+ to_return(body: [{:id=>5, :status=>"ok", :result=>{:one=>1}},
125
+ {:id=>4, :status=>"ok", :result=>{:two=>2}},
126
+ {:id=>6, :status=>"ok", :result=>{:three=>3}}])
127
+
128
+ ret = nil
129
+ @prd.instance_eval{ ret = do_mrpc([{:procedure=>"info"},
130
+ {:procedure=>"info", :id=>4},
131
+ {:procedure=>"info"}]) }
132
+ expect(ret).to eq([{:id=>5, :status=>"ok", :result=>{:one=>1}},
133
+ {:id=>4, :status=>"ok", :result=>{:two=>2}},
134
+ {:id=>6, :status=>"ok", :result=>{:three=>3}}])
135
+ end
136
+
137
+ it "returns res if not Array" do
138
+ stub_request(:post, "https://bizapi.hosted.exosite.io/api:1/product/XYZ/proxy/onep:v1/rpc/process").
139
+ to_return(body: {:not=>'an array'}.to_json)
140
+
141
+ ret = nil
142
+ @prd.instance_eval{ ret = do_mrpc({:id=>1}) }
143
+ expect(ret).to eq({:not=>'an array'})
144
+ end
145
+
146
+ it "returns res if count less than 1" do
147
+ stub_request(:post, "https://bizapi.hosted.exosite.io/api:1/product/XYZ/proxy/onep:v1/rpc/process").
148
+ to_return(body: [])
149
+
150
+ ret = nil
151
+ @prd.instance_eval{ ret = do_mrpc({:id=>1}) }
152
+ expect(ret).to eq([])
153
+ end
154
+
155
+ it "returns res[0] if not Hash" do
156
+ stub_request(:post, "https://bizapi.hosted.exosite.io/api:1/product/XYZ/proxy/onep:v1/rpc/process").
157
+ to_return(body: ["foo"])
158
+
159
+ ret = nil
160
+ @prd.instance_eval{ ret = do_mrpc({:id=>1}) }
161
+ expect(ret).to eq(["foo"])
162
+ end
163
+
164
+ it "returns res[0] if not status ok" do
165
+ stub_request(:post, "https://bizapi.hosted.exosite.io/api:1/product/XYZ/proxy/onep:v1/rpc/process").
166
+ to_return(body: [{:id=>1, :status=>'error'}])
167
+
168
+ ret = nil
169
+ @prd.instance_eval{ ret = do_mrpc({:id=>1}) }
170
+ expect(ret).to eq([{:id=>1, :status=>'error'}])
171
+ end
172
+ end
173
+ end
174
+
175
+ # vim: set ai et sw=2 ts=2 :
@@ -0,0 +1,153 @@
1
+ require 'MrMurano/version'
2
+ require 'MrMurano/Config'
3
+ require 'MrMurano/Product'
4
+ require '_workspace'
5
+
6
+ RSpec.describe MrMurano::Product, "#product" do
7
+ include_context "WORKSPACE"
8
+ before(:example) do
9
+ $cfg = MrMurano::Config.new
10
+ $cfg.load
11
+ $cfg['net.host'] = 'bizapi.hosted.exosite.io'
12
+ $cfg['product.id'] = 'XYZ'
13
+
14
+ @prd = MrMurano::Product.new
15
+ allow(@prd).to receive(:token).and_return("TTTTTTTTTT")
16
+ end
17
+
18
+ it "returns info" do
19
+ stub_request(:get, "https://bizapi.hosted.exosite.io/api:1/product/XYZ/info").
20
+ with(:headers=>{'Authorization'=>'token TTTTTTTTTT',
21
+ 'Content-Type'=>'application/json'}).
22
+ to_return(body: {
23
+ "id"=> "<id>",
24
+ "bizid"=>"<bizid>",
25
+ "label"=> "<label>",
26
+ "endpoint"=> "<endpoint>",
27
+ "rid"=> "<rid>",
28
+ "modelrid"=> "<rid>",
29
+ "resources"=> [{
30
+ "alias"=> "<alias>",
31
+ "format"=> "<format>",
32
+ "rid"=> "<rid>"
33
+ }]
34
+ }.to_json)
35
+
36
+ ret = @prd.info()
37
+ expect(ret).to eq({
38
+ :id=> "<id>",
39
+ :bizid=>"<bizid>",
40
+ :label=> "<label>",
41
+ :endpoint=> "<endpoint>",
42
+ :rid=> "<rid>",
43
+ :modelrid=> "<rid>",
44
+ :resources=> [{
45
+ :alias=> "<alias>",
46
+ :format=> "<format>",
47
+ :rid=> "<rid>"
48
+ }]
49
+ })
50
+ end
51
+
52
+ it "Can list devices" do
53
+ stub_request(:get, "https://bizapi.hosted.exosite.io/api:1/product/XYZ/device/").
54
+ with(query: {'limit'=>50, 'offset'=>0}).
55
+ with(headers: {'Authorization'=>'token TTTTTTTTTT',
56
+ 'Content-Type'=>'application/json'}).
57
+ to_return(body: [{:sn=>"009",
58
+ :status=>"activated",
59
+ :rid=>"XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"}].to_json)
60
+ ret = @prd.list()
61
+ expect(ret).to eq([{:sn=>"009",
62
+ :status=>"activated",
63
+ :rid=>"XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"}])
64
+ end
65
+
66
+ it "can enable" do
67
+ stub_request(:post, "https://bizapi.hosted.exosite.io/api:1/product/XYZ/device/42").
68
+ with(headers: {'Authorization'=>'token TTTTTTTTTT',
69
+ 'Content-Type'=>'application/json'}).
70
+ to_return(body: {:sn=> "<sn>", :status=> "<status>", :rid=> "<devicerid>"}.to_json)
71
+
72
+ ret = @prd.enable(42)
73
+ expect(ret).to eq({:sn=> "<sn>", :status=> "<status>", :rid=> "<devicerid>"})
74
+ end
75
+
76
+ it "can update definition" do
77
+ rbody = [
78
+ {:alias=>"state",
79
+ :rid=>"755857c8df71bb0cfe82773b8ba35236ae70fd77"},
80
+ {:alias=>"temperature",
81
+ :rid=>"6eee2542ec5f1dc7d27e46b90f3dc054a8dadab7"},
82
+ {:alias=>"uptime",
83
+ :rid=>"196c2077557c1924b0d8b75c6c1f6df104f251a6"},
84
+ {:alias=>"humidity",
85
+ :rid=>"49e7d53b6ed3c80ece619ac4878fbdb0bb95aa80"}
86
+ ]
87
+ stub_request(:post, "https://bizapi.hosted.exosite.io/api:1/product/XYZ/definition").
88
+ with(headers: {'Authorization'=>'token TTTTTTTTTT',
89
+ 'Content-Type'=>'text/yaml'}).
90
+ to_return(body: rbody.to_json)
91
+
92
+ # Open test file sepc.yaml
93
+ pth = (@testdir + 'spec/fixtures/product_spec_files/lightbulb.yaml').realpath
94
+ ret = @prd.update(pth)
95
+ expect(ret).to eq(rbody)
96
+ end
97
+
98
+ it "can write" do
99
+ stub_request(:post, "https://bizapi.hosted.exosite.io/api:1/product/XYZ/write/42").
100
+ with(headers: {'Authorization'=>'token TTTTTTTTTT',
101
+ 'Content-Type'=>'application/json'}).
102
+ to_return(body: {:temp=> "ok", :humid=> "ok"}.to_json)
103
+
104
+ ret = @prd.write(42, {:temp=>78, :humid=>50})
105
+ expect(ret).to eq({:temp=> "ok", :humid=> "ok"})
106
+ end
107
+
108
+ context "converting a specFile" do
109
+ it "can convert a file" do
110
+ epth = (@testdir + 'spec/fixtures/product_spec_files/gwe.exoline.spec.yaml').realpath
111
+ mpth = (@testdir + 'spec/fixtures/product_spec_files/gwe.murano.spec.yaml').realpath
112
+ out = @prd.convert(epth)
113
+ want = mpth.read
114
+
115
+ expect(out).to eq(want)
116
+ end
117
+
118
+ it "can convert stdin" do
119
+ epth = (@testdir + 'spec/fixtures/product_spec_files/gwe.exoline.spec.yaml').realpath
120
+ mpth = (@testdir + 'spec/fixtures/product_spec_files/gwe.murano.spec.yaml').realpath
121
+ epth.open do |fin|
122
+ begin
123
+ $stdin = fin
124
+ out = @prd.convert('-')
125
+ want = mpth.read
126
+
127
+ expect(out).to eq(want)
128
+ ensure
129
+ $stdin = STDIN
130
+ end
131
+ end
132
+ end
133
+
134
+ it "converts a fully featured exoline spec file" do
135
+ epth = (@testdir + 'spec/fixtures/product_spec_files/example.exoline.spec.yaml').realpath
136
+ mpth = (@testdir + 'spec/fixtures/product_spec_files/example.murano.spec.yaml').realpath
137
+ out = @prd.convert(epth)
138
+ want = mpth.read
139
+
140
+ expect(out).to eq(want)
141
+ end
142
+
143
+ it "raises when not an exoline spec" do
144
+ expect {
145
+ pth = @testdir + 'spec/fixtures/product_spec_files/example.murano.spec.yaml'
146
+ @prd.convert(pth.realpath)
147
+ }.to raise_exception('No dataports section found, or not an array')
148
+ end
149
+ end
150
+
151
+ end
152
+
153
+ # vim: set ai et sw=2 ts=2 :