rainforest-cli 1.9.0 → 1.10.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +5 -0
- data/README.md +6 -1
- data/lib/rainforest_cli/csv_importer.rb +16 -3
- data/lib/rainforest_cli/options.rb +7 -3
- data/lib/rainforest_cli/version.rb +1 -1
- data/spec/rainforest_cli/csv_importer_spec.rb +89 -28
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: aefdfe1a4a5ecf73e5b919dbbf6da1bb7d13f5c1
|
4
|
+
data.tar.gz: 88ee5992a58f3340535f3b1d21ed54f8fea53cc8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4787e5a59c11fe612a982f2aabb51e6ed5386e2fef18fb5771aad337d54334b7514dfe4ea82d5738c51fb39496e28e13a5f3d440ac0773298eba2082c724969f
|
7
|
+
data.tar.gz: 64c1ef609db5add1c02c19e04d241e73520123b15d5c3fc60c0388875e3994b670f934c6b78b52c5f3750edc829445477a8b71ed544a6a676d4b9dd9d6ebf1b7
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,10 @@
|
|
1
1
|
# Rainforest CLI Changelog
|
2
2
|
|
3
|
+
## 1.10.0 - 19th September 2016
|
4
|
+
- Add `--overwrite-variable` option to overwrite existing tabular variables if the
|
5
|
+
desired variable name is already taken when uploading CSVs. (ebf4ab90c5db2589695eaf6c3d4c4206bad17e7b,
|
6
|
+
@epaulet)
|
7
|
+
|
3
8
|
## 1.9.0 - 14th September 2016
|
4
9
|
- Add `upload-csv` command for updating tabular variables without starting a new run.
|
5
10
|
(069e943cd94cbb08e6f00347ab6c8327372897ce, @epaulet)
|
data/README.md
CHANGED
@@ -136,11 +136,16 @@ rainforest report --run-id <run-id> --junit-file rainforest.xml
|
|
136
136
|
|
137
137
|
#### Updating Tabular Variables
|
138
138
|
|
139
|
-
Upload a CSV
|
139
|
+
Upload a CSV to create a new tabular variables.
|
140
140
|
```bash
|
141
141
|
rainforest csv-upload --import-variable-csv-file PATH/TO/CSV.csv --import-variable-name my_variable
|
142
142
|
```
|
143
143
|
|
144
|
+
Upload a CSV to update an existing tabular variables.
|
145
|
+
```bash
|
146
|
+
rainforest csv-upload --import-variable-csv-file PATH/TO/CSV.csv --import-variable-name my_variable --overwrite-variable
|
147
|
+
```
|
148
|
+
|
144
149
|
## Options
|
145
150
|
|
146
151
|
### General
|
@@ -9,6 +9,7 @@ module RainforestCli
|
|
9
9
|
def initialize(options)
|
10
10
|
@generator_name = options.import_name
|
11
11
|
@file = options.import_file_name
|
12
|
+
@overwrite_variable = options.overwrite_variable
|
12
13
|
end
|
13
14
|
|
14
15
|
def row_data columns, values
|
@@ -27,9 +28,21 @@ module RainforestCli
|
|
27
28
|
end
|
28
29
|
raise 'Invalid schema in CSV. You must include headers in first row.' if !columns
|
29
30
|
|
30
|
-
|
31
|
+
if @overwrite_variable
|
32
|
+
puts 'Checking for existing tabular variables.'
|
33
|
+
generators = http_client.get('/generators')
|
34
|
+
generator = generators.find { |g| g['name'] == @generator_name }
|
35
|
+
|
36
|
+
if generator
|
37
|
+
puts 'Existing tabular variable found. Deleting old data.'
|
38
|
+
response = http_client.delete("/generators/#{generator['id']}")
|
39
|
+
raise "Error deleting old tabular variable: #{response['error']}" if response['error']
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
print 'Creating new tabular variable'
|
31
44
|
response = http_client.post '/generators', { name: @generator_name, description: @generator_name, columns: columns }
|
32
|
-
raise "Error creating
|
45
|
+
raise "Error creating tabular variable: #{response['error']}" if response['error']
|
33
46
|
puts "\t[OK]"
|
34
47
|
|
35
48
|
@columns = response['columns']
|
@@ -39,7 +52,7 @@ module RainforestCli
|
|
39
52
|
p = ProgressBar.create(title: 'Rows', total: rows.count, format: '%a %B %p%% %t')
|
40
53
|
|
41
54
|
# Insert the data
|
42
|
-
Parallel.each(rows, in_threads:
|
55
|
+
Parallel.each(rows, in_threads: RainforestCli::THREADS, finish: lambda { |_item, _i, _result| p.increment }) do |row|
|
43
56
|
response = http_client.post("/generators/#{@generator_id}/rows", {data: row_data(@columns, row)})
|
44
57
|
raise response['error'] if response['error']
|
45
58
|
end
|
@@ -7,7 +7,7 @@ module RainforestCli
|
|
7
7
|
attr_reader :command, :token, :tags, :conflict, :browsers, :site_id, :environment_id,
|
8
8
|
:import_file_name, :import_name, :custom_url, :description, :folder,
|
9
9
|
:debug, :file_name, :test_folder, :embed_tests, :app_source_url, :crowd, :run_id,
|
10
|
-
:junit_file
|
10
|
+
:junit_file, :overwrite_variable
|
11
11
|
|
12
12
|
TOKEN_NOT_REQUIRED = %w{new validate}.freeze
|
13
13
|
|
@@ -42,14 +42,18 @@ module RainforestCli
|
|
42
42
|
@crowd = value
|
43
43
|
end
|
44
44
|
|
45
|
-
opts.on('--import-variable-csv-file FILE', 'Import step variables; CSV data') do |value|
|
45
|
+
opts.on('--import-variable-csv-file FILE', 'Import tabular step variables; CSV data') do |value|
|
46
46
|
@import_file_name = value
|
47
47
|
end
|
48
48
|
|
49
|
-
opts.on('--import-variable-name NAME', 'Import step variables; Name of variable
|
49
|
+
opts.on('--import-variable-name NAME', 'Import tabular step variables; Name of variable') do |value|
|
50
50
|
@import_name = value
|
51
51
|
end
|
52
52
|
|
53
|
+
opts.on('--overwrite-variable', 'Import tabular step variables: overwrite existing variable if desired variable name is taken') do
|
54
|
+
@overwrite_variable = true
|
55
|
+
end
|
56
|
+
|
53
57
|
opts.on('--git-trigger', 'Only run if the last commit contains @rainforestapp') do |_value|
|
54
58
|
@git_trigger = true
|
55
59
|
end
|
@@ -8,43 +8,104 @@ describe RainforestCli::CSVImporter do
|
|
8
8
|
end
|
9
9
|
|
10
10
|
describe '.import' do
|
11
|
-
let(:options) { instance_double('RainforestCli::Options', import_name: 'variables', import_file_name: csv_file) }
|
11
|
+
let(:options) { instance_double('RainforestCli::Options', import_name: 'variables', import_file_name: csv_file, overwrite_variable: overwrite_variable) }
|
12
12
|
subject { described_class.new(options) }
|
13
13
|
let(:columns) { %w(email pass) }
|
14
|
+
let(:generator_id) { 12345 }
|
15
|
+
let(:existing_generators) { [] }
|
14
16
|
|
15
17
|
let(:success_response) do
|
16
18
|
{
|
17
|
-
'id' =>
|
19
|
+
'id' => generator_id,
|
18
20
|
'columns' => columns.each_with_index.map { |col, i| { 'id' => i, 'name' => col } },
|
19
21
|
}
|
20
22
|
end
|
21
23
|
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
24
|
+
before do
|
25
|
+
allow(http_client).to receive(:get).with('/generators').and_return(existing_generators)
|
26
|
+
end
|
27
|
+
|
28
|
+
shared_examples 'it properly uploads variables' do
|
29
|
+
it 'makes the proper API interactions' do
|
30
|
+
expect(http_client).to receive(:post)
|
31
|
+
.with('/generators', {
|
32
|
+
name: 'variables',
|
33
|
+
description: 'variables',
|
34
|
+
columns: columns.map {|col| { name: col } },
|
35
|
+
})
|
36
|
+
.and_return success_response
|
37
|
+
|
38
|
+
expect(http_client).to receive(:post)
|
39
|
+
.with("/generators/#{generator_id}/rows", {
|
40
|
+
data: {
|
41
|
+
0 => 'russ@rainforestqa.com',
|
42
|
+
1 => 'abc123',
|
43
|
+
},
|
44
|
+
}).and_return({})
|
45
|
+
|
46
|
+
expect(http_client).to receive(:post)
|
47
|
+
.with("/generators/#{generator_id}/rows", {
|
48
|
+
data: {
|
49
|
+
0 => 'bob@example.com',
|
50
|
+
1 => 'hunter2',
|
51
|
+
},
|
52
|
+
}).and_return({})
|
53
|
+
subject.import
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
context 'without variable overwriting' do
|
58
|
+
let(:overwrite_variable) { nil }
|
59
|
+
|
60
|
+
it_behaves_like 'it properly uploads variables'
|
61
|
+
|
62
|
+
context 'tabular variable with given name already exists' do
|
63
|
+
let(:existing_generators) do
|
64
|
+
[
|
65
|
+
{
|
66
|
+
'id' => 98765,
|
67
|
+
'name' => 'existing',
|
68
|
+
},
|
69
|
+
{
|
70
|
+
'id' => generator_id,
|
71
|
+
'name' => 'variables',
|
72
|
+
},
|
73
|
+
]
|
74
|
+
end
|
75
|
+
|
76
|
+
before do
|
77
|
+
expect(http_client).to_not receive(:delete)
|
78
|
+
end
|
79
|
+
|
80
|
+
it_behaves_like 'it properly uploads variables'
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
context 'with variable overwriting' do
|
85
|
+
let(:overwrite_variable) { true }
|
86
|
+
|
87
|
+
it_behaves_like 'it properly uploads variables'
|
88
|
+
|
89
|
+
context 'tabular variable with given name already exists' do
|
90
|
+
let(:existing_generators) do
|
91
|
+
[
|
92
|
+
{
|
93
|
+
'id' => 98765,
|
94
|
+
'name' => 'existing',
|
95
|
+
},
|
96
|
+
{
|
97
|
+
'id' => generator_id,
|
98
|
+
'name' => 'variables',
|
99
|
+
},
|
100
|
+
]
|
101
|
+
end
|
102
|
+
|
103
|
+
before do
|
104
|
+
expect(http_client).to receive(:delete).with("/generators/#{generator_id}").and_return({})
|
105
|
+
end
|
106
|
+
|
107
|
+
it_behaves_like 'it properly uploads variables'
|
108
|
+
end
|
48
109
|
end
|
49
110
|
end
|
50
111
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rainforest-cli
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.10.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Russell Smith
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2016-09-
|
12
|
+
date: 2016-09-19 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: httparty
|