machineshop 0.0.4 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,624 +0,0 @@
1
- require 'spec_helper'
2
-
3
- publisher_username = 'publisher@csr.com'
4
- publisher_password = 'password'
5
-
6
-
7
-
8
- =begin
9
- describe "#expiry_time" do
10
- it "default value is 6" do
11
- MachineShop::Configuration.new.expiry_time =23
12
- # puts "original value is #{MachineShop::Configuration.expiry_time}"
13
- end
14
- end
15
-
16
-
17
- describe "#expiry_time=" do
18
- it "can set value" do
19
-
20
- MachineShop.configure do |config|
21
- config.expiry_time = 10
22
- config.enable_caching = false
23
- config.db_username="root"
24
- config.db_password="root"
25
- config.db_name="machineshop"
26
- end
27
- config = MachineShop.configuration
28
-
29
-
30
- config.expiry_time = 7
31
- expect(config.expiry_time).to eq(7)
32
- puts "config.expiry_time #{config.expiry_time}"
33
- end
34
-
35
-
36
- auth_token, user = MachineShop::User.authenticate(
37
- :email => publisher_username,
38
- :password => publisher_password
39
- )
40
-
41
- db = MachineShop::Database.new
42
- it "should get all devices for the user" do
43
- element_data = MachineShop::Device.all(
44
- {:page => 1,
45
- :per_page => 10},
46
- auth_token)
47
- device = element_data[0]
48
- #puts "Devices: #{element_data}"
49
- device.should_not be_nil
50
- device.should be_kind_of MachineShop::Device
51
- end
52
-
53
-
54
-
55
-
56
- it "stores into database" do
57
- # Database.new
58
- db = MachineShop::Database.new
59
- puts "after db =========="
60
- puts "db_connected ? #{db.db_connected}"
61
-
62
- if db.db_connected
63
-
64
- MachineShop::Database.insert('2343','endpoints',"/user/devices/id23")
65
-
66
- end
67
-
68
-
69
- end
70
- end
71
- =end
72
-
73
- # describe "Rubysession" do
74
- # it "should store session " do
75
- # session[:user_id] = "hello"
76
- # end
77
- # end
78
-
79
- describe MachineShop::User do
80
- auth_token = nil
81
- user = nil
82
-
83
- it "should allow a user to authenticate" do
84
- auth_token.should be_nil
85
- auth_token, user = MachineShop::User.authenticate(
86
- :email => publisher_username,
87
- :password => publisher_password
88
- )
89
-
90
- puts "User Data: #{user}"
91
- auth_token.should_not be_nil
92
- user.should_not be_nil
93
- user.should be_kind_of MachineShop::User
94
- end
95
-
96
- it "should get all roles from a static instance" do
97
- element_data = MachineShop::User.all_roles(auth_token)
98
-
99
- puts "all_roles: #{element_data}"
100
- element_data.should_not be_nil
101
- end
102
-
103
- it "should get all roles from a user instance" do
104
-
105
- puts " here user is : #{user}"
106
- element_data = user.all_roles
107
-
108
- #puts "all_roles: #{element_data}"
109
- element_data.should_not be_nil
110
- end
111
-
112
- it "should get a user for the user by id" do
113
- element_data = MachineShop::User.retrieve(user.id, auth_token)
114
-
115
- #puts "user: #{element_data}"
116
- element_data.should_not be_nil
117
- element_data.should be_kind_of MachineShop::User
118
- end
119
-
120
- end
121
-
122
- describe MachineShop::Device do
123
-
124
- auth_token, user = MachineShop::User.authenticate(
125
- :email => publisher_username,
126
- :password => publisher_password
127
- )
128
-
129
- device = nil
130
-
131
- it "should create devices for the user" do
132
- element_data = MachineShop::Device.create(
133
- {
134
- :name => "my_device",
135
- :type => "Test",
136
- :manufacturer => "a company",
137
- :model => "D-vice 1000",
138
- :active => "yes",
139
- :init_cmd => "my_init_cmd",
140
- :init_params => "{'init':'go'}",
141
- :exe_path => "/etc/foo",
142
- :unit_price => "$199.99",
143
- :sample_data => "some arbitrary sample data",
144
- :long_description => "This device tracks position and NCAA football conference.",
145
- :image_url => "http://someurl.com/your_image.png",
146
- :manual_url => "http://someurl.com/manual.pdf"
147
- },
148
- auth_token)
149
-
150
- puts "Element Data: #{element_data}"
151
- puts "element_data.class: #{element_data.class}"
152
-
153
- element_data.should_not be_nil
154
- element_data.should be_kind_of MachineShop::Device
155
- end
156
-
157
- it "should get all devices for the user" do
158
- element_data = MachineShop::Device.all(
159
- {:page => 1,
160
- :per_page => 10},
161
- auth_token)
162
- device = element_data[0]
163
- #puts "Devices: #{element_data}"
164
- device.should_not be_nil
165
- device.should be_kind_of MachineShop::Device
166
- end
167
-
168
- it "should get a device for the user by id" do
169
- element_data = MachineShop::Device.retrieve(device.id, auth_token)
170
-
171
- #puts "Devices: #{element_data}"
172
- element_data.should_not be_nil
173
- element_data.should be_kind_of MachineShop::Device
174
- end
175
-
176
- it "should get a device for the user by name" do
177
- element_data = MachineShop::Device.all(
178
- {
179
- :name => device.name
180
- },
181
- auth_token)
182
-
183
- #puts "Devices: #{element_data}"
184
- element_data.should_not be_nil
185
- element_data.should_not be_empty
186
- end
187
-
188
- # it "should get a device's payload_fields" do
189
- # element_data = device.payload_fields
190
- # element_data.class
191
- # puts "payload_fields: #{element_data}"
192
- # puts "element_data.class: #{element_data.class}"
193
- # element_data.should_not be_nil
194
- #
195
- # end
196
-
197
- end
198
-
199
- describe MachineShop::DeviceInstance do
200
-
201
- auth_token, user = MachineShop::User.authenticate(
202
- :email => publisher_username,
203
- :password => publisher_password
204
- )
205
-
206
- device = nil
207
- device_instance = nil
208
-
209
- it "should create a device instance for the user" do
210
- # First create a device to use
211
- device = MachineShop::Device.create(
212
- {
213
- :name => "my_device",
214
- :type => "Test",
215
- :manufacturer => "a company",
216
- :model => "D-vice 1000",
217
- :active => "yes",
218
- :init_cmd => "my_init_cmd",
219
- :init_params => "{'init':'go'}",
220
- :exe_path => "/etc/foo",
221
- :unit_price => "$199.99",
222
- :sample_data => "some arbitrary sample data",
223
- :long_description => "This device tracks position and NCAA football conference.",
224
- :image_url => "http://someurl.com/your_image.png",
225
- :manual_url => "http://someurl.com/manual.pdf"
226
- },
227
- auth_token)
228
-
229
- puts "device: #{device.inspect}"
230
-
231
- # Now create an instance
232
- device_instance = device.create_instance(
233
- {
234
- :name => "My little instance",
235
- :active => "yes"
236
- }
237
- )
238
-
239
- #puts "Device Instance: #{device_instance.inspect}"
240
- device_instance.should_not be_nil
241
- device_instance.should be_kind_of MachineShop::DeviceInstance
242
- end
243
-
244
-
245
- it "should get device instances" do
246
- element_data = MachineShop::DeviceInstance.all({}, auth_token)
247
-
248
- puts "Device Instances: #{element_data}"
249
-
250
- device_instance = element_data[0]
251
- element_data.should_not be_nil
252
- element_data.should_not be_empty
253
-
254
- device_instance.should be_kind_of MachineShop::DeviceInstance
255
- end
256
-
257
- it "should get a device instance by id" do
258
- element_data = MachineShop::DeviceInstance.retrieve(device_instance.id, auth_token)
259
-
260
- puts "Device Instance by id: #{element_data}"
261
-
262
- element_data.should_not be_nil
263
- element_data.should be_kind_of MachineShop::DeviceInstance
264
- end
265
-
266
- it "should get a device instance by name" do
267
- element_data = MachineShop::DeviceInstance.all({:name => device_instance.name}, auth_token)
268
-
269
- puts "Device Instance by name: #{element_data}"
270
-
271
- element_data.should_not be_nil
272
- element_data.should_not be_empty
273
- end
274
-
275
- it "should get all devices via a user" do
276
- element_data = user.device_instances
277
-
278
- #puts "Device Instance: #{element_data}"
279
-
280
- element_data.should_not be_nil
281
- element_data.should_not be_empty
282
- end
283
-
284
- it "should get all devices via a user with a filter" do
285
- element_data = user.device_instances({:name => device_instance.name})
286
-
287
- #puts "Device Instance: #{element_data}"
288
-
289
- element_data.should_not be_nil
290
- element_data.should_not be_empty
291
- end
292
-
293
- end
294
-
295
- describe MachineShop::Mapping do
296
-
297
- auth_token, user = MachineShop::User.authenticate(
298
- :email => publisher_username,
299
- :password => publisher_password
300
- )
301
-
302
- it "should get a geocoded address" do
303
- element_data = MachineShop::Mapping.geocode(
304
- {
305
- :address => "1600 Amphitheatre Parkway, Mountain View, CA",
306
- :sensor => "false"
307
- },
308
- auth_token)
309
-
310
- #puts "GEO: #{element_data}"
311
-
312
- element_data.should_not be_nil
313
- element_data.should_not be_empty
314
- end
315
-
316
- it "should get directions" do
317
- element_data = MachineShop::Mapping.directions(
318
- {
319
- :origin => "Denver",
320
- :destination => "Boston",
321
- :sensor => "false"
322
- },
323
- auth_token)
324
-
325
- #puts "GEO: #{element_data}"
326
-
327
- element_data.should_not be_nil
328
- element_data.should_not be_empty
329
- end
330
-
331
- it "should get distance" do
332
- element_data = MachineShop::Mapping.distance(
333
- {
334
- :origins => "Vancouver BC",
335
- :destinations => "San Francisco",
336
- :mode => "bicycling",
337
- :language => "fr-FR",
338
- :sensor => "false"
339
- },
340
- auth_token)
341
-
342
- #puts "GEO: #{element_data}"
343
-
344
- element_data.should_not be_nil
345
- element_data.should_not be_empty
346
- end
347
-
348
- end
349
-
350
- describe MachineShop::Meter do
351
-
352
- auth_token, user = MachineShop::User.authenticate(
353
- :email => publisher_username,
354
- :password => publisher_password
355
- )
356
-
357
- it "should get all meter data" do
358
- element_data = MachineShop::Meter.all({}, auth_token)
359
-
360
- puts "element_data from all: #{element_data}"
361
-
362
- element_data.should_not be_nil
363
- element_data.should_not be_empty
364
- end
365
-
366
- it "should get meter by id " do
367
-
368
- element_data = MachineShop::Meter.retrieve('527ac622ff73462550000001', auth_token)
369
- puts "meter by id : #{element_data}"
370
- element_data.should_not be_nil
371
- end
372
-
373
- it "should get meters via a user" do
374
- element_data = user.meters
375
-
376
- puts "meters via user: #{element_data}"
377
- element_data.should_not be_nil
378
- element_data.should_not be_empty
379
- end
380
-
381
- end
382
-
383
- describe MachineShop::Report do
384
-
385
- auth_token, user = MachineShop::User.authenticate(
386
- :email => publisher_username,
387
- :password => publisher_password
388
- )
389
-
390
- it "should get all report data" do
391
- element_data = MachineShop::Report.all({}, auth_token)
392
-
393
- puts "element_data: #{element_data}"
394
-
395
- element_data.should_not be_nil
396
- element_data.should_not be_empty
397
- end
398
-
399
-
400
-
401
- it "should get report of specific device" do
402
- element_data = MachineShop::Report.all(
403
- ({:device_instance_id => '531f00e5981800ad58000006',
404
- :per_page=>'1000',
405
- #:created_at_between=>'2013-11-04T00:00:00_2014-03-19T17:02:00'
406
- }), auth_token)
407
-
408
- puts "element data of f00e5981800ad58000006 #{element_data} "
409
-
410
- element_data.should_not be_nil
411
- end
412
-
413
-
414
- end
415
-
416
- describe MachineShop::Rule do
417
-
418
- rules=nil
419
- auth_token, user = MachineShop::User.authenticate(
420
- :email => publisher_username,
421
- :password => publisher_password
422
- )
423
- it "should get all the rules " do
424
-
425
- #rules = MachineShop::Rule.new.get_rules(auth_token)
426
- rules = MachineShop::Rule.all({},auth_token)
427
- #get_rule
428
- puts "rules haru : #{rules}"
429
- rules.should_not be_nil
430
-
431
-
432
- end
433
-
434
- create_hash = {
435
- :devices=>"52585e1d981800bab2000479",
436
- :device_instances=>{},
437
- :rule=>{
438
- :active=>true,
439
- :description=>"bajratest",
440
- :condition=>{
441
- :type=>"and_rule_condition",
442
- :rule_conditions=>{
443
-
444
- :property=>"var",
445
- :value=>"30",
446
- :type=>"equal_rule_condition"
447
-
448
- }
449
- },
450
- :then_actions=>{
451
- :priority=>"1",
452
- :send_to=>"abc@me.com",
453
- :type=>"email_rule_action"
454
- }
455
- }
456
- }
457
-
458
- it "should create rule" do
459
-
460
- ruleById = MachineShop::Rule.retrieve(rules[0].id,auth_token)
461
- puts "rule by id : #{ruleById}"
462
- ruleById.should_not be_nil
463
-
464
- end
465
-
466
-
467
-
468
- it "should get rule by id" do
469
- ruleById = MachineShop::Rule.retrieve(rules[0].id,auth_token)
470
- puts "rule by id : #{ruleById}"
471
- ruleById.should_not be_nil
472
-
473
- end
474
-
475
-
476
-
477
- it "should get get join rule conditions" do
478
- test_data = MachineShop::Rule.get_join_rule_conditions(auth_token)
479
- puts "rule comparison : #{test_data.inspect}"
480
- test_data.should_not be_nil
481
-
482
- end
483
-
484
-
485
- it "should get comparison rule_conditions" do
486
- test_data = MachineShop::Rule.new.get_comparison_rule_conditions(auth_token)
487
- puts "comparison rule condition : #{test_data.inspect}"
488
- test_data.should_not be_nil
489
-
490
- end
491
-
492
-
493
- it "should get rules deleted" do
494
- test_data = MachineShop::Rule.get_by_device_instance(auth_token,'52585e1d981800bab2000478')
495
- puts "rule by_device_instance : #{test_data.inspect}"
496
- test_data.should_not be_nil
497
-
498
- end
499
-
500
- it "should get deleted rule" do
501
- test_data = MachineShop::Rule.get_deleted(auth_token)
502
- puts "deleted rule : #{test_data.inspect}"
503
- test_data.should_not be_nil
504
-
505
- end
506
- it "should get create rule" do
507
- test_data = MachineShop::Rule.create({},auth_token)
508
- puts "deleted rule : #{test_data.inspect}"
509
- test_data.should_not be_nil
510
-
511
- end
512
-
513
-
514
- end
515
-
516
- describe MachineShop::Util do
517
-
518
- auth_token, user = MachineShop::User.authenticate(
519
- :email => publisher_username,
520
- :password => publisher_password
521
- )
522
-
523
- it "should send an email" do
524
- element_data = MachineShop::Utility.email(
525
- {
526
- :subject => "hello there From the machineshop",
527
- :body => "The body of an email goes here.\nEscaped chars should work.",
528
- :to => "niroj@bajratechnologies.com"
529
- },
530
- auth_token)
531
-
532
- puts "element_data: #{element_data}"
533
-
534
- #element_data[:http_code].should be(200)
535
- end
536
-
537
- it "should send an sms" do
538
- element_data = MachineShop::Utility.sms(
539
- {
540
- :message => "This is a text from the platform",
541
- :to => "13035551212"
542
- },
543
- auth_token)
544
-
545
- #puts "element_data: #{element_data}"
546
-
547
- element_data[:http_code].should be(200)
548
- end
549
-
550
- end
551
-
552
- describe MachineShop::Customer do
553
-
554
- #update = MachineShop::Customer.update
555
-
556
-
557
-
558
-
559
- auth_token , user = MachineShop::User.authenticate(
560
- :email => publisher_username,
561
- :password => publisher_password
562
- )
563
-
564
- customers = nil
565
-
566
- it "should get all the customers " do
567
- customers = MachineShop::Customer.all({}, auth_token)
568
-
569
- puts "customers are #{customers}"
570
-
571
- #puts "first customer is : #{customers[0][:id]}"
572
-
573
- customers.should_not be_nil
574
- end
575
-
576
-
577
- it "should create customer " do
578
-
579
- customer = MachineShop::Customer.create({:email=>"gvhfbs@bajratechnologies.com",
580
- :password=>'password',
581
- :notification_method=>'sms',
582
- :first_name=>'niroj',:last_name=>'sapkota',
583
- :phone_number=>'98989898989',
584
- :company_name=>'technology co'
585
-
586
- },auth_token)
587
- puts "created customer is #{customer}"
588
- customer.should_not be_nil
589
- end
590
-
591
-
592
- specificCustomer = nil
593
- it "should get customer by customer id " do
594
-
595
- specificCustomer = MachineShop::Customer.retrieve(customers[0].id, auth_token)
596
- puts "customer id- #{customers[0].id} is #{specificCustomer}"
597
- specificCustomer.should_not be_nil
598
- end
599
-
600
-
601
-
602
- #success test
603
-
604
- it "should delete customer with id " do
605
-
606
- #puts
607
- puts "deleting customer with id : #{customers[0].id}"
608
-
609
- delete = specificCustomer.delete
610
- #delete = MachineShop::Customer.delete(customers[0].id,auth_token)
611
- puts "delete #{delete}"
612
- delete.http_code.should eq 200
613
- end
614
-
615
-
616
-
617
- it "should update the customer with id " do
618
-
619
- puts "updating customer with id : #{customers[0].id}"
620
- update = MachineShop::Customer.update(customers[0].id,auth_token,{:notification_method => 'email'})
621
- puts "update #{update}"
622
- end
623
- end
624
-