sauce_whisk 0.0.5 → 0.0.7

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- YjUxZmUwNTM1MjkxMmM2OWYxZjViZDhlYjVhMjAwNTQzZWYzNWQzOQ==
4
+ Mjk5OWJjYTU5ZDI4Nzc2NWI1MzliODZkNzQyNWI0YmNiNDUzM2U1YQ==
5
5
  data.tar.gz: !binary |-
6
- YzFjZTE5OTZjZTE4YWNkNzc0NjBiMWZiNTA0MjM5Yjc4YzM5YTUwMQ==
6
+ ZWY3ZWY5ZDk4ZTlmYTM1NmUxYjFmMmYwMGI3YTdmZDU5YzJjZWI5Yw==
7
7
  !binary "U0hBNTEy":
8
8
  metadata.gz: !binary |-
9
- NDczNThiNDI5NmJlM2IzNzg4MzIxMDMyYWRlM2FlMmMyZjVlMTQ4MjRjMDRl
10
- NDU1YWEyMjk3ZDhmNDJiNDZhM2ZkY2E0NDBlZjBjNTcwOTVjYTkxNGNiNjA4
11
- ZGVmMGRlNTAzZGUxNzQ2YjJkMzdlNTE3MDgyZjI0Zjc4YjJmZmE=
9
+ M2NkNmY3ZGY4OTM0YTI5YTBkZTVmZWY5ZGFiZGE3NGI5ZGIyZDRmNzBlYjVk
10
+ ODIxMTJjYzQzZTNkMjcyNGFjYTJkNWMzYzY4NjRmZjI4NWM4OGUwZTNlMzZl
11
+ MmU5MDM4NDkwYTU3ZjFlNTczY2ZjMTdjODZmZDZkYzJmMTkzNGI=
12
12
  data.tar.gz: !binary |-
13
- ODQ4OGJiNzdiZGQ5MmY2ZjI5MTI2YTEwYzhmNTdhOTg1YTZkMWEwM2JiMmUz
14
- OTdmOGUxMTE4ZWJkZGYzZDk3OTg2ZjFlYzNmYTFmNjU5ZDMzNGQ1ZGU0NGU1
15
- NzkyNjNlZDg2NDQ3OTY3YWNjNDc3ZDVkZGE1NDhhYzRhMGQ0NzE=
13
+ MDA0YzI3MWYzMzExYjk5NGUxYTQwM2UwMTc4MmJhOWU3ZTJmYTYyMmRmNWE1
14
+ N2UyNGJmOTljYTZiZWI3N2M1MDc5ODgxYmUyMmRhNmM3YTUxMWYzNDVjYzg3
15
+ YzQxZDE5YzI4ODFmNGMyYjY5OTU0MzliMzc3YzJmNWIxOTZlZDA=
data/.ruby-gemset ADDED
@@ -0,0 +1 @@
1
+ sauce_whisk
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ ruby-1.9.3-p362
data/Gemfile CHANGED
@@ -1,7 +1,9 @@
1
1
  source 'https://rubygems.org'
2
2
 
3
+ gem "pry"
4
+
3
5
  group :test do
4
- # gem 'psych', "2.0.0", :path => "./vendor/psych"
6
+ gem 'psych', "2.0.0", :path => "./vendor/psych"
5
7
  end
6
8
 
7
9
  gemspec
data/README.md CHANGED
@@ -88,6 +88,36 @@ There are three types of asset for Sauce Labs jobs: screenshots, video and logs.
88
88
  video = job.video # A single Asset, holding the video
89
89
  ```
90
90
 
91
+ ### Tunnels
92
+
93
+ Tunnels give information about currently running [Sauce Connect](https://saucelabs.com/docs/connect) tunnels for a given user.
94
+
95
+ #### Fetching All Active Tunnels
96
+
97
+ ```ruby
98
+ all_tunnels = SauceWhisk::Tunnels.all # An array of SauceWhisk::Tunnel objects
99
+ all_tunnels_as_json = SauceWhisk::Tunnels.all(:fetch_each => false) # An array of Tunnel IDs
100
+ ```
101
+
102
+ #### Details for a specific tunnel
103
+ ```ruby
104
+ tunnel = SauceWhisk::Tunnels.fetch(tunnel_id) # An instance of Tunnel
105
+ tunnel.id # The Tunnel, um, id.
106
+ tunnel.owner # The Sauce Account responsible for the tunnel -- The Credentials used to open it
107
+ tunnel.status # Whether or not the tunnel is open
108
+ tunnel.host # The Sauce Labs machine hosting the other end of the Tunnel
109
+ tunnel.creation_time # When the tunnel was opened, in Epoch time
110
+ ```
111
+
112
+ #### Stopping a Tunnel
113
+
114
+ ```ruby
115
+ tunnel = SauceWhisk::Tunnels.fetch tunnel_id
116
+ tunnel.stop # Stops the Tunnel
117
+
118
+ SauceWhisk::Tunnels.stop tunnel_id # Stops the tunnel with the given id
119
+ ```
120
+
91
121
  ### Logger
92
122
 
93
123
  You can set a custom logger object, passing anything that responds to puts:
data/changelog.markdown CHANGED
@@ -1,4 +1,6 @@
1
1
  # Major Version 0
2
+ ### 0.0.6
3
+ * Correct RestClient -- Actually require it
2
4
  ### 0.0.5
3
5
  * Added Sauce class
4
6
 
data/lib/sauce_whisk.rb CHANGED
@@ -1,9 +1,11 @@
1
+ require "sauce_whisk/rest_request_builder"
1
2
  require "sauce_whisk/version"
2
3
  require "sauce_whisk/jobs"
3
4
  require "sauce_whisk/assets"
4
5
  require "sauce_whisk/tunnels"
5
6
  require "sauce_whisk/info"
6
- require "sauce_whisk/rest_request_builder"
7
+ require "sauce_whisk/accounts"
8
+
7
9
 
8
10
 
9
11
  module SauceWhisk
@@ -0,0 +1,38 @@
1
+ module SauceWhisk
2
+ class Accounts
3
+ extend SauceWhisk::RestRequestBuilder
4
+
5
+ def self.fetch(user_id = ENV["SAUCE_USERNAME"], get_concurrency = true)
6
+ user_parameters = JSON.parse get "users/#{user_id}"
7
+ concurrencies = get_concurrency ? concurrency_for(user_id) : {}
8
+
9
+ account_parameters = user_parameters.merge concurrencies
10
+ return Account.new(account_parameters)
11
+ end
12
+
13
+ def self.concurrency_for(job_id = ENV["SAUCE_USERNAME"], type = :both)
14
+ concurrencies = JSON.parse (get "#{job_id}/limits"), :symbolize_names => true
15
+ case type
16
+ when :mac
17
+ return concurrencies[:mac_concurrency]
18
+ when :total
19
+ return concurrencies[:concurrency]
20
+ else
21
+ return {:mac_concurrency => concurrencies[:mac_concurrency],
22
+ :total_concurrency => concurrencies[:concurrency]
23
+ }
24
+ end
25
+ end
26
+
27
+ end
28
+ class Account
29
+ attr_reader :access_key, :username, :minutes, :total_concurrency, :mac_concurrency
30
+ def initialize(options)
31
+ @access_key = options[:access_key]
32
+ @username = options[:id]
33
+ @minutes = options[:minutes]
34
+ @total_concurrency = options[:total_concurrency]
35
+ @mac_concurrency = options[:mac_concurrency]
36
+ end
37
+ end
38
+ end
@@ -1,4 +1,5 @@
1
1
  require "json"
2
+ require 'sauce_whisk/rest_request_builder'
2
3
 
3
4
  module SauceWhisk
4
5
  class Sauce
@@ -17,7 +17,7 @@ module SauceWhisk
17
17
 
18
18
  def self.change_status(job_id, status)
19
19
  put job_id, {"passed" => status}.to_json
20
- rescue e
20
+ rescue StandardError => e
21
21
  SauceWhisk.logger "Unable to change_status for #{job_id} to #{status}\nReason: #{e.to_s}"
22
22
  end
23
23
 
@@ -1,3 +1,5 @@
1
+ require "rest-client"
2
+
1
3
  module SauceWhisk
2
4
  module RestRequestBuilder
3
5
 
@@ -8,8 +8,9 @@ module SauceWhisk
8
8
  "#{SauceWhisk.username}/tunnels"
9
9
  end
10
10
 
11
- def self.all(fetch_each = false)
11
+ def self.all(opts = {:fetch_each => true})
12
12
  all_tunnels = JSON.parse get
13
+ fetch_each = opts[:fetch_each]
13
14
 
14
15
  unless fetch_each
15
16
  return all_tunnels
@@ -1,3 +1,3 @@
1
1
  module SauceWhisk
2
- VERSION = "0.0.5"
2
+ VERSION = "0.0.7"
3
3
  end
@@ -0,0 +1,92 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: get
5
+ uri: https://<SAUCE_USERNAME>:<SAUCE_ACCESS_KEY>@saucelabs.com/rest/v1/users/<SAUCE_USERNAME>
6
+ body:
7
+ encoding: US-ASCII
8
+ string: ''
9
+ headers:
10
+ Accept:
11
+ - '*/*; q=0.5, application/xml'
12
+ Accept-Encoding:
13
+ - gzip, deflate
14
+ User-Agent:
15
+ - Ruby
16
+ response:
17
+ status:
18
+ code: 200
19
+ message: OK
20
+ headers:
21
+ Server:
22
+ - nginx/0.7.62
23
+ Date:
24
+ - Mon, 17 Jun 2013 12:23:32 GMT
25
+ Content-Type:
26
+ - application/json
27
+ Connection:
28
+ - keep-alive
29
+ Pragma:
30
+ - no-cache
31
+ Cache-Control:
32
+ - no-cache
33
+ X-Frame-Options:
34
+ - DENY
35
+ Set-Cookie:
36
+ - csrf_token=80e9120e6d754f5d8df8772d5aadd0a8; expires="Mon, 17-Jun-2013 12:40:47
37
+ GMT"; Max-Age=600; Path=/
38
+ - metrics=a5621049f443f276d44c2d73fbbba83bef904ae8455aede851a14edfb2450fb7e3255e49;
39
+ Path=/
40
+ Content-Length:
41
+ - '143'
42
+ body:
43
+ encoding: US-ASCII
44
+ string: '{"access_key": "<SAUCE_ACCESS_KEY>", "minutes": "infinite", "id": "<SAUCE_USERNAME>",
45
+ "subscribed": true, "can_run_manual": true}'
46
+ http_version:
47
+ recorded_at: Mon, 17 Jun 2013 12:30:46 GMT
48
+ - request:
49
+ method: get
50
+ uri: https://<SAUCE_USERNAME>:<SAUCE_ACCESS_KEY>@saucelabs.com/rest/v1/<SAUCE_USERNAME>/limits
51
+ body:
52
+ encoding: US-ASCII
53
+ string: ''
54
+ headers:
55
+ Accept:
56
+ - '*/*; q=0.5, application/xml'
57
+ Accept-Encoding:
58
+ - gzip, deflate
59
+ User-Agent:
60
+ - Ruby
61
+ response:
62
+ status:
63
+ code: 200
64
+ message: OK
65
+ headers:
66
+ Server:
67
+ - nginx/0.7.62
68
+ Date:
69
+ - Mon, 17 Jun 2013 12:23:33 GMT
70
+ Content-Type:
71
+ - application/json
72
+ Connection:
73
+ - keep-alive
74
+ Pragma:
75
+ - no-cache
76
+ Cache-Control:
77
+ - no-cache
78
+ X-Frame-Options:
79
+ - DENY
80
+ Set-Cookie:
81
+ - csrf_token=d38cdde67f2a155f7083ebe872c582bd; expires="Mon, 17-Jun-2013 12:40:48
82
+ GMT"; Max-Age=600; Path=/
83
+ - metrics=897a82824950620d8e70dbda2cb339666f9a60cba2d2ef02beab418680a125d3df05bb41;
84
+ Path=/
85
+ Content-Length:
86
+ - '76'
87
+ body:
88
+ encoding: US-ASCII
89
+ string: '{"mac_concurrency": 5, "concurrency": 20}'
90
+ http_version:
91
+ recorded_at: Mon, 17 Jun 2013 12:30:47 GMT
92
+ recorded_with: VCR 2.5.0
@@ -0,0 +1,29 @@
1
+ require "spec_helper"
2
+
3
+ describe SauceWhisk::Account do
4
+ describe "#new" do
5
+ it "sets any options passed in as a hash" do
6
+ options = {
7
+ :access_key => 12345,
8
+ :minutes => 23,
9
+ :id => "someone"
10
+ }
11
+
12
+ test_account = SauceWhisk::Account.new options
13
+ test_account.access_key.should eq 12345
14
+ test_account.minutes.should eq 23
15
+ test_account.username.should eq "someone"
16
+ end
17
+
18
+ it "sets concurrency figures" do
19
+ concurrencies = {
20
+ :mac_concurrency => 23,
21
+ :total_concurrency => 100
22
+ }
23
+
24
+ test_account = SauceWhisk::Account.new concurrencies
25
+ test_account.mac_concurrency.should eq 23
26
+ test_account.total_concurrency.should eq 100
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,49 @@
1
+ require "spec_helper"
2
+
3
+ describe SauceWhisk::Accounts, :vcr => {:cassette_name => "accounts"} do
4
+ let(:auth) {"#{ENV["SAUCE_USERNAME"]}:#{ENV["SAUCE_ACCESS_KEY"]}"}
5
+
6
+ describe "#fetch" do
7
+ it "fetches the passed in account" do
8
+ SauceWhisk::Accounts.fetch ENV["SAUCE_USERNAME"]
9
+ assert_requested :get, "https://#{auth}@saucelabs.com/rest/v1/users/#{ENV["SAUCE_USERNAME"]}"
10
+ end
11
+
12
+ it "returns an Account object" do
13
+ SauceWhisk::Accounts.fetch(ENV["SAUCE_USERNAME"]).should be_an_instance_of SauceWhisk::Account
14
+ end
15
+
16
+ it "includes the concurrency by default" do
17
+ account = SauceWhisk::Accounts.fetch ENV["SAUCE_USERNAME"]
18
+ assert_requested :get, "https://#{auth}@saucelabs.com/rest/v1/#{ENV["SAUCE_USERNAME"]}/limits"
19
+ account.total_concurrency.should eq 20
20
+ account.mac_concurrency.should eq 5
21
+ end
22
+
23
+ it "should not include concurrency when conservative is set to false" do
24
+ account = SauceWhisk::Accounts.fetch(ENV["SAUCE_USERNAME"], false)
25
+ assert_not_requested :get, "https://#{auth}@saucelabs.com/rest/v1/#{ENV["SAUCE_USERNAME"]}/limits"
26
+ account.total_concurrency.should be_nil
27
+ end
28
+ end
29
+
30
+ describe "#concurrency_for" do
31
+ it "fetches the concurrency for the passed in account" do
32
+ SauceWhisk::Accounts.concurrency_for ENV["SAUCE_USERNAME"]
33
+ assert_requested :get, "https://#{auth}@saucelabs.com/rest/v1/#{ENV["SAUCE_USERNAME"]}/limits"
34
+ end
35
+
36
+ it "returns concurrencies with altered names" do
37
+ expected_hash = {:mac_concurrency => 5, :total_concurrency => 20}
38
+ SauceWhisk::Accounts.concurrency_for(ENV["SAUCE_USERNAME"]).should eq expected_hash
39
+ end
40
+
41
+ it "returns just mac as an integer when requested" do
42
+ SauceWhisk::Accounts.concurrency_for(ENV["SAUCE_USERNAME"], :mac).should eq 5
43
+ end
44
+
45
+ it "returns just the total as an integer when requested" do
46
+ SauceWhisk::Accounts.concurrency_for(ENV["SAUCE_USERNAME"], :total).should eq 20
47
+ end
48
+ end
49
+ end
@@ -86,8 +86,8 @@ describe SauceWhisk::Jobs do
86
86
  SauceWhisk::Jobs.stop "9591ce8519f043f8b3bea0462923c883"
87
87
  end
88
88
 
89
- it "does something else interesting when the job does not exist" do
90
- SauceWhisk::Jobs.stop "job_id"
89
+ it "throws a ResourceNotFound error when the job isn't found" do
90
+ expect {SauceWhisk::Jobs.stop("job_id")}.to raise_exception RestClient::ResourceNotFound
91
91
  end
92
92
 
93
93
  end
@@ -15,18 +15,18 @@ describe SauceWhisk::Tunnels, :vcr => {:cassette_name => "tunnels"} do
15
15
  end
16
16
 
17
17
  context "called without the 'fetch' parameter" do
18
- it "returns an array of strings" do
18
+ it "returns an array of Tunnels" do
19
19
  tunnels = SauceWhisk::Tunnels.all
20
20
  tunnels.should be_an_instance_of Array
21
- tunnels.each {|tunnel| tunnel.should be_an_instance_of String }
21
+ tunnels.each {|tunnel| tunnel.should be_an_instance_of SauceWhisk::Tunnel}
22
22
  end
23
23
  end
24
24
 
25
- context "called with the fetch parameter" do
26
- it "returns an array of Tunnels" do
27
- tunnels = SauceWhisk::Tunnels.all(:fetch)
25
+ context "called with the fetch parameter set false" do
26
+ it "returns an array of strings" do
27
+ tunnels = SauceWhisk::Tunnels.all(:fetch_each => false)
28
28
  tunnels.should be_an_instance_of Array
29
- tunnels.each {|tunnel| tunnel.should be_an_instance_of SauceWhisk::Tunnel}
29
+ tunnels.each {|tunnel| tunnel.should be_an_instance_of String }
30
30
  end
31
31
  end
32
32
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sauce_whisk
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.5
4
+ version: 0.0.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dylan Lacey
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-06-13 00:00:00.000000000 Z
11
+ date: 2013-06-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rest-client
@@ -88,12 +88,15 @@ extensions: []
88
88
  extra_rdoc_files: []
89
89
  files:
90
90
  - .gitignore
91
+ - .ruby-gemset
92
+ - .ruby-version
91
93
  - Gemfile
92
94
  - LICENSE.txt
93
95
  - README.md
94
96
  - Rakefile
95
97
  - changelog.markdown
96
98
  - lib/sauce_whisk.rb
99
+ - lib/sauce_whisk/accounts.rb
97
100
  - lib/sauce_whisk/assets.rb
98
101
  - lib/sauce_whisk/info.rb
99
102
  - lib/sauce_whisk/jobs.rb
@@ -101,6 +104,7 @@ files:
101
104
  - lib/sauce_whisk/tunnels.rb
102
105
  - lib/sauce_whisk/version.rb
103
106
  - sauce_whisk.gemspec
107
+ - spec/fixtures/vcr_cassettes/accounts.yml
104
108
  - spec/fixtures/vcr_cassettes/assets.yml
105
109
  - spec/fixtures/vcr_cassettes/info.yml
106
110
  - spec/fixtures/vcr_cassettes/jobs.yml
@@ -108,6 +112,8 @@ files:
108
112
  - spec/fixtures/vcr_cassettes/no_tunnels.yml
109
113
  - spec/fixtures/vcr_cassettes/rest_request.yml
110
114
  - spec/fixtures/vcr_cassettes/tunnels.yml
115
+ - spec/lib/sauce_whisk/account_spec.rb
116
+ - spec/lib/sauce_whisk/accounts_spec.rb
111
117
  - spec/lib/sauce_whisk/asset_spec.rb
112
118
  - spec/lib/sauce_whisk/assets_spec.rb
113
119
  - spec/lib/sauce_whisk/info_spec.rb
@@ -190,6 +196,7 @@ specification_version: 4
190
196
  summary: Sauce_Whisk lets you mix extra data into your Sauce test results! Fetch and
191
197
  update Job details, screenshots, videos and logs.
192
198
  test_files:
199
+ - spec/fixtures/vcr_cassettes/accounts.yml
193
200
  - spec/fixtures/vcr_cassettes/assets.yml
194
201
  - spec/fixtures/vcr_cassettes/info.yml
195
202
  - spec/fixtures/vcr_cassettes/jobs.yml
@@ -197,6 +204,8 @@ test_files:
197
204
  - spec/fixtures/vcr_cassettes/no_tunnels.yml
198
205
  - spec/fixtures/vcr_cassettes/rest_request.yml
199
206
  - spec/fixtures/vcr_cassettes/tunnels.yml
207
+ - spec/lib/sauce_whisk/account_spec.rb
208
+ - spec/lib/sauce_whisk/accounts_spec.rb
200
209
  - spec/lib/sauce_whisk/asset_spec.rb
201
210
  - spec/lib/sauce_whisk/assets_spec.rb
202
211
  - spec/lib/sauce_whisk/info_spec.rb