MrMurano 1.11.3 → 1.12.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (53) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +1 -0
  3. data/Gemfile +2 -0
  4. data/README.markdown +12 -14
  5. data/Rakefile +2 -2
  6. data/TODO.taskpaper +8 -6
  7. data/docs/demo.md +109 -0
  8. data/lib/MrMurano/Account.rb +6 -3
  9. data/lib/MrMurano/Config.rb +13 -37
  10. data/lib/MrMurano/Product-1P-Device.rb +2 -0
  11. data/lib/MrMurano/Product-Resources.rb +5 -4
  12. data/lib/MrMurano/Product.rb +3 -3
  13. data/lib/MrMurano/Solution-File.rb +1 -2
  14. data/lib/MrMurano/Solution-ServiceConfig.rb +11 -1
  15. data/lib/MrMurano/Solution-Services.rb +24 -7
  16. data/lib/MrMurano/Solution-Users.rb +6 -4
  17. data/lib/MrMurano/SyncUpDown.rb +67 -28
  18. data/lib/MrMurano/commands/config.rb +4 -1
  19. data/lib/MrMurano/commands/exportImport.rb +3 -0
  20. data/lib/MrMurano/hash.rb +2 -0
  21. data/lib/MrMurano/http.rb +3 -3
  22. data/lib/MrMurano/verbosing.rb +9 -3
  23. data/lib/MrMurano/version.rb +1 -1
  24. data/spec/Account_spec.rb +104 -0
  25. data/spec/Config_spec.rb +202 -57
  26. data/spec/Http_spec.rb +204 -0
  27. data/spec/MakePretties_spec.rb +35 -0
  28. data/spec/Mock_spec.rb +13 -20
  29. data/spec/ProductBase_spec.rb +2 -0
  30. data/spec/ProductContent_spec.rb +77 -12
  31. data/spec/ProductResources_spec.rb +235 -0
  32. data/spec/Product_1P_Device_spec.rb +62 -0
  33. data/spec/Product_1P_RPC_spec.rb +2 -0
  34. data/spec/Product_spec.rb +18 -8
  35. data/spec/Solution-Cors_spec.rb +28 -1
  36. data/spec/Solution-Endpoint_spec.rb +250 -33
  37. data/spec/Solution-File_spec.rb +210 -0
  38. data/spec/Solution-ServiceConfig_spec.rb +2 -0
  39. data/spec/Solution-ServiceDevice_spec.rb +174 -0
  40. data/spec/Solution-ServiceEventHandler_spec.rb +134 -1
  41. data/spec/Solution-ServiceModules_spec.rb +317 -64
  42. data/spec/Solution-UsersRoles_spec.rb +207 -0
  43. data/spec/Solution_spec.rb +90 -0
  44. data/spec/SyncRoot_spec.rb +52 -46
  45. data/spec/SyncUpDown_spec.rb +364 -0
  46. data/spec/Verbosing_spec.rb +279 -0
  47. data/spec/_workspace.rb +27 -0
  48. data/spec/fixtures/dumped_config +47 -0
  49. data/spec/fixtures/product_spec_files/lightbulb-no-state.yaml +11 -0
  50. data/spec/fixtures/product_spec_files/lightbulb.yaml +2 -0
  51. data/spec/fixtures/roles-three.yaml +11 -0
  52. data/spec/spec_helper.rb +9 -0
  53. metadata +26 -2
@@ -0,0 +1,174 @@
1
+ require 'MrMurano/version'
2
+ require 'MrMurano/Solution-ServiceConfig'
3
+ require 'tempfile'
4
+ require '_workspace'
5
+
6
+ RSpec.describe MrMurano::SC_Device 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['solution.id'] = 'XYZ'
13
+
14
+ @srv = MrMurano::SC_Device.new
15
+ allow(@srv).to receive(:token).and_return("TTTTTTTTTT")
16
+ end
17
+
18
+ it "initializes" do
19
+ uri = @srv.endPoint('/')
20
+ expect(uri.to_s).to eq("https://bizapi.hosted.exosite.io/api:1/solution/XYZ/serviceconfig/")
21
+ end
22
+
23
+ it "lists triggers; with scid lookup" do
24
+ body = {:items=>[{
25
+ :id => "624098f1",
26
+ :name => "Device Gateway Service",
27
+ :alias => "XYZ_device",
28
+ :solution_id => "XYZ",
29
+ :quota => {},
30
+ :service => "device",
31
+ :status => "ready",
32
+ :created_at => "2016-07-13T19:24:14.206Z",
33
+ :updated_at => "2016-08-01T15:44:11.433Z",
34
+ :deleted_at => nil
35
+ }], :total=>1}
36
+ stub_request(:get, "https://bizapi.hosted.exosite.io/api:1/solution/XYZ/serviceconfig").
37
+ with(:headers=>{'Authorization'=>'token TTTTTTTTTT',
38
+ 'Content-Type'=>'application/json'}).
39
+ to_return(body: body.to_json)
40
+
41
+
42
+ body = {
43
+ :id => "624098f1",
44
+ :alias => "XYZ_device",
45
+ :name => "Device Gateway Service",
46
+ :status => "ready",
47
+ :solution_id => "XYZ",
48
+ :service => "device",
49
+ :parameters => {
50
+ :bizid => "ABCDEFG",
51
+ },
52
+ :triggers => {
53
+ :pid => [
54
+ "LMNOP"
55
+ ]
56
+ },
57
+ :quota => {},
58
+ :created_at => "2016-07-13T19:24:14.206Z",
59
+ :updated_at => "2016-08-01T15:44:11.433Z",
60
+ :deleted_at => nil
61
+ }
62
+ stub_request(:get, "https://bizapi.hosted.exosite.io/api:1/solution/XYZ/serviceconfig/624098f1").
63
+ with(:headers => {'Authorization'=>'token TTTTTTTTTT',
64
+ 'Content-Type'=>'application/json'}).
65
+ to_return(:body => body.to_json)
66
+
67
+ ret = @srv.showTriggers
68
+ expect(ret).to eq(["LMNOP"])
69
+ end
70
+
71
+ it "lists triggers" do
72
+ expect(@srv).to receive(:scid).once.and_return('624098f1')
73
+ body = {
74
+ :id => "624098f1",
75
+ :alias => "XYZ_device",
76
+ :name => "Device Gateway Service",
77
+ :status => "ready",
78
+ :solution_id => "XYZ",
79
+ :service => "device",
80
+ :parameters => {
81
+ :bizid => "ABCDEFG",
82
+ },
83
+ :triggers => {
84
+ :pid => [
85
+ "LMNOP"
86
+ ]
87
+ },
88
+ :quota => {},
89
+ :created_at => "2016-07-13T19:24:14.206Z",
90
+ :updated_at => "2016-08-01T15:44:11.433Z",
91
+ :deleted_at => nil
92
+ }
93
+ stub_request(:get, "https://bizapi.hosted.exosite.io/api:1/solution/XYZ/serviceconfig/624098f1").
94
+ with(:headers => {'Authorization'=>'token TTTTTTTTTT',
95
+ 'Content-Type'=>'application/json'}).
96
+ to_return(:body => body.to_json)
97
+
98
+ ret = @srv.showTriggers
99
+ expect(ret).to eq(["LMNOP"])
100
+ end
101
+
102
+ it "assigns trigger" do
103
+ expect(@srv).to receive(:scid).twice.and_return('624098f1')
104
+ body = {
105
+ :id => "624098f1",
106
+ :alias => "XYZ_device",
107
+ :name => "Device Gateway Service",
108
+ :status => "ready",
109
+ :solution_id => "XYZ",
110
+ :service => "device",
111
+ :parameters => {
112
+ :bizid => "ABCDEFG",
113
+ },
114
+ :triggers => {
115
+ :pid => [
116
+ "LMNOP"
117
+ ]
118
+ },
119
+ :quota => {},
120
+ :created_at => "2016-07-13T19:24:14.206Z",
121
+ :updated_at => "2016-08-01T15:44:11.433Z",
122
+ :deleted_at => nil
123
+ }
124
+ stub_request(:get, "https://bizapi.hosted.exosite.io/api:1/solution/XYZ/serviceconfig/624098f1").
125
+ with(:headers => {'Authorization'=>'token TTTTTTTTTT',
126
+ 'Content-Type'=>'application/json'}).
127
+ to_return(:body => body.to_json)
128
+
129
+ stub_request(:put, "https://bizapi.hosted.exosite.io/api:1/solution/XYZ/serviceconfig/624098f1").
130
+ with(:headers => {'Authorization'=>'token TTTTTTTTTT',
131
+ 'Content-Type'=>'application/json'}).
132
+ to_return(:body => '')
133
+
134
+ ret = @srv.assignTriggers('OTTF')
135
+ expect(ret).to eq({})
136
+ end
137
+
138
+ it "assigns multiple triggers" do
139
+ expect(@srv).to receive(:scid).twice.and_return('624098f1')
140
+ body = {
141
+ :id => "624098f1",
142
+ :alias => "XYZ_device",
143
+ :name => "Device Gateway Service",
144
+ :status => "ready",
145
+ :solution_id => "XYZ",
146
+ :service => "device",
147
+ :parameters => {
148
+ :bizid => "ABCDEFG",
149
+ },
150
+ :triggers => {
151
+ :pid => [
152
+ "LMNOP"
153
+ ]
154
+ },
155
+ :quota => {},
156
+ :created_at => "2016-07-13T19:24:14.206Z",
157
+ :updated_at => "2016-08-01T15:44:11.433Z",
158
+ :deleted_at => nil
159
+ }
160
+ stub_request(:get, "https://bizapi.hosted.exosite.io/api:1/solution/XYZ/serviceconfig/624098f1").
161
+ with(:headers => {'Authorization'=>'token TTTTTTTTTT',
162
+ 'Content-Type'=>'application/json'}).
163
+ to_return(:body => body.to_json)
164
+
165
+ stub_request(:put, "https://bizapi.hosted.exosite.io/api:1/solution/XYZ/serviceconfig/624098f1").
166
+ with(:headers => {'Authorization'=>'token TTTTTTTTTT',
167
+ 'Content-Type'=>'application/json'}).
168
+ to_return(:body => '')
169
+
170
+ ret = @srv.assignTriggers(['OTTF', '1234'])
171
+ expect(ret).to eq({})
172
+ end
173
+ end
174
+ # vim: set ai et sw=2 ts=2 :
@@ -1,8 +1,10 @@
1
1
  require 'MrMurano/version'
2
2
  require 'MrMurano/Solution-Services'
3
3
  require 'tempfile'
4
+ require '_workspace'
4
5
 
5
6
  RSpec.describe MrMurano::EventHandler do
7
+ include_context "WORKSPACE"
6
8
  before(:example) do
7
9
  $cfg = MrMurano::Config.new
8
10
  $cfg.load
@@ -62,6 +64,32 @@ RSpec.describe MrMurano::EventHandler do
62
64
  expect(ret).to eq(body[:script])
63
65
  end
64
66
 
67
+ it "fetches, with header into block" do
68
+ body = {:id=>"9K0",
69
+ :name=>"debug",
70
+ :alias=>"XYZ_debug",
71
+ :solution_id=>"XYZ",
72
+ :service=>"device",
73
+ :event=>"datapoint",
74
+ :created_at=>"2016-07-07T19:16:19.479Z",
75
+ :updated_at=>"2016-09-12T13:26:55.868Z",
76
+ :script=>%{--#EVENT device datapoint
77
+ -- lua code is here
78
+ function foo(bar)
79
+ return bar + 1
80
+ end
81
+ }
82
+ }
83
+ stub_request(:get, "https://bizapi.hosted.exosite.io/api:1/solution/XYZ/eventhandler/9K0").
84
+ with(:headers=>{'Authorization'=>'token TTTTTTTTTT',
85
+ 'Content-Type'=>'application/json'}).
86
+ to_return(body: body.to_json)
87
+
88
+ ret = nil
89
+ @srv.fetch('9K0') { |sc| ret = sc }
90
+ expect(ret).to eq(body[:script])
91
+ end
92
+
65
93
  it "fetches, without header" do
66
94
  body = {:id=>"9K0",
67
95
  :name=>"debug",
@@ -209,7 +237,112 @@ end
209
237
  end
210
238
  end
211
239
 
212
- # TODO: status tests
240
+ context "Lookup functions" do
241
+ it "gets local name" do
242
+ ret = @srv.tolocalname({ :name=>"bob" }, nil)
243
+ expect(ret).to eq('bob.lua')
244
+ end
245
+
246
+ it "gets synckey" do
247
+ ret = @srv.synckey({ :service=>'device', :event=>'datapoint' })
248
+ expect(ret).to eq("device_datapoint")
249
+ end
250
+
251
+ it "gets searchfor" do
252
+ $cfg['eventhandler.searchFor'] = %{a b c/**/d/*.bob}
253
+ ret = @srv.searchFor
254
+ expect(ret).to eq(["a", "b", "c/**/d/*.bob"])
255
+ end
256
+
257
+ it "gets ignoring" do
258
+ $cfg['eventhandler.ignoring'] = %{a b c/**/d/*.bob}
259
+ ret = @srv.ignoring
260
+ expect(ret).to eq(["a", "b", "c/**/d/*.bob"])
261
+ end
262
+
263
+ it "raises on alias without service" do
264
+ expect {
265
+ @srv.mkname( {:event=>'bob'} )
266
+ }.to raise_error %{Missing parts! {"event":"bob"}}
267
+ end
268
+
269
+ it "raises on alias without event" do
270
+ expect {
271
+ @srv.mkalias( {:service=>'bob'} )
272
+ }.to raise_error %{Missing parts! {"service":"bob"}}
273
+ end
274
+
275
+ it "raises on name without service" do
276
+ expect {
277
+ @srv.mkalias( {:event=>'bob'} )
278
+ }.to raise_error %{Missing parts! {"event":"bob"}}
279
+ end
280
+
281
+ it "raises on name without event" do
282
+ expect {
283
+ @srv.mkname( {:service=>'bob'} )
284
+ }.to raise_error %{Missing parts! {"service":"bob"}}
285
+ end
286
+ end
287
+
288
+ context "toRemoteItem" do
289
+ before(:example) do
290
+ allow(@srv).to receive(:warning)
291
+ end
292
+
293
+ it "reads one" do
294
+ Tempfile.open('foo') do |tio|
295
+ tio << %{--#EVENT device datapoint
296
+ -- do something.
297
+ Tsdb.write{tags={sn='1'},metrics={[data.alias]=data.value[2]}}
298
+ }.gsub(/^\s+/,'')
299
+ tio.close
300
+
301
+ ret = @srv.toRemoteItem(nil, tio.path)
302
+ expect(ret).to eq({:service=>'device',
303
+ :event=>'datapoint',
304
+ :line=>0,
305
+ :line_end=>3,
306
+ :local_path=>Pathname.new(tio.path),
307
+ :script=>%{--#EVENT device datapoint\n-- do something.\nTsdb.write{tags={sn='1'},metrics={[data.alias]=data.value[2]}}\n},
308
+ })
309
+ end
310
+ end
311
+
312
+ it "skips all when no header found" do
313
+ Tempfile.open('foo') do |tio|
314
+ tio << %{
315
+ -- do something.
316
+ Tsdb.write{tags={sn='1'},metrics={[data.alias]=data.value[2]}}
317
+ }.gsub(/^\s+/,'')
318
+ tio.close
319
+
320
+ ret = @srv.toRemoteItem(nil, tio.path)
321
+ expect(ret).to eq(nil)
322
+ end
323
+ end
324
+
325
+ it "skips junk at begining" do
326
+ Tempfile.open('foo') do |tio|
327
+ tio << %{
328
+ -- do something.
329
+ --#EVENT device datapoint
330
+ Tsdb.write{tags={sn='1'},metrics={[data.alias]=data.value[2]}}
331
+ }.gsub(/^\s+/,'')
332
+ tio.close
333
+
334
+ ret = @srv.toRemoteItem(nil, tio.path)
335
+ expect(ret).to eq({:service=>'device',
336
+ :event=>'datapoint',
337
+ :line=>1,
338
+ :line_end=>3,
339
+ :local_path=>Pathname.new(tio.path),
340
+ :script=>%{--#EVENT device datapoint\nTsdb.write{tags={sn='1'},metrics={[data.alias]=data.value[2]}}\n},
341
+ })
342
+ end
343
+ end
344
+
345
+ end
213
346
 
214
347
  end
215
348
  # vim: set ai et sw=2 ts=2 :