MrMurano 1.3.2 → 1.4.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,98 @@
1
+ require 'MrMurano/version'
2
+ require 'MrMurano/verbosing'
3
+ require 'MrMurano/http'
4
+ require 'MrMurano/Product'
5
+ require 'MrMurano/configFile'
6
+
7
+ RSpec.describe MrMurano::ProductContent, "#product_content" do
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::ProductContent.new
15
+ allow(@prd).to receive(:token).and_return("TTTTTTTTTT")
16
+
17
+ @urlroot = "https://bizapi.hosted.exosite.io/api:1/product/XYZ/proxy/provision/manage/content/XYZ"
18
+ end
19
+
20
+ it "lists nothing" do
21
+ stub_request(:get, @urlroot + "/").
22
+ with(headers: {'Authorization'=>'token TTTTTTTTTT',
23
+ 'Content-Type'=>'application/json'}).
24
+ to_return(body: "")
25
+
26
+ ret = @prd.list
27
+ expect(ret).to eq([])
28
+ end
29
+
30
+ it "creates an item" do
31
+ stub_request(:post, @urlroot + "/").
32
+ with(headers: {'Authorization'=>'token TTTTTTTTTT',
33
+ 'Content-Type'=>'application/x-www-form-urlencoded'}).
34
+ with(body: {'id'=>'testFor', 'meta'=> 'some meta'}).
35
+ to_return(status: 205)
36
+
37
+ ret = @prd.create("testFor", "some meta")
38
+ expect(ret).to eq({})
39
+ end
40
+
41
+ it "removes an item" do
42
+ stub_request(:post, @urlroot + "/").
43
+ with(headers: {'Authorization'=>'token TTTTTTTTTT',
44
+ 'Content-Type'=>'application/x-www-form-urlencoded'}).
45
+ with(body: {'id'=>'testFor', 'delete'=>'true'}).
46
+ to_return(status: 205)
47
+
48
+ ret = @prd.remove("testFor")
49
+ expect(ret).to eq({})
50
+ end
51
+
52
+ it "gets info for content" do
53
+ stub_request(:get, @urlroot + "/testFor").
54
+ with(headers: {'Authorization'=>'token TTTTTTTTTT',
55
+ 'Content-Type'=>'application/json'}).
56
+ to_return(body: "text/plain,42,123456789,test meta,false")
57
+
58
+ ret = @prd.info("testFor")
59
+ expect(ret).to eq([['text/plain','42','123456789','test meta','false']])
60
+ end
61
+
62
+ it "removes content" do
63
+ stub_request(:delete, @urlroot + "/testFor").
64
+ with(headers: {'Authorization'=>'token TTTTTTTTTT',
65
+ 'Content-Type'=>'application/json'}).
66
+ to_return(status: 205)
67
+
68
+ ret = @prd.remove_content("testFor")
69
+ expect(ret).to eq({})
70
+ end
71
+
72
+ it "uploads content data" do
73
+ size = FileTest.size('spec/lightbulb.yaml')
74
+ stub_request(:post, @urlroot + "/testFor").
75
+ with(headers: {'Authorization'=>'token TTTTTTTTTT',
76
+ 'Content-Type'=>'text/yaml',
77
+ 'Content-Length' => size
78
+ }).
79
+ to_return(status: 205)
80
+
81
+ ret = @prd.upload('testFor', 'spec/lightbulb.yaml')
82
+ expect(ret).to eq({})
83
+ end
84
+
85
+ it "downloads content" do
86
+ stub_request(:get, @urlroot + "/testFor?download=true").
87
+ with(headers: {'Authorization'=>'token TTTTTTTTTT',
88
+ 'Content-Type'=>'application/json'}).
89
+ to_return(body: "short and sweet")
90
+
91
+ data = ""
92
+ @prd.download('testFor') {|chunk| data << chunk}
93
+ expect(data).to eq("short and sweet")
94
+ end
95
+
96
+ end
97
+
98
+ # vim: set ai et sw=2 ts=2 :
@@ -0,0 +1,109 @@
1
+ require 'MrMurano/version'
2
+ require 'MrMurano/verbosing'
3
+ require 'MrMurano/http'
4
+ require 'MrMurano/Product'
5
+ require 'MrMurano/configFile'
6
+
7
+ RSpec.describe MrMurano::Product, "#product" do
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
+ ret = @prd.update('spec/lightbulb.yaml')
94
+ expect(ret).to eq(rbody)
95
+ end
96
+
97
+ it "can write" do
98
+ stub_request(:post, "https://bizapi.hosted.exosite.io/api:1/product/XYZ/write/42").
99
+ with(headers: {'Authorization'=>'token TTTTTTTTTT',
100
+ 'Content-Type'=>'application/json'}).
101
+ to_return(body: {:temp=> "ok", :humid=> "ok"}.to_json)
102
+
103
+ ret = @prd.write(42, {:temp=>78, :humid=>50})
104
+ expect(ret).to eq({:temp=> "ok", :humid=> "ok"})
105
+ end
106
+
107
+ end
108
+
109
+ # vim: set ai et sw=2 ts=2 :
@@ -0,0 +1,12 @@
1
+ - alias: state
2
+ format: integer
3
+ initial: 0
4
+ - alias: temperature
5
+ format: float
6
+ initial: 0
7
+ - alias: uptime
8
+ format: integer
9
+ initial: 0
10
+ - alias: humidity
11
+ format: float
12
+ initial: 0
@@ -0,0 +1,105 @@
1
+ # This file was generated by the `rspec --init` command. Conventionally, all
2
+ # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
3
+ # The generated `.rspec` file contains `--require spec_helper` which will cause
4
+ # this file to always be loaded, without a need to explicitly require it in any
5
+ # files.
6
+ #
7
+ # Given that it is always loaded, you are encouraged to keep this file as
8
+ # light-weight as possible. Requiring heavyweight dependencies from this file
9
+ # will add to the boot time of your test suite on EVERY test run, even for an
10
+ # individual file that may not need all of that loaded. Instead, consider making
11
+ # a separate helper file that requires the additional dependencies and performs
12
+ # the additional setup, and require it from the spec files that actually need
13
+ # it.
14
+ #
15
+ # The `.rspec` file also contains a few flags that are not defaults but that
16
+ # users commonly want.
17
+ #
18
+ require 'webmock/rspec'
19
+
20
+ # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
21
+ RSpec.configure do |config|
22
+ # rspec-expectations config goes here. You can use an alternate
23
+ # assertion/expectation library such as wrong or the stdlib/minitest
24
+ # assertions if you prefer.
25
+ config.expect_with :rspec do |expectations|
26
+ # This option will default to `true` in RSpec 4. It makes the `description`
27
+ # and `failure_message` of custom matchers include text for helper methods
28
+ # defined using `chain`, e.g.:
29
+ # be_bigger_than(2).and_smaller_than(4).description
30
+ # # => "be bigger than 2 and smaller than 4"
31
+ # ...rather than:
32
+ # # => "be bigger than 2"
33
+ expectations.include_chain_clauses_in_custom_matcher_descriptions = true
34
+ end
35
+
36
+ # rspec-mocks config goes here. You can use an alternate test double
37
+ # library (such as bogus or mocha) by changing the `mock_with` option here.
38
+ config.mock_with :rspec do |mocks|
39
+ # Prevents you from mocking or stubbing a method that does not exist on
40
+ # a real object. This is generally recommended, and will default to
41
+ # `true` in RSpec 4.
42
+ mocks.verify_partial_doubles = true
43
+ end
44
+
45
+ # This option will default to `:apply_to_host_groups` in RSpec 4 (and will
46
+ # have no way to turn it off -- the option exists only for backwards
47
+ # compatibility in RSpec 3). It causes shared context metadata to be
48
+ # inherited by the metadata hash of host groups and examples, rather than
49
+ # triggering implicit auto-inclusion in groups with matching metadata.
50
+ config.shared_context_metadata_behavior = :apply_to_host_groups
51
+
52
+ # The settings below are suggested to provide a good initial experience
53
+ # with RSpec, but feel free to customize to your heart's content.
54
+ =begin
55
+ # This allows you to limit a spec run to individual examples or groups
56
+ # you care about by tagging them with `:focus` metadata. When nothing
57
+ # is tagged with `:focus`, all examples get run. RSpec also provides
58
+ # aliases for `it`, `describe`, and `context` that include `:focus`
59
+ # metadata: `fit`, `fdescribe` and `fcontext`, respectively.
60
+ config.filter_run_when_matching :focus
61
+
62
+ # Allows RSpec to persist some state between runs in order to support
63
+ # the `--only-failures` and `--next-failure` CLI options. We recommend
64
+ # you configure your source control system to ignore this file.
65
+ config.example_status_persistence_file_path = "spec/examples.txt"
66
+
67
+ # Limits the available syntax to the non-monkey patched syntax that is
68
+ # recommended. For more details, see:
69
+ # - http://rspec.info/blog/2012/06/rspecs-new-expectation-syntax/
70
+ # - http://www.teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/
71
+ # - http://rspec.info/blog/2014/05/notable-changes-in-rspec-3/#zero-monkey-patching-mode
72
+ config.disable_monkey_patching!
73
+
74
+ # This setting enables warnings. It's recommended, but in some cases may
75
+ # be too noisy due to issues in dependencies.
76
+ config.warnings = true
77
+
78
+ # Many RSpec users commonly either run the entire suite or an individual
79
+ # file, and it's useful to allow more verbose output when running an
80
+ # individual spec file.
81
+ if config.files_to_run.one?
82
+ # Use the documentation formatter for detailed output,
83
+ # unless a formatter has already been configured
84
+ # (e.g. via a command-line flag).
85
+ config.default_formatter = 'doc'
86
+ end
87
+
88
+ # Print the 10 slowest examples and example groups at the
89
+ # end of the spec run, to help surface which specs are running
90
+ # particularly slow.
91
+ config.profile_examples = 10
92
+
93
+ # Run specs in random order to surface order dependencies. If you find an
94
+ # order dependency and want to debug it, you can fix the order by providing
95
+ # the seed, which is printed after each run.
96
+ # --seed 1234
97
+ config.order = :random
98
+
99
+ # Seed global randomization in this process using the `--seed` CLI option.
100
+ # Setting this allows you to use `--seed` to deterministically reproduce
101
+ # test failures related to randomization by passing the same `--seed` value
102
+ # as the one that triggered the failure.
103
+ Kernel.srand config.seed
104
+ =end
105
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: MrMurano
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.2
4
+ version: 1.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Michael Conrad Tadpol Tilstra
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-09-13 00:00:00.000000000 Z
11
+ date: 2016-09-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: commander
@@ -122,34 +122,48 @@ dependencies:
122
122
  - - ~>
123
123
  - !ruby/object:Gem::Version
124
124
  version: 1.7.6
125
+ - !ruby/object:Gem::Dependency
126
+ name: rake
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - ~>
130
+ - !ruby/object:Gem::Version
131
+ version: 10.1.1
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - ~>
137
+ - !ruby/object:Gem::Version
138
+ version: 10.1.1
125
139
  - !ruby/object:Gem::Dependency
126
140
  name: rspec
127
141
  requirement: !ruby/object:Gem::Requirement
128
142
  requirements:
129
143
  - - ~>
130
144
  - !ruby/object:Gem::Version
131
- version: '3.2'
145
+ version: '3.5'
132
146
  type: :development
133
147
  prerelease: false
134
148
  version_requirements: !ruby/object:Gem::Requirement
135
149
  requirements:
136
150
  - - ~>
137
151
  - !ruby/object:Gem::Version
138
- version: '3.2'
152
+ version: '3.5'
139
153
  - !ruby/object:Gem::Dependency
140
- name: rake
154
+ name: webmock
141
155
  requirement: !ruby/object:Gem::Requirement
142
156
  requirements:
143
157
  - - ~>
144
158
  - !ruby/object:Gem::Version
145
- version: 10.1.1
159
+ version: 2.1.0
146
160
  type: :development
147
161
  prerelease: false
148
162
  version_requirements: !ruby/object:Gem::Requirement
149
163
  requirements:
150
164
  - - ~>
151
165
  - !ruby/object:Gem::Version
152
- version: 10.1.1
166
+ version: 2.1.0
153
167
  description: "Do more from the command line with Murano\n\n Push and pull data from
154
168
  Murano.\n Get status on what things have changed.\n See a diff of the changes
155
169
  before you push.\n "
@@ -161,6 +175,7 @@ extensions: []
161
175
  extra_rdoc_files: []
162
176
  files:
163
177
  - .gitignore
178
+ - .rspec
164
179
  - .travis.yml
165
180
  - Gemfile
166
181
  - MrMurano.gemspec
@@ -170,14 +185,18 @@ files:
170
185
  - bin/mr
171
186
  - lib/MrMurano.rb
172
187
  - lib/MrMurano/Account.rb
188
+ - lib/MrMurano/Product.rb
173
189
  - lib/MrMurano/Solution-Endpoint.rb
174
190
  - lib/MrMurano/Solution-File.rb
175
191
  - lib/MrMurano/Solution-ServiceConfig.rb
176
192
  - lib/MrMurano/Solution-Services.rb
177
193
  - lib/MrMurano/Solution-Users.rb
178
194
  - lib/MrMurano/Solution.rb
195
+ - lib/MrMurano/configCommand.rb
179
196
  - lib/MrMurano/configFile.rb
197
+ - lib/MrMurano/contentCommand.rb
180
198
  - lib/MrMurano/cors.rb
199
+ - lib/MrMurano/exportImport.rb
181
200
  - lib/MrMurano/hash.rb
182
201
  - lib/MrMurano/http.rb
183
202
  - lib/MrMurano/keystore.rb
@@ -186,7 +205,14 @@ files:
186
205
  - lib/MrMurano/status.rb
187
206
  - lib/MrMurano/sync.rb
188
207
  - lib/MrMurano/timeseries.rb
208
+ - lib/MrMurano/verbosing.rb
189
209
  - lib/MrMurano/version.rb
210
+ - spec/Account-Passwords_spec.rb
211
+ - spec/ProductBase_spec.rb
212
+ - spec/ProductContent_spec.rb
213
+ - spec/Product_spec.rb
214
+ - spec/lightbulb.yaml
215
+ - spec/spec_helper.rb
190
216
  homepage: https://github.com/tadpol/MrMurano
191
217
  licenses:
192
218
  - MIT
@@ -211,4 +237,10 @@ rubygems_version: 2.0.14.1
211
237
  signing_key:
212
238
  specification_version: 4
213
239
  summary: Do more from the command line with Murano
214
- test_files: []
240
+ test_files:
241
+ - spec/Account-Passwords_spec.rb
242
+ - spec/ProductBase_spec.rb
243
+ - spec/ProductContent_spec.rb
244
+ - spec/Product_spec.rb
245
+ - spec/lightbulb.yaml
246
+ - spec/spec_helper.rb