testrail-client 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: e1874bd4d07830db69ca5be41ffd40cf8342b3b0e5ed72852cce04eded71ad9c
4
+ data.tar.gz: a70994ff627bf68a499a897f1d0f0e72b4276bfe1b8b8791e9dd67947dfc868e
5
+ SHA512:
6
+ metadata.gz: da717d9b3481a2ed35c687de158c8cc01fd3783995c0dc766517181347e4a0bcb2c1a520ca0d4996ecc5d7ec4b62e10ae6fac09c64064ef6ad8fe7edd24b58a9
7
+ data.tar.gz: 4594c8d5ce51f433c8d9b4adf9facda3744d2ff9da42e52691dc16b898f9fc3177aa64ce00da4044ad2e72b6d139c6c62cb74da5bf4d308ef51e93974ebdf205
data/.gitignore ADDED
@@ -0,0 +1,12 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+ /vendor/
10
+
11
+ # rspec failure tracking
12
+ .rspec_status
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source "https://rubygems.org"
2
+
3
+ git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
4
+
5
+ # Specify your gem's dependencies in testrail-client.gemspec
6
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,60 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ testrail-client (0.2.0)
5
+
6
+ GEM
7
+ remote: https://rubygems.org/
8
+ specs:
9
+ addressable (2.6.0)
10
+ public_suffix (>= 2.0.2, < 4.0)
11
+ crack (0.4.3)
12
+ safe_yaml (~> 1.0.0)
13
+ diff-lcs (1.3)
14
+ hashdiff (1.0.0)
15
+ mustermann (1.0.3)
16
+ public_suffix (3.1.1)
17
+ rack (2.0.7)
18
+ rack-protection (2.0.5)
19
+ rack
20
+ rake (10.5.0)
21
+ rspec (3.8.0)
22
+ rspec-core (~> 3.8.0)
23
+ rspec-expectations (~> 3.8.0)
24
+ rspec-mocks (~> 3.8.0)
25
+ rspec-core (3.8.2)
26
+ rspec-support (~> 3.8.0)
27
+ rspec-expectations (3.8.4)
28
+ diff-lcs (>= 1.2.0, < 2.0)
29
+ rspec-support (~> 3.8.0)
30
+ rspec-mocks (3.8.1)
31
+ diff-lcs (>= 1.2.0, < 2.0)
32
+ rspec-support (~> 3.8.0)
33
+ rspec-support (3.8.2)
34
+ safe_yaml (1.0.5)
35
+ sinatra (2.0.5)
36
+ mustermann (~> 1.0)
37
+ rack (~> 2.0)
38
+ rack-protection (= 2.0.5)
39
+ tilt (~> 2.0)
40
+ tilt (2.0.9)
41
+ webmock (3.6.2)
42
+ addressable (>= 2.3.6)
43
+ crack (>= 0.3.2)
44
+ hashdiff (>= 0.4.0, < 2.0.0)
45
+ yard (0.9.20)
46
+
47
+ PLATFORMS
48
+ ruby
49
+
50
+ DEPENDENCIES
51
+ bundler (~> 1.17)
52
+ rake (~> 10.0)
53
+ rspec (~> 3.0)
54
+ sinatra (~> 2.0.5)
55
+ testrail-client!
56
+ webmock (~> 3.6.2)
57
+ yard (~> 0.9.2)
58
+
59
+ BUNDLED WITH
60
+ 1.17.3
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2019 Edmundo Sanchez
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,90 @@
1
+ # Testrail::Client
2
+
3
+ Based on [testrail_client](https://github.com/zachpendleton/testrail) and [testrail-ruby](https://gitlab.com/RubyAPITools/testrail-ruby) gems.
4
+
5
+ Why? [testrail_client](https://github.com/zachpendleton/testrail) requires more setup and [testrail-ruby](https://gitlab.com/RubyAPITools/testrail-ruby) has a lot of missing endpoints which hard to maintain and time consuming to add.
6
+
7
+ This gem provides both the Testrail::Client to send get and posts requests and an idiomatic interface for testrail v2 API, which ever sits better on you.
8
+
9
+ ## Installation
10
+
11
+ Add this line to your application's Gemfile:
12
+
13
+ ```ruby
14
+ gem 'testrail-client'
15
+ ```
16
+
17
+ And then execute:
18
+
19
+ `$ bundle`
20
+
21
+ Or install it yourself as:
22
+
23
+ `$ gem install testrail-client`
24
+
25
+ ## Usage
26
+
27
+ ### Common Configuration
28
+
29
+ ``` ruby
30
+ require 'testrail/api'
31
+
32
+ client = TestRail::Client::Api.new('https://YourTestrailURL')
33
+ client.user = 'YourUserName'
34
+ client.password = 'YourPassword'
35
+ ```
36
+ ### First way, Client::Request
37
+ This is how you would normally use the gem [testrail_client](https://github.com/zachpendleton/testrail), it uses Net::HTTP to send requests to the API
38
+
39
+ ``` ruby
40
+ # GET case with ID 1
41
+ client.send_get("get_case/1")
42
+ # GET cases from Project_id 22, limit to 1 case
43
+ client.send_get("get_cases/22&limit1")
44
+ # POST update to case with ID 1, update case title
45
+ client.send_post("update_case/1",{:title => "new Name"})
46
+ # POST delete to case with ID 1, delete the case
47
+ client.send_post("delete_case/1")
48
+ ```
49
+ ### Second way, Client::Api
50
+ This is how you would normally use [testrail-ruby](https://gitlab.com/RubyAPITools/testrail-ruby), the change is on how it is coded, but the functionality stays, plus all endpoints from the testrail API are supported
51
+
52
+ ``` ruby
53
+ # GET case with ID 1
54
+ client.get_case(1)
55
+ # GET cases from Project_id 22, limit to 1 case
56
+ client.get_cases(22,{:limit => 1})
57
+ # POST update to case with ID 1, update case title
58
+ client.update_case(1,{:title => "new Name"})
59
+ # POST delete to case with ID 1, delete the case
60
+ client.delete_case(1)
61
+ ```
62
+ As you see, this is more standardized and easy. It follows the testrail documentation.
63
+
64
+ ## Attachments, the special case.
65
+ The add_attachment endpoints require the `multipart/form-data` content type and you to send a File, this is how that is done.
66
+
67
+ ```ruby
68
+ # takes result ID and a hash with the file
69
+ file = File.open('path/to/file')
70
+ client.add_attachment_to_result(1,{:attachment => file})
71
+ # takes case ID and a hash with the file
72
+ client.add_attachment_to_result_for_case(22,{:attachment => file})
73
+ ```
74
+ ## TODO
75
+
76
+ 1. Test if add_attachment routes actually work
77
+
78
+ ## Development
79
+
80
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
81
+
82
+ 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).
83
+
84
+ ## Contributing
85
+
86
+ Bug reports and pull requests are welcome on GitHub at [mundo03/testrails-client-ruby](https://github.com/mundo03/testrails-client-ruby).
87
+
88
+ ## License
89
+
90
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,15 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "testrail/client"
5
+ require "testrail/api"
6
+
7
+ # You can add fixtures and/or initialization code here to make experimenting
8
+ # with your gem easier. You can also use a different console, if you like.
9
+
10
+ # (If you use this, don't forget to add pry to your Gemfile!)
11
+ # require "pry"
12
+ # Pry.start
13
+
14
+ require "irb"
15
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,34 @@
1
+ require "testrail/client"
2
+ # @author Edmundo Sanchez
3
+ module Testrail
4
+ module Client
5
+ # Metaprogrammed class to provide an idiomatic interface to the testrails API
6
+ class Api < Request
7
+ private
8
+ # Using Meta programming, catch all endpoints adn send a request to them
9
+ # @param m [string] name of the missing method
10
+ # @param args [Array] Arguments
11
+ # @param block [Proc] Block
12
+ def method_missing(m, *args, &block)
13
+ x,y = *args
14
+ id = x if x.is_a? Integer #if Integer it is an ID
15
+ opts = x if x.is_a? Hash #if Hash it is an options array
16
+ opts ||= y #if opts not set, take second arg
17
+ case m
18
+ when /get/
19
+ send_get("#{m}/#{id}&#{_param_stringify(opts)}")
20
+ when /add_attachment/
21
+ send_post("#{m}/#{id}",opts.to_a)
22
+ else
23
+ send_post("#{m}/#{id}",opts)
24
+ end
25
+ end
26
+ # Stringify parameters for GET requests
27
+ # @param opts [Hash] parameters for the request
28
+ # @return [String] Stringified parameters
29
+ def _param_stringify(opts)
30
+ opts.to_a.map { |x| "#{x[0]}=#{x[1]}" }.join("&")
31
+ end
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,99 @@
1
+ require "testrail/client/version"
2
+ require 'net/http'
3
+ require 'net/https'
4
+ require 'uri'
5
+ require 'json'
6
+
7
+ # @author Edmundo Sanchez
8
+ module Testrail
9
+ # Client for the TestRail API, both request based and idiomatic
10
+ module Client
11
+ # Net:HTTP based interface for the Testrail API
12
+ # @attr url [String] Your Test rail URL
13
+ # @attr user [String] Your testrail user
14
+ # @attr password [String] Your testrail password
15
+ class Request
16
+ attr_accessor :url
17
+ attr_accessor :user
18
+ attr_accessor :password
19
+ # Initialize Client
20
+ # @param base_url [String] Your Testrail URL
21
+ def initialize(base_url)
22
+ if !base_url.match(/\/$/)
23
+ base_url += '/'
24
+ end
25
+ @url = base_url + 'index.php?/api/v2/'
26
+ @content_type = "application/json"
27
+ end
28
+ # send GET to uri
29
+ # @param uri [String] Test rail API path
30
+ # @return [Hash] Response from testrail API
31
+ def send_get(uri)
32
+ request = _setup_request("GET",uri)
33
+ _send_request(request)
34
+ end
35
+ # send POST to uri
36
+ # @param uri [String] test rail API path
37
+ # @param data [Enumerable] data to be sent in the POST request
38
+ # @return [Hash] Response from testrail API
39
+ def send_post(uri, data = nil)
40
+ request = _setup_request('POST', uri, data)
41
+ _send_request(request)
42
+ end
43
+
44
+ private
45
+ # Setup NET::HTTP request object
46
+ # @param method [String] can be POST, GET, PUT, PATCH, or DELETE
47
+ # @param uri [String] test rail API path
48
+ # @param data [Enumerable] data to be sent in request
49
+ # @return [Net::HTTPRequest] Request object
50
+ def _setup_request(method,uri,data = nil)
51
+ url = URI.parse(@url + uri)
52
+ STDERR.puts "#{method} #{url}"
53
+ http_request = eval("Net::HTTP::#{method.capitalize}")
54
+ request = http_request.new(url)
55
+ request.add_field('Content-Type', @content_type)
56
+ request.body = JSON.dump(data) if data.is_a? Hash
57
+ request.set_form data, 'multipart/form-data' if data.is_a? Array
58
+ request.basic_auth(@user, @password)
59
+ return request
60
+ end
61
+
62
+ # Returns response from API
63
+ # @param request [Net::HTTPRequest] Request object created on _setup_request
64
+ # @return [Hash] Response from API
65
+ def _send_request(request)
66
+ conn = Net::HTTP.new(request.uri.host, request.uri.port)
67
+ if request.uri.scheme == 'https'
68
+ conn.use_ssl = true
69
+ conn.verify_mode = OpenSSL::SSL::VERIFY_NONE
70
+ end
71
+ response = conn.request(request)
72
+
73
+ if response.body && !response.body.empty?
74
+ begin
75
+ result = JSON.parse(response.body)
76
+ rescue
77
+ raise APIError.new("Can't parse response \n" + response.body)
78
+ end
79
+ else
80
+ result = {}
81
+ end
82
+ if response.code != '200'
83
+ if result && result.key?('error')
84
+ error = '"' + result['error'] + '"'
85
+ else
86
+ error = 'No additional error message received'
87
+ end
88
+ raise APIError.new('TestRail API returned HTTP %s (%s)' %
89
+ [response.code, error])
90
+ end
91
+ result
92
+ end
93
+ end
94
+
95
+ # Custom Error class
96
+ class APIError < StandardError; end
97
+
98
+ end
99
+ end
@@ -0,0 +1,6 @@
1
+ module Testrail
2
+ module Client
3
+ # Gem version
4
+ VERSION = "0.2.0"
5
+ end
6
+ end
@@ -0,0 +1,34 @@
1
+
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "testrail/client/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "testrail-client"
8
+ spec.version = Testrail::Client::VERSION
9
+ spec.authors = ["Edmundo Sanchez"]
10
+ spec.email = ["zomundo@gmail.com"]
11
+
12
+ spec.summary = "Another Client wrapper in Ruby for TestRail API (v2)"
13
+ spec.description = "An easy to mantain gem that wrapps the v2 testrail API"
14
+ spec.homepage = "https://github.com/mundo03/testrails-client-ruby"
15
+ spec.license = "MIT"
16
+
17
+ # Specify which files should be added to the gem when it is released.
18
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
19
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
20
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
21
+ end
22
+ spec.bindir = "exe"
23
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
24
+ spec.require_paths = ["lib"]
25
+
26
+ spec.required_ruby_version = '>= 2.6.3'
27
+ spec.add_development_dependency "bundler", "~> 1.17"
28
+ spec.add_development_dependency "rake", "~> 10.0"
29
+ spec.add_development_dependency "rspec", "~> 3.0"
30
+ spec.add_development_dependency "sinatra", "~> 2.0.5"
31
+ spec.add_development_dependency 'webmock', "~> 3.6.2"
32
+ spec.add_development_dependency 'yard', "~> 0.9.2"
33
+
34
+ end
metadata ADDED
@@ -0,0 +1,140 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: testrail-client
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.2.0
5
+ platform: ruby
6
+ authors:
7
+ - Edmundo Sanchez
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2019-08-13 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.17'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.17'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: sinatra
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: 2.0.5
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: 2.0.5
69
+ - !ruby/object:Gem::Dependency
70
+ name: webmock
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: 3.6.2
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: 3.6.2
83
+ - !ruby/object:Gem::Dependency
84
+ name: yard
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: 0.9.2
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: 0.9.2
97
+ description: An easy to mantain gem that wrapps the v2 testrail API
98
+ email:
99
+ - zomundo@gmail.com
100
+ executables: []
101
+ extensions: []
102
+ extra_rdoc_files: []
103
+ files:
104
+ - ".gitignore"
105
+ - ".rspec"
106
+ - Gemfile
107
+ - Gemfile.lock
108
+ - LICENSE.txt
109
+ - README.md
110
+ - Rakefile
111
+ - bin/console
112
+ - bin/setup
113
+ - lib/testrail/api.rb
114
+ - lib/testrail/client.rb
115
+ - lib/testrail/client/version.rb
116
+ - testrail-client.gemspec
117
+ homepage: https://github.com/mundo03/testrails-client-ruby
118
+ licenses:
119
+ - MIT
120
+ metadata: {}
121
+ post_install_message:
122
+ rdoc_options: []
123
+ require_paths:
124
+ - lib
125
+ required_ruby_version: !ruby/object:Gem::Requirement
126
+ requirements:
127
+ - - ">="
128
+ - !ruby/object:Gem::Version
129
+ version: 2.6.3
130
+ required_rubygems_version: !ruby/object:Gem::Requirement
131
+ requirements:
132
+ - - ">="
133
+ - !ruby/object:Gem::Version
134
+ version: '0'
135
+ requirements: []
136
+ rubygems_version: 3.0.4
137
+ signing_key:
138
+ specification_version: 4
139
+ summary: Another Client wrapper in Ruby for TestRail API (v2)
140
+ test_files: []