testrailv2 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,15 @@
1
+ ---
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ NmUyOWQ2ZTkyMjVlMmU3OTIwMGY1NzVjYzFhZmQ2MDE0NDNmMjg5Mg==
5
+ data.tar.gz: !binary |-
6
+ ZTIxOTUxNzY3MWE0ZjU2Mzg1NzA0MGVlZjU5MjU3Y2Y1ZjhkZjU2OA==
7
+ SHA512:
8
+ metadata.gz: !binary |-
9
+ MTY1Mjc0ZWMzN2JiZDI1MDRkYjA3ZmVkZjdhMzU0ZGRiODRkOTIxNWNiY2Iz
10
+ NmNiZTg3ZjFmYTFiZjM3MGM1MDA5MzE1ZmY2MDQ0ZmNjMDM4Yzc1NWIyYTFi
11
+ Yjc3ZGU3YzhjZjMxMDZkZWY2ZTA3ZjZiZWE0N2U2YzNhY2I4NTc=
12
+ data.tar.gz: !binary |-
13
+ MmNkNzdiYmMzOGY1MTlmM2JlOWE2YTZmY2I5OTMwY2UyZmRlZTNmNDc4OWM4
14
+ MTcwZGNjMWI4NjMyNTQ3MzVmZTg4ZTE2ODc2NDgyZmE5NWExMmY4ZjU2NjQ4
15
+ NDk3YjMxMDliYTI2YjU2MDQxMjVmNmZhN2Y5NzY4OTM1OWVjY2M=
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Declare your gem's dependencies in testrail.gemspec.
4
+ # Bundler will treat runtime dependencies like base dependencies, and
5
+ # development dependencies will be added by default to the :development group.
6
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2012 Kristine Robison
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,59 @@
1
+ # testrail [![Gem Version](https://badge.fury.io/rb/testrail.png)](http://badge.fury.io/rb/testrail) [![Travis Status](https://travis-ci.org/krobi64/testrail.png)](https://travis-ci.org/krobi64/testrail) [![Code Climate](https://codeclimate.com/github/krobi64/testrail.png)](https://codeclimate.com/github/krobi64/testrail) [![Gemnasium](https://gemnasium.com/krobi64/testrail.png)](https://gemnasium.com/krobi64/testrail)
2
+
3
+ A Ruby client that tries to match TestRail's API one-to-one, while still
4
+ providing an idiomatic interface.
5
+
6
+ ## Installation
7
+ gem install testrail
8
+
9
+ or in Gemfile
10
+
11
+ gem "testrail"
12
+
13
+ ## Configuration
14
+
15
+ By default, Testrail's configuration points to their hosted service. You can set your api_key in either of the following ways:
16
+
17
+ Testrail.config.api_key = 'my_api_key'
18
+
19
+ Testrail.configure do |c|
20
+ c.api_key = 'my_api_key'
21
+ end
22
+
23
+ Configuration options [defaults] include:
24
+ * server: the location of the TestRail application. ['https://example.testrail.com']
25
+ * api_path: the path on the server that provides the api. ['/index.php?/miniapi/']
26
+ * api_key: the api_key required to access the TestRail application. [nil]
27
+ * logger: the logging instance to use for capturing log messages. [Logger.new]
28
+
29
+ ## Usage
30
+
31
+ client = Testrail::Client.new
32
+ response = client.add_case(<section_id>, body: {
33
+ title: "A New Test",
34
+ priority_id: 4,
35
+ references: 'url_to_issue_tracker'
36
+ })
37
+
38
+ test_id = response.payload if response.success
39
+ error = response.error unless response.success
40
+
41
+ # ToDo
42
+
43
+ * Add Testrail specific objects to represent the Testrail domain.
44
+
45
+ # Contributing to testrail
46
+
47
+ * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet.
48
+ * Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it.
49
+ * Fork the project.
50
+ * Start a feature/bugfix branch.
51
+ * Commit and push until you are happy with your contribution.
52
+ * Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
53
+ * Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
54
+
55
+ ## Copyright
56
+
57
+ Copyright (c) 2012 Kristine Robison. See LICENSE.txt for
58
+ further details.
59
+
data/Rakefile ADDED
@@ -0,0 +1,38 @@
1
+ #!/usr/bin/env rake
2
+ begin
3
+ require 'bundler/setup'
4
+ rescue LoadError
5
+ puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
6
+ end
7
+
8
+ Bundler::GemHelper.install_tasks
9
+
10
+ require 'rspec/core'
11
+ require 'rspec/core/rake_task'
12
+ desc "Run all specs in spec directory"
13
+ RSpec::Core::RakeTask.new(:spec) do |spec|
14
+ spec.pattern = FileList['spec/**/*_spec.rb']
15
+ end
16
+
17
+ RSpec::Core::RakeTask.new(:simplecov) do |spec|
18
+ spec.pattern = 'spec/**/*_spec.rb'
19
+ spec.rcov = true
20
+ end
21
+
22
+ task :default => :spec
23
+
24
+ begin
25
+ require 'rdoc/task'
26
+ rescue LoadError
27
+ require 'rdoc/rdoc'
28
+ require 'rake/rdoctask'
29
+ RDoc::Task = Rake::RDocTask
30
+ end
31
+
32
+ RDoc::Task.new(:rdoc) do |rdoc|
33
+ rdoc.rdoc_dir = 'rdoc'
34
+ rdoc.title = 'Testrail'
35
+ rdoc.options << '--line-numbers'
36
+ rdoc.rdoc_files.include('README.md')
37
+ rdoc.rdoc_files.include('lib/**/*.rb')
38
+ end
data/lib/testrail.rb ADDED
@@ -0,0 +1,10 @@
1
+ require 'testrail/config'
2
+ require 'testrail/request'
3
+ require 'testrail/response'
4
+ require 'testrail/client'
5
+
6
+ module Testrail
7
+ def self.logger
8
+ Testrail.config.logger
9
+ end
10
+ end
@@ -0,0 +1,212 @@
1
+ module Testrail
2
+ class Client
3
+
4
+ attr_reader :request
5
+
6
+ def initialize
7
+ @request = Testrail::Request
8
+ end
9
+
10
+ # Test Results - see http://docs.gurock.com/testrail-api/reference-results
11
+ def add_result(test_id, opts = {})
12
+ request.post(__method__, test_id, opts)
13
+ end
14
+
15
+ def add_result_for_case(run_id, case_id, opts = {})
16
+ request.post(__method__, [run_id, case_id], opts)
17
+ end
18
+
19
+ def get_results(test_id, limit, opts = {})
20
+ request.get(__method__, test_id, limit, opts)
21
+ end
22
+
23
+ def get_results_for_case(run_id, case_id, limit, opts = {})
24
+ request.get(__method__, [run_id, case_id], limit, opts)
25
+ end
26
+
27
+ # Test - see http://docs.gurock.com/testrail-api/reference-tests
28
+ def get_test(test_id, opts = {})
29
+ request.get(__method__, test_id, opts)
30
+ end
31
+
32
+ def get_tests(run_id, opts = {})
33
+ request.get(__method__, run_id, opts)
34
+ end
35
+
36
+ # Test Cases - see http://docs.gurock.com/testrail-api/reference-cases
37
+ def get_case(case_id, opts = {})
38
+ request.get(__method__, case_id, opts)
39
+ end
40
+
41
+ def get_cases(project_id, suite_id, section_id, opts = {})
42
+ request.get(__method__, project_id, suite_id, section_id, opts)
43
+ end
44
+
45
+ def add_case(section_id, opts = {})
46
+ request.post(__method__, section_id, opts)
47
+ end
48
+
49
+ def update_case(case_id, opts = {})
50
+ request.post(__method__, case_id, opts)
51
+ end
52
+
53
+ def delete_case(case_id, opts = {})
54
+ request.post(__method__, case_id, opts)
55
+ end
56
+
57
+ # Suites - see http://docs.gurock.com/testrail-api/reference-suites
58
+ def get_suite(suite_id, opts = {})
59
+ request.get(__method__, suite_id, opts)
60
+ end
61
+
62
+ def get_suites(project_id, opts = {})
63
+ request.get(__method__, project_id, opts)
64
+ end
65
+
66
+ def add_suite(project_id, opts = {})
67
+ request.post(__method__, project_id, opts)
68
+ end
69
+
70
+ def update_suite(suite_id, opts = {})
71
+ request.post(__method__, suite_id, opts)
72
+ end
73
+
74
+ def delete_suite(suite_id, opts = {})
75
+ request.post(__method__, suite_id, opts)
76
+ end
77
+
78
+ #Sections
79
+ def get_section(section_id, opts = {})
80
+ request.get(__method__, section_id, opts)
81
+ end
82
+
83
+ def get_sections(project_id, suite_id, opts = {})
84
+ request.get(__method__, project_id, suite_id, opts)
85
+ end
86
+
87
+ def add_section(project_id, opts = {})
88
+ request.post(__method__, project_id, opts)
89
+ end
90
+
91
+ def update_section(section_id, opts = {})
92
+ request.get(__method__, section_id, opts)
93
+ end
94
+
95
+ def delete_section(section_id, opts = {})
96
+ request.get(__method__, section_id, opts)
97
+ end
98
+
99
+ # Test Runs - see http://docs.gurock.com/testrail-api/reference-runs
100
+ def get_run(run_id, opts = {})
101
+ request.get(__method__, run_id, opts)
102
+ end
103
+
104
+ def get_runs(project_id, opts = {})
105
+ request.get(__method__, project_id, opts)
106
+ end
107
+
108
+ def add_run(project_id, opts = {})
109
+ request.post(__method__, project_id, opts)
110
+ end
111
+
112
+ def update_run(run_id, opts = {})
113
+ request.post(__method__, run_id, opts)
114
+ end
115
+
116
+ def close_run(run_id, opts = {})
117
+ request.post(__method__, run_id, opts)
118
+ end
119
+
120
+ def delete_run(run_id, opts = {})
121
+ request.post(__method__, run_id, opts)
122
+ end
123
+
124
+ # Test Plans - see http://docs.gurock.com/testrail-api/reference-plans
125
+ def get_plan(plan_id, opts = {})
126
+ request.get(__method__, plan_id, opts)
127
+ end
128
+
129
+ def get_plans(project_id, opts = {})
130
+ request.get(__method__, project_id, opts)
131
+ end
132
+
133
+ def add_plan(project_id, opts = {})
134
+ request.post(__method__, project_id, opts)
135
+ end
136
+
137
+ def add_plan_entry(plan_id, opts = {})
138
+ request.post(__method__, plan_id, opts)
139
+ end
140
+
141
+ def update_plan(plan_id, opts = {})
142
+ request.post(__method__, plan_id, opts)
143
+ end
144
+
145
+ def close_plan(plan_id, opts = {})
146
+ request.post(__method__, plan_id, opts)
147
+ end
148
+
149
+ # Milestones - see http://docs.gurock.com/testrail-api/reference-milestones
150
+ def get_milestone(milestone_id, opts = {})
151
+ request.get(__method__, milestone_id, opts)
152
+ end
153
+
154
+ def get_milestones(project_id, opts = {})
155
+ request.get(__method__, project_id, opts)
156
+ end
157
+
158
+ def add_milestone(project_id, opts = {})
159
+ request.post(__method__, project_id, opts)
160
+ end
161
+
162
+ # Projects - see http://docs.gurock.com/testrail-api/reference-projects
163
+ def get_project(project_id, opts = {})
164
+ request.get(__method__, project_id, opts)
165
+ end
166
+
167
+ def get_projects(opts = {})
168
+ request.get(__method__, opts)
169
+ end
170
+
171
+ # Statuses
172
+ def get_statuses(opts = {})
173
+ request.get(__method__, opts)
174
+ end
175
+
176
+ # COMMANDS.each do |method_name|
177
+ # define_method method_name
178
+ # end
179
+
180
+ COMMANDS = %w[add_result
181
+ add_result_for_case
182
+ get_results
183
+ get_results_for_case
184
+ get_test
185
+ get_tests
186
+ get_case
187
+ get_cases
188
+ add_case
189
+ update_case
190
+ delete_case
191
+ get_suite
192
+ get_suites
193
+ get_section
194
+ get_sections
195
+ add_suite
196
+ add_section
197
+ get_run
198
+ get_runs
199
+ add_run
200
+ close_run
201
+ get_plan
202
+ get_plans
203
+ add_plan
204
+ add_plan_entries
205
+ close_plan
206
+ get_milestone
207
+ get_milestones
208
+ add_milestone
209
+ get_project
210
+ get_projects]
211
+ end
212
+ end
@@ -0,0 +1,29 @@
1
+ module Testrail
2
+ module CommandHelper
3
+ def build_url(command, ids = nil)
4
+ arg_names = Client.instance_method(command.to_sym).parameters.map(&:last).map(&:to_s)
5
+ command = Testrail.config.server + Testrail.config.api_path + Testrail.config.version + "/" + command
6
+ unless ids.nil?
7
+ args = ids.shift
8
+ if args.kind_of?(Array)
9
+ arg_names.shift(args.size)
10
+ args = args.join('/')
11
+ else
12
+ arg_names.shift
13
+ args = args.to_s
14
+ end
15
+ command += '/' + args
16
+ command += '&' + ids.each_with_index.map{ |x,i| arg_names[i] + '=' + x.to_s}.join('&') unless ids.empty?
17
+ #ids = '/' + [ids].flatten.join('/')
18
+ #command += ids
19
+ end
20
+ puts command
21
+ command + key
22
+ end
23
+
24
+ private
25
+ def key
26
+ ('&key=' + String(Testrail.config.api_key) unless Testrail.config.api_key.nil?).to_s
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,36 @@
1
+ require 'logger'
2
+ require 'active_support/configurable'
3
+
4
+ module Testrail
5
+
6
+ def self.configure(&block)
7
+ @config = Config.new
8
+ yield @config if block_given?
9
+ end
10
+
11
+ def self.config
12
+ @config ||= Config.new
13
+ end
14
+
15
+ class Config
16
+ include ActiveSupport::Configurable
17
+ config_accessor :headers, :server, :api_path, :version, :api_key, :username, :password, :logger
18
+
19
+ def initialize
20
+ default_config
21
+ end
22
+
23
+ def default_config
24
+ self.headers = {
25
+ "Accept" => "application/json"
26
+ }
27
+ self.server = "https://example.testrail.com"
28
+ self.version = "api/v2"
29
+ self.api_path = "/index.php?/"
30
+ self.api_key = nil
31
+ self.username = nil
32
+ self.password = nil
33
+ self.logger = Logger.new STDOUT
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,60 @@
1
+ require 'httparty'
2
+ require 'testrail/command_helper'
3
+
4
+ module Testrail
5
+ class Request
6
+ extend Testrail::CommandHelper
7
+ include HTTParty
8
+
9
+ base_uri Testrail.config.server
10
+ format :json
11
+
12
+ def self.get(*args)
13
+ request(:get, *args)
14
+ end
15
+
16
+ def self.post(*args)
17
+ request(:post, *args)
18
+ end
19
+
20
+ private
21
+
22
+ def self.request(method, *args)
23
+ command, ids, opts = parse_args(*args)
24
+ url = build_url(command, ids)
25
+ if not Testrail.config.username.nil? and not Testrail.config.password.nil?
26
+ opts.merge!({:basic_auth => {:username => Testrail.config.username, :password => Testrail.config.password}})
27
+ end
28
+ attempts = 0
29
+ begin
30
+ response = Testrail::Response.new(HTTParty.send(method, url, opts))
31
+ rescue TimeoutError => error
32
+ attempts += 1
33
+ retry if attempts < 3
34
+ log_error error, "Timeout connecting to #{method.to_s.upcase} #{url}"
35
+ raise error
36
+ rescue Exception => error
37
+ log_error error, "Unexpected exception intercepted calling TestRail"
38
+ raise error
39
+ end
40
+ response
41
+ end
42
+
43
+ def self.log_error(error, message)
44
+ unless Testrail.logger.nil?
45
+ Testrail.logger.error message
46
+ Testrail.logger.error error
47
+ end
48
+ end
49
+
50
+ def self.parse_args(*args)
51
+ opts = args.last.instance_of?(Hash) ? args.pop : {}
52
+ opts[:headers] = opts[:headers] ? Testrail.config.headers.merge(opts[:headers]) : Testrail.config.headers
53
+ opts[:headers].merge!({"Content-Type" => "application/json"}) if Testrail.config.version != "miniapi"
54
+ opts[:body] = opts[:body].to_json if opts[:body] != nil and Testrail.config.version != "miniapi"
55
+ command = args.shift.to_s
56
+ ids = args.empty? ? nil : args
57
+ [command, ids, opts]
58
+ end
59
+ end
60
+ end