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,212 @@
1
+ require 'MrMurano/version'
2
+ require 'MrMurano/Solution-File'
3
+ require '_workspace'
4
+
5
+ RSpec.describe MrMurano::File do
6
+ include_context "WORKSPACE"
7
+ before(:example) do
8
+ $cfg = MrMurano::Config.new
9
+ $cfg.load
10
+ $project = MrMurano::ProjectFile.new
11
+ $project.load
12
+ $cfg['net.host'] = 'bizapi.hosted.exosite.io'
13
+ $cfg['solution.id'] = 'XYZ'
14
+
15
+ @srv = MrMurano::File.new
16
+ allow(@srv).to receive(:token).and_return("TTTTTTTTTT")
17
+ end
18
+
19
+ it "initializes" do
20
+ uri = @srv.endPoint('/')
21
+ expect(uri.to_s).to eq("https://bizapi.hosted.exosite.io/api:1/solution/XYZ/file/")
22
+ end
23
+
24
+ it "lists" do
25
+ body = [
26
+ {:path=>"/",
27
+ :mime_type=>"text/html",
28
+ :checksum=>"f535dad52b2877a49717a034b4eee5ff1cdb8a18"},
29
+ {:path=>"/batteryMeter.svg",
30
+ :mime_type=>"image/svg+xml",
31
+ :checksum=>"06a1aab86ba8cb9b3f2913c673d4aa243c553494"},
32
+ {:path=>"/meter.html",
33
+ :mime_type=>"text/html",
34
+ :checksum=>"82e12125c2f1324bbf7bd64bf187f3334416117e"}
35
+ ]
36
+ stub_request(:get, "https://bizapi.hosted.exosite.io/api:1/solution/XYZ/file").
37
+ with(:headers=>{'Authorization'=>'token TTTTTTTTTT',
38
+ 'Content-Type'=>'application/json'}).
39
+ to_return(body: body.to_json)
40
+
41
+ ret = @srv.list()
42
+ expect(ret).to eq(body)
43
+ end
44
+
45
+ it "removes" do
46
+ stub_request(:delete, "https://bizapi.hosted.exosite.io/api:1/solution/XYZ/file/index.html").
47
+ with(:headers=>{'Authorization'=>'token TTTTTTTTTT',
48
+ 'Content-Type'=>'application/json'}).
49
+ to_return(status: 200)
50
+ ret = @srv.remove('index.html')
51
+ expect(ret).to eq({})
52
+ end
53
+
54
+ context "fetches" do
55
+ it "gets an error" do
56
+ stub_request(:get, "https://bizapi.hosted.exosite.io/api:1/solution/XYZ/file/bob").
57
+ with(:headers=>{'Authorization'=>'token TTTTTTTTTT',
58
+ 'Content-Type'=>'application/json'}).
59
+ to_return(status: 404, body: "nope")
60
+ saved = $stderr
61
+ $stderr = StringIO.new
62
+ ret = @srv.fetch('/bob')
63
+ expect(ret).to be_nil
64
+ expect($stderr.string).to eq("\e[31mRequest Failed: 404: nope\e[0m\n")
65
+ $stderr = saved
66
+ end
67
+
68
+ it "gets $stdout" do
69
+ stub_request(:get, "https://bizapi.hosted.exosite.io/api:1/solution/XYZ/file/bob").
70
+ with(:headers=>{'Authorization'=>'token TTTTTTTTTT',
71
+ 'Content-Type'=>'application/json'}).
72
+ to_return(status: 200, body: "nope")
73
+ saved = $stdout
74
+ $stdout = StringIO.new
75
+ ret = @srv.fetch('/bob')
76
+ expect(ret).to be_nil
77
+ expect($stdout.string).to eq("nope")
78
+ $stdout = saved
79
+ end
80
+
81
+ it "gets to block" do
82
+ stub_request(:get, "https://bizapi.hosted.exosite.io/api:1/solution/XYZ/file/bob").
83
+ with(:headers=>{'Authorization'=>'token TTTTTTTTTT',
84
+ 'Content-Type'=>'application/json'}).
85
+ to_return(status: 200, body: "nope")
86
+ got = ""
87
+ ret = @srv.fetch('/bob') {|chunk| got << chunk}
88
+ expect(ret).to be_nil
89
+ expect(got).to eq("nope")
90
+ end
91
+ end
92
+
93
+ context "uploads" do
94
+ before(:example) do
95
+ FileUtils.mkpath(@projectDir + '/files')
96
+ @lp = Pathname.new(@projectDir + '/files/one.text')
97
+ @lp.open('w') {|io| io << %{Just some text}}
98
+ @lp = @lp.realpath
99
+ end
100
+
101
+ it "an item" do
102
+ stub_request(:put, "https://bizapi.hosted.exosite.io/api:1/solution/XYZ/fileupload/one.text").
103
+ with(:headers=>{'Authorization'=>'token TTTTTTTTTT',
104
+ 'Content-Type'=>%r{multipart/form-data; boundary=.*}},
105
+ )
106
+
107
+ @srv.upload(@lp, {:path=>'/one.text'}, false)
108
+ end
109
+
110
+ it "gets an error" do
111
+ stub_request(:put, "https://bizapi.hosted.exosite.io/api:1/solution/XYZ/fileupload/one.text").
112
+ with(:headers=>{'Authorization'=>'token TTTTTTTTTT',
113
+ 'Content-Type'=>%r{multipart/form-data; boundary=.*}},
114
+ ).
115
+ to_return(status: 401, body: "nope")
116
+
117
+ saved = $stderr
118
+ $stderr = StringIO.new
119
+ @srv.upload(@lp, {:path=>'/one.text'}, false)
120
+ expect($stderr.string).to eq("\e[31mRequest Failed: 401: nope\e[0m\n")
121
+ $stderr = saved
122
+ end
123
+
124
+ it "an item with curl debug" do
125
+ stub_request(:put, "https://bizapi.hosted.exosite.io/api:1/solution/XYZ/fileupload/one.text").
126
+ with(:headers=>{'Authorization'=>'token TTTTTTTTTT',
127
+ 'Content-Type'=>%r{multipart/form-data; boundary=.*}},
128
+ )
129
+ $cfg['tool.curldebug'] = true
130
+ saved = $stdout
131
+ $stdout = StringIO.new
132
+ @srv.upload(@lp, {:path=>'/one.text'}, false)
133
+ expect($stdout.string).to match(%r{^curl -s -H 'Authorization: token TTTTTTTTTT'.*-X PUT 'https://bizapi.hosted.exosite.io/api:1/solution/XYZ/fileupload/one.text' -F file=@.*$})
134
+ $stdout = saved
135
+ end
136
+ end
137
+
138
+ context "compares" do
139
+ before(:example) do
140
+ @iA = {:path=>"/api/v1/bar",
141
+ :mime_type=>"application/json",
142
+ :checksum=>'12',
143
+ }
144
+ @iB = {:path=>"/api/v1/bar",
145
+ :mime_type=>"application/json",
146
+ :checksum=>'12',
147
+ }
148
+ end
149
+ it "equal" do
150
+ ret = @srv.docmp(@iA, @iB)
151
+ expect(ret).to be false
152
+ end
153
+ it "different mime" do
154
+ iA = @iA.merge({:mime_type=>'text/plain'})
155
+ ret = @srv.docmp(iA, @iB)
156
+ expect(ret).to be true
157
+ end
158
+ it "different checksum" do
159
+ iA = @iA.merge({:checksum=>'4352'})
160
+ ret = @srv.docmp(iA, @iB)
161
+ expect(ret).to be true
162
+ end
163
+ end
164
+
165
+ context "Lookup functions" do
166
+ it "gets local name" do
167
+ ret = @srv.tolocalname({:path=>'/one/two/three.html'}, :path)
168
+ expect(ret).to eq('/one/two/three.html')
169
+ end
170
+
171
+ it "gets default_page local name" do
172
+ ret = @srv.tolocalname({:path=>'/'}, :path)
173
+ expect(ret).to eq('index.html')
174
+ end
175
+
176
+ it "gets synckey" do
177
+ ret = @srv.synckey({:path=>'/one/two/three'})
178
+ expect(ret).to eq("/one/two/three")
179
+ end
180
+
181
+ it "gets searchfor" do
182
+ $cfg['files.searchFor'] = %{a b c/**/d/*.bob}
183
+ ret = @srv.searchFor
184
+ expect(ret).to eq(["a", "b", "c/**/d/*.bob"])
185
+ end
186
+
187
+ it "gets ignoring" do
188
+ $cfg['files.ignoring'] = %{a b c/**/d/*.bob}
189
+ ret = @srv.ignoring
190
+ expect(ret).to eq(["a", "b", "c/**/d/*.bob"])
191
+ end
192
+ end
193
+
194
+ context "toRemoteItem" do
195
+ before(:example) do
196
+ FileUtils.mkpath(@projectDir + '/files')
197
+ @lp = Pathname.new(@projectDir + '/files/one.text')
198
+ @lp.open('w') {|io| io << %{Just some text}}
199
+ @lp = @lp.realpath
200
+ end
201
+ it "gets item" do
202
+ prj = Pathname.new(@projectDir).realpath
203
+ ret = @srv.toRemoteItem(prj, @lp)
204
+ expect(ret).to eq({
205
+ :path=>"/files/one.text",
206
+ :mime_type=>"text/plain",
207
+ :checksum=>"d1af3dadf08479a1d43b282f95d61dda8efda5e7"
208
+ })
209
+ end
210
+ end
211
+ end
212
+ # vim: set ai et sw=2 ts=2 :
@@ -0,0 +1,202 @@
1
+ require 'MrMurano/version'
2
+ require 'MrMurano/Solution-ServiceConfig'
3
+ require 'tempfile'
4
+ require '_workspace'
5
+
6
+ RSpec.describe MrMurano::ServiceConfig 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['solution.id'] = 'XYZ'
15
+
16
+ @srv = MrMurano::ServiceConfig.new
17
+ allow(@srv).to receive(:token).and_return("TTTTTTTTTT")
18
+ end
19
+
20
+ it "initializes" do
21
+ uri = @srv.endPoint('/')
22
+ expect(uri.to_s).to eq("https://bizapi.hosted.exosite.io/api:1/solution/XYZ/serviceconfig/")
23
+ end
24
+
25
+ it "lists" do
26
+ body = {:items=>[{:id=>"9K0",
27
+ :name=>"debug",
28
+ :alias=>"XYZ_debug",
29
+ :solution_id=>"XYZ",
30
+ :service=>"device",
31
+ :status=>"ready",
32
+ :created_at=>"2016-07-07T19:16:19.479Z",
33
+ :updated_at=>"2016-09-12T13:26:55.868Z",
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
+ ret = @srv.list()
42
+ expect(ret).to eq(body[:items])
43
+ end
44
+
45
+ it "fetches" do
46
+ body = {:id=>"9K0",
47
+ :name=>"debug",
48
+ :alias=>"XYZ_debug",
49
+ :solution_id=>"XYZ",
50
+ :service=>"device",
51
+ :status=>"ready",
52
+ :created_at=>"2016-07-07T19:16:19.479Z",
53
+ :updated_at=>"2016-09-12T13:26:55.868Z"
54
+ }
55
+ stub_request(:get, "https://bizapi.hosted.exosite.io/api:1/solution/XYZ/serviceconfig/9K0").
56
+ with(:headers=>{'Authorization'=>'token TTTTTTTTTT',
57
+ 'Content-Type'=>'application/json'}).
58
+ to_return(body: body.to_json)
59
+
60
+ ret = @srv.fetch('9K0')
61
+ expect(ret).to eq(body)
62
+ end
63
+
64
+ it "gets id from service" do
65
+ body = {:items=>[{:id=>"9K0",
66
+ :name=>"debug",
67
+ :alias=>"XYZ_debug",
68
+ :solution_id=>"XYZ",
69
+ :service=>"device",
70
+ :status=>"ready",
71
+ :created_at=>"2016-07-07T19:16:19.479Z",
72
+ :updated_at=>"2016-09-12T13:26:55.868Z",
73
+ :deleted_at=>nil}],
74
+ :total=>1}
75
+ stub_request(:get, "https://bizapi.hosted.exosite.io/api:1/solution/XYZ/serviceconfig").
76
+ with(:headers=>{'Authorization'=>'token TTTTTTTTTT',
77
+ 'Content-Type'=>'application/json'}).
78
+ to_return(body: body.to_json)
79
+
80
+ ret = @srv.scid_for_name('device')
81
+ expect(ret).to eq("9K0")
82
+ end
83
+
84
+ it "gets nil if not there" do
85
+ body = {:items=>[{:id=>"9K0",
86
+ :name=>"debug",
87
+ :alias=>"XYZ_debug",
88
+ :solution_id=>"XYZ",
89
+ :service=>"device",
90
+ :status=>"ready",
91
+ :created_at=>"2016-07-07T19:16:19.479Z",
92
+ :updated_at=>"2016-09-12T13:26:55.868Z",
93
+ :deleted_at=>nil}],
94
+ :total=>1}
95
+ stub_request(:get, "https://bizapi.hosted.exosite.io/api:1/solution/XYZ/serviceconfig").
96
+ with(:headers=>{'Authorization'=>'token TTTTTTTTTT',
97
+ 'Content-Type'=>'application/json'}).
98
+ to_return(body: body.to_json)
99
+
100
+ ret = @srv.scid_for_name('debug')
101
+ expect(ret).to eq(nil)
102
+ end
103
+
104
+ it "gets info" do
105
+ body = {:calls=>{:daily=>0, :monthly=>0, :total=>0}}
106
+ stub_request(:get, "https://bizapi.hosted.exosite.io/api:1/solution/XYZ/serviceconfig/9K0/info").
107
+ with(:headers=>{'Authorization'=>'token TTTTTTTTTT',
108
+ 'Content-Type'=>'application/json'}).
109
+ to_return(body: body.to_json)
110
+
111
+ ret = @srv.info('9K0')
112
+ expect(ret).to eq(body)
113
+ end
114
+
115
+ context "calls" do
116
+ before(:example) do
117
+ allow(@srv).to receive(:scid).and_return("9K0")
118
+ end
119
+ it "a get" do
120
+ body = {:calls=>{:daily=>0, :monthly=>0, :total=>0}}
121
+ stub_request(:get, "https://bizapi.hosted.exosite.io/api:1/solution/XYZ/serviceconfig/9K0/call/info").
122
+ with(:headers=>{'Authorization'=>'token TTTTTTTTTT',
123
+ 'Content-Type'=>'application/json'}).
124
+ to_return(body: body.to_json)
125
+
126
+ ret = @srv.call(:info)
127
+ expect(ret).to eq(body)
128
+ end
129
+
130
+ it "a get with query" do
131
+ body = {:calls=>{:daily=>0, :monthly=>0, :total=>0}}
132
+ stub_request(:get, "https://bizapi.hosted.exosite.io/api:1/solution/XYZ/serviceconfig/9K0/call/ask?q=what").
133
+ with(:headers=>{'Authorization'=>'token TTTTTTTTTT',
134
+ 'Content-Type'=>'application/json'}).
135
+ to_return(body: body.to_json)
136
+
137
+ ret = @srv.call(:ask, :get, {:q=>'what'})
138
+ expect(ret).to eq(body)
139
+ end
140
+
141
+ it "a post" do
142
+ body = {:calls=>{:daily=>0, :monthly=>0, :total=>0}}
143
+ stub_request(:post, "https://bizapi.hosted.exosite.io/api:1/solution/XYZ/serviceconfig/9K0/call/ask").
144
+ with(:body => JSON.generate({:q=> 'what'}),
145
+ :headers=>{'Authorization'=>'token TTTTTTTTTT',
146
+ 'Content-Type'=>'application/json'}).
147
+ to_return(body: body.to_json)
148
+
149
+ ret = @srv.call(:ask, :post, {:q=>'what'})
150
+ expect(ret).to eq(body)
151
+ end
152
+
153
+ it "a post without data" do
154
+ body = {:calls=>{:daily=>0, :monthly=>0, :total=>0}}
155
+ stub_request(:post, "https://bizapi.hosted.exosite.io/api:1/solution/XYZ/serviceconfig/9K0/call/ask").
156
+ with(:body => JSON.generate({}),
157
+ :headers=>{'Authorization'=>'token TTTTTTTTTT',
158
+ 'Content-Type'=>'application/json'}).
159
+ to_return(body: body.to_json)
160
+
161
+ ret = @srv.call(:ask, :post)
162
+ expect(ret).to eq(body)
163
+ end
164
+
165
+ it "a put" do
166
+ body = {:calls=>{:daily=>0, :monthly=>0, :total=>0}}
167
+ stub_request(:put, "https://bizapi.hosted.exosite.io/api:1/solution/XYZ/serviceconfig/9K0/call/ask").
168
+ with(:body => JSON.generate({:q=> 'what'}),
169
+ :headers=>{'Authorization'=>'token TTTTTTTTTT',
170
+ 'Content-Type'=>'application/json'}).
171
+ to_return(body: body.to_json)
172
+
173
+ ret = @srv.call(:ask, :put, {:q=>'what'})
174
+ expect(ret).to eq(body)
175
+ end
176
+
177
+ it "a put without data" do
178
+ body = {:calls=>{:daily=>0, :monthly=>0, :total=>0}}
179
+ stub_request(:put, "https://bizapi.hosted.exosite.io/api:1/solution/XYZ/serviceconfig/9K0/call/ask").
180
+ with(:body => JSON.generate({}),
181
+ :headers=>{'Authorization'=>'token TTTTTTTTTT',
182
+ 'Content-Type'=>'application/json'}).
183
+ to_return(body: body.to_json)
184
+
185
+ ret = @srv.call(:ask, :put)
186
+ expect(ret).to eq(body)
187
+ end
188
+
189
+ it "a delete" do
190
+ body = {:calls=>{:daily=>0, :monthly=>0, :total=>0}}
191
+ stub_request(:delete, "https://bizapi.hosted.exosite.io/api:1/solution/XYZ/serviceconfig/9K0/call/gone").
192
+ with(:headers=>{'Authorization'=>'token TTTTTTTTTT',
193
+ 'Content-Type'=>'application/json'}).
194
+ to_return(body: body.to_json)
195
+
196
+ ret = @srv.call(:gone, :delete)
197
+ expect(ret).to eq(body)
198
+ end
199
+ end
200
+
201
+ end
202
+ # vim: set ai et sw=2 ts=2 :
@@ -0,0 +1,176 @@
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
+ $project = MrMurano::ProjectFile.new
12
+ $project.load
13
+ $cfg['net.host'] = 'bizapi.hosted.exosite.io'
14
+ $cfg['solution.id'] = 'XYZ'
15
+
16
+ @srv = MrMurano::SC_Device.new
17
+ allow(@srv).to receive(:token).and_return("TTTTTTTTTT")
18
+ end
19
+
20
+ it "initializes" do
21
+ uri = @srv.endPoint('/')
22
+ expect(uri.to_s).to eq("https://bizapi.hosted.exosite.io/api:1/solution/XYZ/serviceconfig/")
23
+ end
24
+
25
+ it "lists triggers; with scid lookup" do
26
+ body = {:items=>[{
27
+ :id => "624098f1",
28
+ :name => "Device Gateway Service",
29
+ :alias => "XYZ_device",
30
+ :solution_id => "XYZ",
31
+ :quota => {},
32
+ :service => "device",
33
+ :status => "ready",
34
+ :created_at => "2016-07-13T19:24:14.206Z",
35
+ :updated_at => "2016-08-01T15:44:11.433Z",
36
+ :deleted_at => nil
37
+ }], :total=>1}
38
+ stub_request(:get, "https://bizapi.hosted.exosite.io/api:1/solution/XYZ/serviceconfig").
39
+ with(:headers=>{'Authorization'=>'token TTTTTTTTTT',
40
+ 'Content-Type'=>'application/json'}).
41
+ to_return(body: body.to_json)
42
+
43
+
44
+ body = {
45
+ :id => "624098f1",
46
+ :alias => "XYZ_device",
47
+ :name => "Device Gateway Service",
48
+ :status => "ready",
49
+ :solution_id => "XYZ",
50
+ :service => "device",
51
+ :parameters => {
52
+ :bizid => "ABCDEFG",
53
+ },
54
+ :triggers => {
55
+ :pid => [
56
+ "LMNOP"
57
+ ]
58
+ },
59
+ :quota => {},
60
+ :created_at => "2016-07-13T19:24:14.206Z",
61
+ :updated_at => "2016-08-01T15:44:11.433Z",
62
+ :deleted_at => nil
63
+ }
64
+ stub_request(:get, "https://bizapi.hosted.exosite.io/api:1/solution/XYZ/serviceconfig/624098f1").
65
+ with(:headers => {'Authorization'=>'token TTTTTTTTTT',
66
+ 'Content-Type'=>'application/json'}).
67
+ to_return(:body => body.to_json)
68
+
69
+ ret = @srv.showTriggers
70
+ expect(ret).to eq(["LMNOP"])
71
+ end
72
+
73
+ it "lists triggers" do
74
+ expect(@srv).to receive(:scid).once.and_return('624098f1')
75
+ body = {
76
+ :id => "624098f1",
77
+ :alias => "XYZ_device",
78
+ :name => "Device Gateway Service",
79
+ :status => "ready",
80
+ :solution_id => "XYZ",
81
+ :service => "device",
82
+ :parameters => {
83
+ :bizid => "ABCDEFG",
84
+ },
85
+ :triggers => {
86
+ :pid => [
87
+ "LMNOP"
88
+ ]
89
+ },
90
+ :quota => {},
91
+ :created_at => "2016-07-13T19:24:14.206Z",
92
+ :updated_at => "2016-08-01T15:44:11.433Z",
93
+ :deleted_at => nil
94
+ }
95
+ stub_request(:get, "https://bizapi.hosted.exosite.io/api:1/solution/XYZ/serviceconfig/624098f1").
96
+ with(:headers => {'Authorization'=>'token TTTTTTTTTT',
97
+ 'Content-Type'=>'application/json'}).
98
+ to_return(:body => body.to_json)
99
+
100
+ ret = @srv.showTriggers
101
+ expect(ret).to eq(["LMNOP"])
102
+ end
103
+
104
+ it "assigns trigger" do
105
+ expect(@srv).to receive(:scid).twice.and_return('624098f1')
106
+ body = {
107
+ :id => "624098f1",
108
+ :alias => "XYZ_device",
109
+ :name => "Device Gateway Service",
110
+ :status => "ready",
111
+ :solution_id => "XYZ",
112
+ :service => "device",
113
+ :parameters => {
114
+ :bizid => "ABCDEFG",
115
+ },
116
+ :triggers => {
117
+ :pid => [
118
+ "LMNOP"
119
+ ]
120
+ },
121
+ :quota => {},
122
+ :created_at => "2016-07-13T19:24:14.206Z",
123
+ :updated_at => "2016-08-01T15:44:11.433Z",
124
+ :deleted_at => nil
125
+ }
126
+ stub_request(:get, "https://bizapi.hosted.exosite.io/api:1/solution/XYZ/serviceconfig/624098f1").
127
+ with(:headers => {'Authorization'=>'token TTTTTTTTTT',
128
+ 'Content-Type'=>'application/json'}).
129
+ to_return(:body => body.to_json)
130
+
131
+ stub_request(:put, "https://bizapi.hosted.exosite.io/api:1/solution/XYZ/serviceconfig/624098f1").
132
+ with(:headers => {'Authorization'=>'token TTTTTTTTTT',
133
+ 'Content-Type'=>'application/json'}).
134
+ to_return(:body => '')
135
+
136
+ ret = @srv.assignTriggers('OTTF')
137
+ expect(ret).to eq({})
138
+ end
139
+
140
+ it "assigns multiple triggers" do
141
+ expect(@srv).to receive(:scid).twice.and_return('624098f1')
142
+ body = {
143
+ :id => "624098f1",
144
+ :alias => "XYZ_device",
145
+ :name => "Device Gateway Service",
146
+ :status => "ready",
147
+ :solution_id => "XYZ",
148
+ :service => "device",
149
+ :parameters => {
150
+ :bizid => "ABCDEFG",
151
+ },
152
+ :triggers => {
153
+ :pid => [
154
+ "LMNOP"
155
+ ]
156
+ },
157
+ :quota => {},
158
+ :created_at => "2016-07-13T19:24:14.206Z",
159
+ :updated_at => "2016-08-01T15:44:11.433Z",
160
+ :deleted_at => nil
161
+ }
162
+ stub_request(:get, "https://bizapi.hosted.exosite.io/api:1/solution/XYZ/serviceconfig/624098f1").
163
+ with(:headers => {'Authorization'=>'token TTTTTTTTTT',
164
+ 'Content-Type'=>'application/json'}).
165
+ to_return(:body => body.to_json)
166
+
167
+ stub_request(:put, "https://bizapi.hosted.exosite.io/api:1/solution/XYZ/serviceconfig/624098f1").
168
+ with(:headers => {'Authorization'=>'token TTTTTTTTTT',
169
+ 'Content-Type'=>'application/json'}).
170
+ to_return(:body => '')
171
+
172
+ ret = @srv.assignTriggers(['OTTF', '1234'])
173
+ expect(ret).to eq({})
174
+ end
175
+ end
176
+ # vim: set ai et sw=2 ts=2 :