rainforest-cli 0.0.12 → 0.0.13

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,7 @@
1
1
  ---
2
- !binary "U0hBMQ==":
3
- metadata.gz: !binary |-
4
- YjNhOTdmMWViMTU0OTIwNzE1NTI5YzkzZTc3NzgxZjIyY2Y3MTY2OQ==
5
- data.tar.gz: !binary |-
6
- Y2MwYTljZWQ2Zjg5ODE0ZmIzMTM3M2E2Y2MwYWM4MzFkMDk5ZWFjOQ==
7
- !binary "U0hBNTEy":
8
- metadata.gz: !binary |-
9
- ODlmZTMzNjIzMzQ1NjhiYTM0ZTZiNWQ5Nzk2ZjE0N2RmODI2Y2VmMGMyNWZl
10
- ZDQ0ODljM2FlZDM0OWMxN2E3NjBiNjNkZTQ2MTE2ZGQ5NWRiM2NiYjhjOTA0
11
- YTllZWMwMGQwYzQxODI0YTA3NTQ1ODc5YTU5ZmQxMmI2OWRlZWI=
12
- data.tar.gz: !binary |-
13
- ZTgzN2M1NzE3N2U1NjQ5Yzg0NmVhNjM3MmFkZTI1YzA3MzhhZTk1YTY4ZDQ0
14
- YjQ4OTljZDQ2ZWYwM2QyYTUxMDM5OWIxNWZkMzYwMjQ0ZDA4ZWI5NmQzYmRh
15
- Y2Y2ODhmNGYzYTVmZTk4ZDczYzkwYjVhNzBiODY3ZmNlMzIyYzI=
2
+ SHA1:
3
+ metadata.gz: 72def45d00f529b7b7c35d23b097dbe3e0e0ea89
4
+ data.tar.gz: 0a6312c46e0862e24272881e6adb6fc22c477423
5
+ SHA512:
6
+ metadata.gz: 1a1c28ebb3bce9b4ef7788b75c098055f7b83f588d1797a547d44c65d7490cef80ccb43179873f8fbcbd9d5dac095bc567d40904c3dd596f0d2cb011d9623579
7
+ data.tar.gz: 4a37fbeb379b70c1f7b8b284ff5f61c56fc02c7a26a35f8b893bdb53879ed48a2ce0fd3954670db3cab7a8f0b24aca467c48fbe34b56e991191b384ba9fbf8b4
checksums.yaml.gz.sig ADDED
Binary file
data.tar.gz.sig ADDED
@@ -0,0 +1 @@
1
+ �?��̛��Ɛe��Q���H���} �I�&O�Hf��A��b�z��V�: �[�����X�߬v���bu�����֬��gR�~��-"дja�0H6`5ާz$�8őP��p�+V[�xq��#)� ��E�J})$�up#�� �!��iս}�XA*��� ��� N���l��h wͥ$k��r��i �u(��R���� ��ŗ{y�A�J�L�'���
data/.gitignore CHANGED
@@ -16,3 +16,5 @@ test/tmp
16
16
  test/version_tmp
17
17
  tmp
18
18
  tags
19
+
20
+ *.csv
data/.rspec CHANGED
@@ -1,4 +1,3 @@
1
1
  --color
2
- --format=nested
3
2
  --require spec_helper
4
3
  --profile
data/.rvmrc CHANGED
@@ -1 +1 @@
1
- rvm use 1.9.3@rainforest-cli --create
1
+ rvm use 2.1.2@rainforest-cli --create
data/.travis.yml CHANGED
@@ -2,9 +2,6 @@ language: ruby
2
2
  rvm:
3
3
  - 2.0.0
4
4
  - 1.9.3
5
- - jruby-19mode
6
- - rbx-2.1.1
7
5
  - ruby-head
8
- - jruby-head
9
6
 
10
7
  script: bundle exec rspec spec
data/Gemfile CHANGED
@@ -4,5 +4,5 @@ source 'https://rubygems.org'
4
4
  gemspec
5
5
 
6
6
  group :test do
7
- gem "rspec"
7
+ gem "rspec", "2.14"
8
8
  end
@@ -1,14 +1,28 @@
1
1
  require "rainforest/cli/version"
2
2
  require "rainforest/cli/options"
3
+ require "rainforest/cli/csv_importer"
3
4
  require "httparty"
4
5
  require "json"
5
6
 
6
7
  module Rainforest
7
8
  module Cli
8
- API_URL = 'https://app.rainforestqa.com/api/1/runs'
9
-
9
+ API_URL = 'https://app.rainforestqa.com/api/1'.freeze
10
+
10
11
  def self.start(args)
11
12
  @options = OptionParser.new(args)
13
+
14
+ if @options.import_file_name && @options.import_name
15
+ unless File.exists?(@options.import_file_name)
16
+ puts "Input file: #{@options.import_file_name} not found"
17
+ exit 2
18
+ end
19
+
20
+ delete_generator(@options.import_name)
21
+ CSVImporter.new(@options.import_name, @options.import_file_name, @options.token).import
22
+ elsif @options.import_file_name || @options.import_name
23
+ puts "You must pass both --import-variable-csv-file and --import-variable-name"
24
+ exit 2
25
+ end
12
26
 
13
27
  post_opts = {}
14
28
  if !@options.tags.empty?
@@ -23,7 +37,7 @@ module Rainforest
23
37
 
24
38
  puts "Issuing run"
25
39
 
26
- response = post(API_URL, post_opts)
40
+ response = post(API_URL + '/runs', post_opts)
27
41
 
28
42
  if response['error']
29
43
  puts "Error starting your run: #{response['error']}"
@@ -37,7 +51,7 @@ module Rainforest
37
51
 
38
52
  while running
39
53
  Kernel.sleep 5
40
- response = get "#{API_URL}/#{run_id}?gem_version=#{Rainforest::Cli::VERSION}"
54
+ response = get "#{API_URL}/runs/#{run_id}?gem_version=#{Rainforest::Cli::VERSION}"
41
55
  if response
42
56
  if %w(queued in_progress sending_webhook waiting_for_callback).include?(response["state"])
43
57
  puts "Run #{run_id} is #{response['state']} and is #{response['current_progress']['percent']}% complete"
@@ -54,6 +68,24 @@ module Rainforest
54
68
  end
55
69
  true
56
70
  end
71
+
72
+ def self.list_generators
73
+ get("#{API_URL}/generators")
74
+ end
75
+
76
+ def self.delete_generator(name)
77
+ generator = list_generators.find {|g| g['type'] == 'custom' && g['key'] == name }
78
+ delete("#{API_URL}/generators/#{generator['id']}") if generator
79
+ end
80
+
81
+ def self.delete(url, body = {})
82
+ response = HTTParty.delete url, {
83
+ body: body,
84
+ headers: {"CLIENT_TOKEN" => @options.token}
85
+ }
86
+
87
+ JSON.parse(response.body)
88
+ end
57
89
 
58
90
  def self.post(url, body = {})
59
91
  response = HTTParty.post url, {
@@ -0,0 +1,55 @@
1
+ #!/usr/bin/env ruby
2
+ require 'csv'
3
+ require 'httparty'
4
+ require 'parallel'
5
+ require 'ruby-progressbar'
6
+
7
+ module Rainforest
8
+ module Cli
9
+ class CSVImporter
10
+ def initialize name, file, token
11
+ @generator_name = name
12
+ @file = file
13
+ @token = token
14
+ end
15
+
16
+ def post url, body
17
+ HTTParty.post(Rainforest::Cli::API_URL + url, body: body.to_json, headers: {'Content-Type' => 'application/json', "CLIENT_TOKEN" => @token})
18
+ end
19
+
20
+ def row_data columns, values
21
+ Hash[(columns.map {|c| c['id']}).zip(values)]
22
+ end
23
+
24
+ def import
25
+ rows = []
26
+ CSV.foreach(@file, encoding: 'windows-1251:utf-8') do |row|
27
+ rows << row
28
+ end
29
+
30
+ # Create the generator
31
+ columns = rows.shift.map do |column|
32
+ {name: column.downcase.strip.gsub(/\s/, '_')}
33
+ end
34
+ raise 'Invalid schema in CSV. You must include headers in first row.' if not columns
35
+
36
+ print "Creating custom step variable"
37
+ response = post "/generators", { name: @generator_name, description: @generator_name, columns: columns }
38
+ raise "Error creating custom step variable: #{response.code}, #{response.body}" unless response.code == 201
39
+ puts "\t[OK]"
40
+
41
+ @columns = response['columns']
42
+ @generator_id = response['id']
43
+
44
+ puts "Uploading data..."
45
+ p = ProgressBar.create(title: 'Rows', total: rows.count, format: '%a %B %p%% %t')
46
+
47
+ # Insert the data
48
+ Parallel.each(rows, in_processes: 16, finish: lambda { |item, i, result| p.increment }) do |row|
49
+ response = post("/generators/#{@generator_id}/rows", {data: row_data(@columns, row)})
50
+ raise response.to_json unless response.code == 201
51
+ end
52
+ end
53
+ end
54
+ end
55
+ end
@@ -10,7 +10,7 @@ module Rainforest
10
10
  end
11
11
 
12
12
  class OptionParser
13
- attr_reader :command, :token, :tags, :conflict, :browsers
13
+ attr_reader :command, :token, :tags, :conflict, :browsers, :import_file_name, :import_name
14
14
 
15
15
  VALID_BROWSERS = %w{chrome firefox safari ie8 ie9}.freeze
16
16
 
@@ -20,6 +20,14 @@ module Rainforest
20
20
  @browsers = nil
21
21
 
22
22
  @parsed = ::OptionParser.new do |opts|
23
+ opts.on("--import-variable-csv-file FILE", "Import step variables; CSV data") do |value|
24
+ @import_file_name = value
25
+ end
26
+
27
+ opts.on("--import-variable-name NAME", "Import step variables; Name of variable (note, will be replaced if exists)") do |value|
28
+ @import_name = value
29
+ end
30
+
23
31
  opts.on("--fg", "Run the tests in foreground.") do |value|
24
32
  @foreground = value
25
33
  end
@@ -1,5 +1,5 @@
1
1
  module Rainforest
2
2
  module Cli
3
- VERSION = "0.0.12"
3
+ VERSION = "0.0.13"
4
4
  end
5
5
  end
@@ -8,8 +8,8 @@ Gem::Specification.new do |spec|
8
8
  spec.version = Rainforest::Cli::VERSION
9
9
  spec.authors = ["Simon Mathieu", "Russell Smith"]
10
10
  spec.email = ["simon@rainforestqa.com", "russ@rainforestqa.com"]
11
- spec.description = %q{Command line utility for RainforestQA}
12
- spec.summary = %q{Command line utility for RainforestQA}
11
+ spec.description = %q{Command line utility for Rainforest QA}
12
+ spec.summary = %q{Command line utility for Rainforest QA}
13
13
  spec.homepage = "https://www.rainforestqa.com/"
14
14
  spec.license = "MIT"
15
15
 
@@ -19,6 +19,11 @@ Gem::Specification.new do |spec|
19
19
  spec.require_paths = ["lib"]
20
20
 
21
21
  spec.add_dependency "httparty"
22
+ spec.add_dependency "parallel"
23
+ spec.add_dependency "ruby-progressbar"
22
24
  spec.add_development_dependency "bundler", "~> 1.3"
23
25
  spec.add_development_dependency "rake"
26
+
27
+ spec.cert_chain = ['certs/ukd1.pem']
28
+ spec.signing_key = File.expand_path("~/.ssh/gem-private_key.pem") if $0 =~ /gem\z/
24
29
  end
data/spec/options_spec.rb CHANGED
@@ -1,6 +1,16 @@
1
1
  describe Rainforest::Cli::OptionParser do
2
2
  subject { Rainforest::Cli::OptionParser.new(args) }
3
3
 
4
+ context "importing csv file" do
5
+ let(:args) { ["--import-variable-csv-file", "some_file.csv"] }
6
+ its(:import_file_name) { should == "some_file.csv" }
7
+ end
8
+
9
+ context "importing name" do
10
+ let(:args) { ["--import-variable-name", "some_name"] }
11
+ its(:import_name) { should == "some_name" }
12
+ end
13
+
4
14
  context "run all tests" do
5
15
  let(:args) { ["run", "all"] }
6
16
  its(:tests) { should == ["all"]}
metadata CHANGED
@@ -1,59 +1,110 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rainforest-cli
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.12
4
+ version: 0.0.13
5
5
  platform: ruby
6
6
  authors:
7
7
  - Simon Mathieu
8
8
  - Russell Smith
9
9
  autorequire:
10
10
  bindir: bin
11
- cert_chain: []
12
- date: 2013-12-19 00:00:00.000000000 Z
11
+ cert_chain:
12
+ - |
13
+ -----BEGIN CERTIFICATE-----
14
+ MIIDljCCAn6gAwIBAgIBATANBgkqhkiG9w0BAQUFADBIMR0wGwYDVQQDDBRydXNz
15
+ ZWxsLmhvd2FyZC5zbWl0aDESMBAGCgmSJomT8ixkARkWAm1lMRMwEQYKCZImiZPy
16
+ LGQBGRYDY29tMB4XDTE0MDgxNDA1Mzc0NloXDTE1MDgxNDA1Mzc0NlowSDEdMBsG
17
+ A1UEAwwUcnVzc2VsbC5ob3dhcmQuc21pdGgxEjAQBgoJkiaJk/IsZAEZFgJtZTET
18
+ MBEGCgmSJomT8ixkARkWA2NvbTCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoC
19
+ ggEBAKSK3Sfhs+miX1jdDywi9Khl1QjIn2DUM1U+bou6WLkQaOUtqhX/T2jHltQ9
20
+ Olc7jaz4XO5g+YngELX2tGFA6zbUnvaHXnPz23hPsP5TUErFAI1VJYl9fmQY6sEd
21
+ komCT8jZwB09Re20iyZtNsEMa8gagR7qX1wgPVqxAncE7OJ5stwHxcSQABfGrInF
22
+ sdZyjqNE2D0NxWZoWTC7CERaRNUm12y4NpHm6fdvtbgsB14WQjaqOYYUmFffT89Y
23
+ c0TOOGUV1aMbjpRUZFhu/tAaWGW+GfZnln9F3GWYJMRzC5k8+awB1vXgnfqZH007
24
+ ef85jyOutXfKKYyXcWlvrDMoTTUCAwEAAaOBijCBhzAJBgNVHRMEAjAAMAsGA1Ud
25
+ DwQEAwIEsDAdBgNVHQ4EFgQUFws4YIAtrBiQdbpWgqwcYd/+Hh4wJgYDVR0RBB8w
26
+ HYEbcnVzc2VsbC5ob3dhcmQuc21pdGhAbWUuY29tMCYGA1UdEgQfMB2BG3J1c3Nl
27
+ bGwuaG93YXJkLnNtaXRoQG1lLmNvbTANBgkqhkiG9w0BAQUFAAOCAQEADHQJiURU
28
+ PJbfReV/MgIum917Vktz9Zv1GPzKzY5EkIL34FylaSernkITWe6GcsMb8yNrdG/1
29
+ eSyAvx32v/L3ef2mp7kHXbtzcXBq3xyCewfH6AfX3dm65CfgaeGx+qK/F/bl0iiZ
30
+ SQpNWk3RB/7deQThk3SYD8jS8n1d7KSRLogpXnSNWRyaSHtZ2x7T2qVpn4lp1PIi
31
+ /4Hg5bJrO0VqDlVG8UvsFbFB24ZNDQVq73MLZFNez0UBhOZVo4kBlSUvyEv5YLlA
32
+ wWdLLpBZZ1O4GE0uzQovmTiis4iyCF+8tFIgjbM/FVwKUBV6OZpxs4FOBtR1mK6L
33
+ lj0cPcKRm/FZUw==
34
+ -----END CERTIFICATE-----
35
+ date: 2014-08-14 00:00:00.000000000 Z
13
36
  dependencies:
14
37
  - !ruby/object:Gem::Dependency
15
38
  name: httparty
16
39
  requirement: !ruby/object:Gem::Requirement
17
40
  requirements:
18
- - - ! '>='
41
+ - - ">="
19
42
  - !ruby/object:Gem::Version
20
43
  version: '0'
21
44
  type: :runtime
22
45
  prerelease: false
23
46
  version_requirements: !ruby/object:Gem::Requirement
24
47
  requirements:
25
- - - ! '>='
48
+ - - ">="
49
+ - !ruby/object:Gem::Version
50
+ version: '0'
51
+ - !ruby/object:Gem::Dependency
52
+ name: parallel
53
+ requirement: !ruby/object:Gem::Requirement
54
+ requirements:
55
+ - - ">="
56
+ - !ruby/object:Gem::Version
57
+ version: '0'
58
+ type: :runtime
59
+ prerelease: false
60
+ version_requirements: !ruby/object:Gem::Requirement
61
+ requirements:
62
+ - - ">="
63
+ - !ruby/object:Gem::Version
64
+ version: '0'
65
+ - !ruby/object:Gem::Dependency
66
+ name: ruby-progressbar
67
+ requirement: !ruby/object:Gem::Requirement
68
+ requirements:
69
+ - - ">="
70
+ - !ruby/object:Gem::Version
71
+ version: '0'
72
+ type: :runtime
73
+ prerelease: false
74
+ version_requirements: !ruby/object:Gem::Requirement
75
+ requirements:
76
+ - - ">="
26
77
  - !ruby/object:Gem::Version
27
78
  version: '0'
28
79
  - !ruby/object:Gem::Dependency
29
80
  name: bundler
30
81
  requirement: !ruby/object:Gem::Requirement
31
82
  requirements:
32
- - - ~>
83
+ - - "~>"
33
84
  - !ruby/object:Gem::Version
34
85
  version: '1.3'
35
86
  type: :development
36
87
  prerelease: false
37
88
  version_requirements: !ruby/object:Gem::Requirement
38
89
  requirements:
39
- - - ~>
90
+ - - "~>"
40
91
  - !ruby/object:Gem::Version
41
92
  version: '1.3'
42
93
  - !ruby/object:Gem::Dependency
43
94
  name: rake
44
95
  requirement: !ruby/object:Gem::Requirement
45
96
  requirements:
46
- - - ! '>='
97
+ - - ">="
47
98
  - !ruby/object:Gem::Version
48
99
  version: '0'
49
100
  type: :development
50
101
  prerelease: false
51
102
  version_requirements: !ruby/object:Gem::Requirement
52
103
  requirements:
53
- - - ! '>='
104
+ - - ">="
54
105
  - !ruby/object:Gem::Version
55
106
  version: '0'
56
- description: Command line utility for RainforestQA
107
+ description: Command line utility for Rainforest QA
57
108
  email:
58
109
  - simon@rainforestqa.com
59
110
  - russ@rainforestqa.com
@@ -62,10 +113,10 @@ executables:
62
113
  extensions: []
63
114
  extra_rdoc_files: []
64
115
  files:
65
- - .gitignore
66
- - .rspec
67
- - .rvmrc
68
- - .travis.yml
116
+ - ".gitignore"
117
+ - ".rspec"
118
+ - ".rvmrc"
119
+ - ".travis.yml"
69
120
  - CHANGELOG.md
70
121
  - Gemfile
71
122
  - LICENSE.txt
@@ -73,6 +124,7 @@ files:
73
124
  - Rakefile
74
125
  - bin/rainforest
75
126
  - lib/rainforest/cli.rb
127
+ - lib/rainforest/cli/csv_importer.rb
76
128
  - lib/rainforest/cli/options.rb
77
129
  - lib/rainforest/cli/version.rb
78
130
  - rainforest-cli.gemspec
@@ -89,20 +141,20 @@ require_paths:
89
141
  - lib
90
142
  required_ruby_version: !ruby/object:Gem::Requirement
91
143
  requirements:
92
- - - ! '>='
144
+ - - ">="
93
145
  - !ruby/object:Gem::Version
94
146
  version: '0'
95
147
  required_rubygems_version: !ruby/object:Gem::Requirement
96
148
  requirements:
97
- - - ! '>='
149
+ - - ">="
98
150
  - !ruby/object:Gem::Version
99
151
  version: '0'
100
152
  requirements: []
101
153
  rubyforge_project:
102
- rubygems_version: 2.0.5
154
+ rubygems_version: 2.2.2
103
155
  signing_key:
104
156
  specification_version: 4
105
- summary: Command line utility for RainforestQA
157
+ summary: Command line utility for Rainforest QA
106
158
  test_files:
107
159
  - spec/cli_spec.rb
108
160
  - spec/options_spec.rb
metadata.gz.sig ADDED
Binary file