testrail_helper 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +21 -0
- data/README.md +54 -0
- data/Rakefile +1 -0
- data/bin/console +14 -0
- data/bin/setup +7 -0
- data/lib/testrail_api.rb +106 -0
- data/lib/testrail_helper/version.rb +3 -0
- data/lib/testrail_helper.rb +63 -0
- data/test.rb +16 -0
- data/testrail_helper.gemspec +26 -0
- metadata +111 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: b0179f957feb7015c0c1bbe73b2148bc0f4076e9
|
4
|
+
data.tar.gz: cc020c62417f7e41b551dacec736bd7c74b30f1f
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 7544aabd9f8a76675525ab6e900f0d643dc862790fb00e0474b6038db34586c6cff8b3ea4ad3d14200c853a5b83c0a14cf95f0f346e023f2f31f549a176584ac
|
7
|
+
data.tar.gz: 06d0def213fcae9fab84f83d2bb747103bf2654bdb5eeb0bef95596fcb6dd3fde9e4eba2245faa10b94a6f52dcdb01e9c7e26fcebe3f6f8cf83921ffcb3d5749
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2015 kinezu
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,54 @@
|
|
1
|
+
# testrail_helper
|
2
|
+
|
3
|
+
A gem to help you pull test cases from test suites and filter them out by whatever fields you want. Iterate through multiple suites to construct comprehensive reports.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'testrail_helper'
|
11
|
+
```
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install testrail_helperr
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
|
23
|
+
```ruby
|
24
|
+
# testrail_helper a new client
|
25
|
+
client = TestrailHelper::Client.new(username:'',password: '',url: 'https://blarg.testrail.com/')
|
26
|
+
|
27
|
+
# get a list of test cases by passing in the suite_id and section_id
|
28
|
+
cases = client.get_all_test_cases_in_section(suite_id: "729", section_id: "8")
|
29
|
+
|
30
|
+
# filter your list down by various required fields. AND
|
31
|
+
filtered_cases_with_and = client.filter_by_fields_and(cases,priority_id: 4, created_by: 34)
|
32
|
+
|
33
|
+
# filter your list down by various required fields. OR
|
34
|
+
filtered_cases_with_or = client.filter_by_fields_or(cases,priority_id: 4, created_by: 34)
|
35
|
+
|
36
|
+
# write list to file
|
37
|
+
write_to_file(cases,'/output/filename')
|
38
|
+
```
|
39
|
+
|
40
|
+
## Development
|
41
|
+
|
42
|
+
After checking out the re`po, run `bin/setup` to install dependencies. Then, run `rake false` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
43
|
+
|
44
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
45
|
+
|
46
|
+
## Contributing
|
47
|
+
|
48
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/kinezu/testrail_helper. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](contributor-covenant.org) code of conduct.
|
49
|
+
|
50
|
+
|
51
|
+
## License
|
52
|
+
|
53
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
54
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "testrail_helper"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start
|
data/bin/setup
ADDED
data/lib/testrail_api.rb
ADDED
@@ -0,0 +1,106 @@
|
|
1
|
+
#
|
2
|
+
# TestRail API binding for Ruby (API v2, available since TestRail 3.0)
|
3
|
+
#
|
4
|
+
# Learn more:
|
5
|
+
#
|
6
|
+
# http://docs.gurock.com/testrail-api2/start
|
7
|
+
# http://docs.gurock.com/testrail-api2/accessing
|
8
|
+
#
|
9
|
+
# Copyright Gurock Software GmbH. See license.md for details.
|
10
|
+
#
|
11
|
+
|
12
|
+
require 'net/http'
|
13
|
+
require 'net/https'
|
14
|
+
require 'uri'
|
15
|
+
require 'json'
|
16
|
+
|
17
|
+
module TestRail
|
18
|
+
class APIClient
|
19
|
+
@url = ''
|
20
|
+
@user = ''
|
21
|
+
@password = ''
|
22
|
+
|
23
|
+
attr_accessor :user
|
24
|
+
attr_accessor :password
|
25
|
+
|
26
|
+
def initialize(base_url)
|
27
|
+
if !base_url.match(/\/$/)
|
28
|
+
base_url += '/'
|
29
|
+
end
|
30
|
+
@url = base_url + 'index.php?/api/v2/'
|
31
|
+
end
|
32
|
+
|
33
|
+
#
|
34
|
+
# Send Get
|
35
|
+
#
|
36
|
+
# Issues a GET request (read) against the API and returns the result
|
37
|
+
# (as Ruby hash).
|
38
|
+
#
|
39
|
+
# Arguments:
|
40
|
+
#
|
41
|
+
# uri The API method to call including parameters
|
42
|
+
# (e.g. get_case/1)
|
43
|
+
#
|
44
|
+
def send_get(uri)
|
45
|
+
_send_request('GET', uri, nil)
|
46
|
+
end
|
47
|
+
|
48
|
+
#
|
49
|
+
# Send POST
|
50
|
+
#
|
51
|
+
# Issues a POST request (write) against the API and returns the result
|
52
|
+
# (as Ruby hash).
|
53
|
+
#
|
54
|
+
# Arguments:
|
55
|
+
#
|
56
|
+
# uri The API method to call including parameters
|
57
|
+
# (e.g. add_case/1)
|
58
|
+
# data The data to submit as part of the request (as
|
59
|
+
# Ruby hash, strings must be UTF-8 encoded)
|
60
|
+
#
|
61
|
+
def send_post(uri, data)
|
62
|
+
_send_request('POST', uri, data)
|
63
|
+
end
|
64
|
+
|
65
|
+
private
|
66
|
+
def _send_request(method, uri, data)
|
67
|
+
url = URI.parse(@url + uri)
|
68
|
+
if method == 'POST'
|
69
|
+
request = Net::HTTP::Post.new(url.path + '?' + url.query)
|
70
|
+
request.body = JSON.dump(data)
|
71
|
+
else
|
72
|
+
request = Net::HTTP::Get.new(url.path + '?' + url.query)
|
73
|
+
end
|
74
|
+
request.basic_auth(@user, @password)
|
75
|
+
request.add_field('Content-Type', 'application/json')
|
76
|
+
|
77
|
+
conn = Net::HTTP.new(url.host, url.port)
|
78
|
+
if url.scheme == 'https'
|
79
|
+
conn.use_ssl = true
|
80
|
+
conn.verify_mode = OpenSSL::SSL::VERIFY_NONE
|
81
|
+
end
|
82
|
+
response = conn.request(request)
|
83
|
+
|
84
|
+
if response.body && !response.body.empty?
|
85
|
+
result = JSON.parse(response.body)
|
86
|
+
else
|
87
|
+
result = {}
|
88
|
+
end
|
89
|
+
|
90
|
+
if response.code != '200'
|
91
|
+
if result && result.key?('error')
|
92
|
+
error = '"' + result['error'] + '"'
|
93
|
+
else
|
94
|
+
error = 'No additional error message received'
|
95
|
+
end
|
96
|
+
raise APIError.new('TestRail API returned HTTP %s (%s)' %
|
97
|
+
[response.code, error])
|
98
|
+
end
|
99
|
+
|
100
|
+
result
|
101
|
+
end
|
102
|
+
end
|
103
|
+
|
104
|
+
class APIError < StandardError
|
105
|
+
end
|
106
|
+
end
|
@@ -0,0 +1,63 @@
|
|
1
|
+
require 'testrail'
|
2
|
+
require 'json'
|
3
|
+
|
4
|
+
require File.expand_path(File.dirname(__FILE__) + '/testrail_api')
|
5
|
+
|
6
|
+
module TestrailHelper
|
7
|
+
|
8
|
+
class Client
|
9
|
+
|
10
|
+
def initialize(params = {})
|
11
|
+
@client = TestRail::APIClient.new(params[:url])
|
12
|
+
@client.user = params[:username]
|
13
|
+
@client.password = params[:password]
|
14
|
+
@client
|
15
|
+
end
|
16
|
+
|
17
|
+
def get_all_test_cases_in_section(params={})
|
18
|
+
uri = "get_cases/#{params[:section_id]}&suite_id=#{params[:suite_id]}"
|
19
|
+
uri = uri + "&priority_id=#{params[:priority]}" if params[:priority]
|
20
|
+
@client.send_get(uri)
|
21
|
+
end
|
22
|
+
|
23
|
+
def filter_by_fields_and(list,params={})
|
24
|
+
@master_list = list
|
25
|
+
@temp_list = []
|
26
|
+
h = params.map
|
27
|
+
h.each do |par|
|
28
|
+
puts par
|
29
|
+
@master_list.each do |x|
|
30
|
+
puts x
|
31
|
+
if x.fetch(par[0].to_s) == par[1]
|
32
|
+
@temp_list << x
|
33
|
+
end
|
34
|
+
end
|
35
|
+
@master_list = @temp_list
|
36
|
+
@temp_list = []
|
37
|
+
end
|
38
|
+
@master_list
|
39
|
+
end
|
40
|
+
|
41
|
+
def filter_by_fields_or(list,params={})
|
42
|
+
@temp_list = list
|
43
|
+
h = params.map
|
44
|
+
h.each do |par|
|
45
|
+
puts par
|
46
|
+
@master_list.each do |x|
|
47
|
+
puts x
|
48
|
+
if x.fetch(par[0].to_s) == par[1]
|
49
|
+
@temp_list << x
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
@master_list = @temp_list.uniq
|
54
|
+
@master_list
|
55
|
+
end
|
56
|
+
|
57
|
+
def write_to_file(list,filename)
|
58
|
+
File.open(filename, "w+") do |f|
|
59
|
+
list.each { |element| f.puts(element) }
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
data/test.rb
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/lib/testrail_helper')
|
2
|
+
|
3
|
+
# create a new client
|
4
|
+
client = TestrailHelper::Client.new(username:'',password: '',url: 'https://blarg.testrail.com/')
|
5
|
+
|
6
|
+
# get a list of test cases by passing in the suite_id and section_id
|
7
|
+
cases = client.get_all_test_cases_in_section(suite_id: "729", section_id: "8")
|
8
|
+
|
9
|
+
# filter your list down by various required fields. AND
|
10
|
+
filtered_cases_with_and = client.filter_by_fields_and(cases,priority_id: 4, created_by: 34)
|
11
|
+
|
12
|
+
# filter your list down by various required fields. OR
|
13
|
+
filtered_cases_with_or = client.filter_by_fields_or(cases,priority_id: 4, created_by: 34)
|
14
|
+
|
15
|
+
# write list to file
|
16
|
+
write_to_file(cases,'/output/filename')
|
@@ -0,0 +1,26 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'testrail_helper/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "testrail_helper"
|
8
|
+
spec.version = TestrailHelper::VERSION
|
9
|
+
spec.authors = ["kinezu"]
|
10
|
+
|
11
|
+
spec.summary = "A tool to help get and parse testrail data"
|
12
|
+
spec.description = "A tool to help get and parse testrail data"
|
13
|
+
spec.homepage = "https://github.com/kinezu/testrail_helper"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
17
|
+
spec.bindir = "exe"
|
18
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_dependency 'json'
|
22
|
+
spec.add_dependency 'testrail'
|
23
|
+
|
24
|
+
spec.add_development_dependency "bundler", "~> 1.10"
|
25
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
26
|
+
end
|
metadata
ADDED
@@ -0,0 +1,111 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: testrail_helper
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- kinezu
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-07-12 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: json
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: testrail
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: bundler
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '1.10'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '1.10'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rake
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '10.0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '10.0'
|
69
|
+
description: A tool to help get and parse testrail data
|
70
|
+
email:
|
71
|
+
executables: []
|
72
|
+
extensions: []
|
73
|
+
extra_rdoc_files: []
|
74
|
+
files:
|
75
|
+
- Gemfile
|
76
|
+
- LICENSE.txt
|
77
|
+
- README.md
|
78
|
+
- Rakefile
|
79
|
+
- bin/console
|
80
|
+
- bin/setup
|
81
|
+
- lib/testrail_api.rb
|
82
|
+
- lib/testrail_helper.rb
|
83
|
+
- lib/testrail_helper/version.rb
|
84
|
+
- test.rb
|
85
|
+
- testrail_helper.gemspec
|
86
|
+
homepage: https://github.com/kinezu/testrail_helper
|
87
|
+
licenses:
|
88
|
+
- MIT
|
89
|
+
metadata: {}
|
90
|
+
post_install_message:
|
91
|
+
rdoc_options: []
|
92
|
+
require_paths:
|
93
|
+
- lib
|
94
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
95
|
+
requirements:
|
96
|
+
- - ">="
|
97
|
+
- !ruby/object:Gem::Version
|
98
|
+
version: '0'
|
99
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
requirements: []
|
105
|
+
rubyforge_project:
|
106
|
+
rubygems_version: 2.2.2
|
107
|
+
signing_key:
|
108
|
+
specification_version: 4
|
109
|
+
summary: A tool to help get and parse testrail data
|
110
|
+
test_files: []
|
111
|
+
has_rdoc:
|