okapi 0.1.0 → 0.1.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.
data/README.md CHANGED
@@ -1,19 +1,3 @@
1
1
  # OKApi
2
2
 
3
- https://github.com/apiaryio/OKApi
4
-
5
- ## Installation
6
-
7
- $ gem install okapi
8
-
9
- ## Usage
10
-
11
- $ okapi help
12
-
13
- ## Contributing
14
-
15
- 1. Fork it
16
- 2. Create your feature branch (`git checkout -b my-new-feature`)
17
- 3. Commit your changes (`git commit -am 'Add some feature'`)
18
- 4. Push to the branch (`git push origin my-new-feature`)
19
- 5. Create new Pull Request
3
+ OKApi has been merged into Apiary.io CLI [https://github.com/apiaryio/apiary-client]
data/okapi.gemspec CHANGED
@@ -1,23 +1,17 @@
1
1
  # coding: utf-8
2
- lib = File.expand_path('../lib', __FILE__)
3
- $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
2
 
5
- require File.expand_path('../lib/okapi/version', __FILE__)
6
3
 
7
4
  Gem::Specification.new do |spec|
8
5
  spec.name = "okapi"
9
- spec.version = Apiary::Okapi::VERSION
6
+ spec.version = "0.1.1"
10
7
  spec.authors = ["Tu1ly"]
11
8
  spec.email = ["tully@apiary.io"]
12
- spec.description = %q{Apiary.io API tester - OKApi allows you to test if your documentation in Apiary Blueprint match your API}
13
- spec.summary = %q{Apiary.io API tester - OKApi allows you to test if your documentation in Apiary Blueprint match your API}
9
+ spec.description = %q{OKApi has been merged into Apiary.io CLI [https://rubygems.org/gems/apiaryio]}
10
+ spec.summary = %q{OKApi has been merged into Apiary.io CLI [https://rubygems.org/gems/apiaryio]}
14
11
  spec.homepage = "http://apiary.io"
15
12
  spec.license = "MIT"
16
13
 
17
14
  spec.files = `git ls-files`.split($/)
18
- spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
19
- spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
20
- spec.require_paths = ["lib"]
21
15
 
22
16
  spec.add_dependency "json"
23
17
  spec.add_dependency "rest-client"
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: okapi
3
3
  version: !ruby/object:Gem::Version
4
- hash: 27
4
+ hash: 25
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 1
9
- - 0
10
- version: 0.1.0
9
+ - 1
10
+ version: 0.1.1
11
11
  platform: ruby
12
12
  authors:
13
13
  - Tu1ly
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2013-05-07 00:00:00 +02:00
18
+ date: 2013-05-09 00:00:00 +02:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -46,11 +46,11 @@ dependencies:
46
46
  version: "0"
47
47
  type: :runtime
48
48
  version_requirements: *id002
49
- description: Apiary.io API tester - OKApi allows you to test if your documentation in Apiary Blueprint match your API
49
+ description: OKApi has been merged into Apiary.io CLI [https://rubygems.org/gems/apiaryio]
50
50
  email:
51
51
  - tully@apiary.io
52
- executables:
53
- - okapi
52
+ executables: []
53
+
54
54
  extensions: []
55
55
 
56
56
  extra_rdoc_files: []
@@ -58,29 +58,7 @@ extra_rdoc_files: []
58
58
  files:
59
59
  - .gitignore
60
60
  - Gemfile
61
- - LICENSE.txt
62
61
  - README.md
63
- - Rakefile
64
- - bin/okapi
65
- - examples/apiary.apib
66
- - examples/apiary.yaml
67
- - examples/tests.spec
68
- - examples/tests2.spec
69
- - examples/tests_1.spec
70
- - lib/okapi.rb
71
- - lib/okapi/apiary_connector.rb
72
- - lib/okapi/cli.rb
73
- - lib/okapi/config.rb
74
- - lib/okapi/exceptions.rb
75
- - lib/okapi/help.rb
76
- - lib/okapi/okapi
77
- - lib/okapi/output.rb
78
- - lib/okapi/outputs/base.rb
79
- - lib/okapi/outputs/tap.rb
80
- - lib/okapi/resources.rb
81
- - lib/okapi/spec_parser.rb
82
- - lib/okapi/test.rb
83
- - lib/okapi/version.rb
84
62
  - okapi.gemspec
85
63
  has_rdoc: true
86
64
  homepage: http://apiary.io
@@ -115,6 +93,6 @@ rubyforge_project:
115
93
  rubygems_version: 1.3.7
116
94
  signing_key:
117
95
  specification_version: 3
118
- summary: Apiary.io API tester - OKApi allows you to test if your documentation in Apiary Blueprint match your API
96
+ summary: OKApi has been merged into Apiary.io CLI [https://rubygems.org/gems/apiaryio]
119
97
  test_files: []
120
98
 
data/LICENSE.txt DELETED
@@ -1,22 +0,0 @@
1
- Copyright (c) 2013 Tu1ly
2
-
3
- MIT License
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining
6
- a copy of this software and associated documentation files (the
7
- "Software"), to deal in the Software without restriction, including
8
- without limitation the rights to use, copy, modify, merge, publish,
9
- distribute, sublicense, and/or sell copies of the Software, and to
10
- permit persons to whom the Software is furnished to do so, subject to
11
- the following conditions:
12
-
13
- The above copyright notice and this permission notice shall be
14
- included in all copies or substantial portions of the Software.
15
-
16
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
- EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
- MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
- NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
- LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
- OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
- WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/Rakefile DELETED
File without changes
data/bin/okapi DELETED
@@ -1,6 +0,0 @@
1
- #!/usr/bin/env ruby
2
- $:.unshift(File.expand_path(File.join(File.dirname(__FILE__), '..','lib')))
3
- require 'okapi'
4
-
5
- trap(:INT) { abort "" }
6
- Apiary::Okapi::CLI.new(ARGV)
data/examples/apiary.apib DELETED
@@ -1,59 +0,0 @@
1
- HOST: http://www.google.com/
2
-
3
- --- aaaaaaa ---
4
-
5
- ---
6
- Welcome to the our sample API documentation. All comments can be written in (support [Markdown](http://daringfireball.net/projects/markdown/syntax) syntax)
7
- ---
8
-
9
- --
10
- Shopping Cart Resources
11
- The following is a section of resources related to the shopping cart
12
- --
13
-
14
- List products added into your shopping-cart. (comment block again in Markdown)
15
- GET /shopping-cart/{id}
16
- < 200
17
- < Content-Type: application/json
18
- { "items": [
19
- { "url": "/shopping-cart/1", "product":"2ZY48XPZ", "quantity": 1, "name": "New socks", "price": 1.25 }
20
- ] }
21
-
22
- Save new products in your shopping cart
23
- POST /shopping-cart/{id2}
24
- > Content-Type: application/json
25
- > CCC: aaa
26
- { "product":"1AB23ORM", "quantity": 2 }
27
- < 201
28
- < Content-Type: application/json
29
- < CCC: aaa
30
- { "status": "created", "url": "/shopping-cart/2" }
31
-
32
- -- Payment Resources --
33
-
34
- This resource allows you to submit payment information to process your *shopping cart* items
35
- POST /payment
36
- { "cc": "12345678900", "cvc": "123", "expiry": "0112" }
37
- < 200
38
- { "receipt": "/payment/receipt/1" }
39
-
40
- -- JSON Schema Validations --
41
-
42
- POST /shopping-cart/{id2}
43
- {"request":
44
- { "type": "object",
45
- "properties": {
46
- "product": { "type": "string","format": "alphanumeric" },
47
- "quantity": { "type": "integer" }
48
- }
49
- }
50
- ,
51
- "response":
52
- { "type": "object",
53
- "properties": {
54
- "product": { "type": "string","format": "alphanumeric" },
55
- "status": { "type": "integer" }
56
- }
57
- }
58
- }
59
-
data/examples/apiary.yaml DELETED
@@ -1,5 +0,0 @@
1
- tests:
2
- host: http://aptest.apiary.io
3
- specs:
4
- - tests.spec
5
- - tests2.spec
data/examples/tests.spec DELETED
@@ -1,6 +0,0 @@
1
- VARS {"id2": "eee", "id": "5"}
2
- POST /shopping-cart/{id2} {"id2": "eee2"}
3
- POST
4
- CONTINUE
5
-
6
-
data/examples/tests2.spec DELETED
@@ -1,3 +0,0 @@
1
- POST /shopping-cart/{id2} {"id2": "eee2"}
2
- POST /payment
3
-
@@ -1,18 +0,0 @@
1
- [{
2
- "resource": "/shopping-cart/{id}",
3
- "method": "GET",
4
- "params": {"id": "eee"}
5
- }
6
- ,
7
- {
8
- "resource": "/shopping-cart/{id2}",
9
- "method": "POST",
10
- "params": {"id2": "eee2"}
11
- }
12
- ,
13
- {
14
- "resource": "/payment",
15
- "method": "POST",
16
- "params": {}
17
- }
18
- ]
@@ -1,101 +0,0 @@
1
- # encoding: utf-8
2
- require 'rest_client'
3
- require 'json'
4
-
5
- module Apiary
6
- module Okapi
7
- class ApiaryConnector
8
-
9
- attr_reader :apiary_url, :blueprint
10
-
11
- def initialize(apiary_url, req_path, res_path)
12
- @apiary_url = apiary_url
13
- @req_path = req_path
14
- @res_path = res_path
15
- end
16
-
17
- def get_response(raw_resp, json_data, error, code)
18
- { :resp => raw_resp,
19
- :data => json_data ? json_data['requests'] : nil,
20
- :status => json_data ? json_data['status'] : nil ,
21
- :error => json_data ? json_data['error'] || error : error,
22
- :code => code
23
- }
24
- end
25
-
26
- def get_requests(resources, blueprint, all_resources = false, global_vars = {})
27
-
28
- resources_list = []
29
-
30
- resources.each() do |res|
31
- resources_list << {
32
- :resource => res['resource'],
33
- :method => res['method'],
34
- :params => res['params']
35
- }
36
- end
37
-
38
- data = {
39
- :resources => resources_list,
40
- :blueprint => blueprint,
41
- :all_resources => all_resources,
42
- :global_vars => global_vars
43
- }.to_json()
44
-
45
- begin
46
- response = RestClient.post @apiary_url + @req_path, data, :content_type => :json, :accept => :json
47
- get_response(response, JSON.parse(response.to_str), nil, response.code.to_i)
48
- rescue RestClient::BadRequest, RestClient::InternalServerError => e
49
- begin
50
- data = JSON.parse(e.http_body)
51
- get_response(nil, JSON.parse(e.http_body), data['error'], e.http_code.to_i)
52
- rescue
53
- get_response(nil, nil, e.to_s, e.http_code.to_i)
54
- end
55
- rescue Exception => e
56
- get_response(nil, nil, e.to_s, nil)
57
- end
58
-
59
- end
60
-
61
- def get_results(resources, blueprint)
62
-
63
- resources_list = []
64
- resources.each() do |res|
65
- resources_list << {
66
- :request => {
67
- :uri => res.uri,
68
- :expandedUri => res.expanded_uri,
69
- :method => res.method,
70
- :headers => res.headers,
71
- :body => res.body,
72
- },
73
- :response => {
74
- :status => res.response.status,
75
- :headers => res.response.headers ,
76
- :body => res.response.body
77
- }
78
- }
79
- end
80
-
81
- data = {
82
- :resources => resources_list,
83
- :blueprint => blueprint
84
- }.to_json()
85
-
86
- begin
87
- response = RestClient.post @apiary_url + @res_path, data, :content_type => :json, :accept => :json
88
- get_response(response, JSON.parse(response.to_str), nil, response.code.to_i)
89
- rescue RestClient::BadRequest, RestClient::InternalServerError => e
90
- begin
91
- get_response(nil, JSON.parse(e.http_body), data['error'], e.http_code.to_i)
92
- rescue
93
- get_response(nil, nil, e.to_s, e.http_code.to_i)
94
- end
95
- rescue Exception => e
96
- get_response(nil, nil, e.to_s, nil)
97
- end
98
- end
99
- end
100
- end
101
- end
data/lib/okapi/cli.rb DELETED
@@ -1,125 +0,0 @@
1
- # encoding: utf-8
2
- require 'optparse'
3
- require 'yaml'
4
-
5
- module Apiary
6
- module Okapi
7
- class CLI
8
-
9
- def initialize(args)
10
- case args.first
11
- when 'help'
12
- Apiary::Okapi::Help.show
13
- exit 0
14
- when 'version'
15
- puts VERSION
16
- exit 0
17
- when 'okapi'
18
- Apiary::Okapi::Help.okapi
19
- exit 0
20
- else
21
- parse_options!(args)
22
- parse_config
23
- @options[:blueprint] ||= BLUEPRINT_PATH
24
- @options[:test_spec] ||= TEST_SPEC_PATHS
25
- @options[:output] ||= OUTPUT
26
- @options[:test_url] ||= TEST_URL
27
- @options[:apiary_url] ||= APIARY_URL
28
-
29
- @options[:test_spec] ||= TEST_SPEC_PATHS.gsub(' ','').split(',')
30
-
31
- if @options[:params]
32
- puts "running with :"
33
- p @options
34
- puts "\n"
35
- end
36
-
37
- exit run
38
- end
39
- end
40
-
41
- def run
42
- pass = true
43
- @options[:test_spec].each { |spec|
44
- pass = Apiary::Okapi::Test.new(@options[:blueprint], spec, @options[:test_url], @options[:output], @options[:apiary_url]).run()
45
- }
46
- if pass
47
- 0
48
- else
49
- 1
50
- end
51
- end
52
-
53
- def parse_config
54
- begin
55
- if tests = YAML.load_file(@options[:config_path])['tests']
56
- @options[:test_url] ||= tests['host'] if tests['host']
57
- @options[:test_spec] ||= tests['specs'] if tests['specs']
58
- end
59
- rescue Errno::ENOENT => e
60
- puts "Config file (#{@options[:config_path]}) not accessible ... skiping"
61
- puts "\n"
62
- rescue Exception => e
63
- puts "Config file (#{@options[:config_path]}) loading problem :#{e}"
64
- puts "\n"
65
- exit 1
66
- end
67
- end
68
-
69
- def parse_options!(args)
70
- @options = {}
71
- options_parser = OptionParser.new do |opts|
72
- opts.on("-c", "--config CONFIG",
73
- "path config file (default: " + CONFIG_PATH + " )") do |config|
74
- @options[:config_path] = config
75
- end
76
-
77
- opts.on("-b", "--blueprint BLUEPRINT",
78
- "path to the blueprint (default: " + BLUEPRINT_PATH + " )") do |blueprint|
79
- @options[:blueprint] = blueprint
80
- end
81
-
82
- opts.on("-t","--test_spec TEST_SPEC",
83
- "comma separated paths to the test specifications (default: " + TEST_SPEC_PATHS + " )") do |test_spec|
84
- @options[:test_spec] = test_spec
85
- end
86
-
87
- opts.on("-o","--output OUTPUT",
88
- "output format (default" + OUTPUT + ")") do |output|
89
- @options[:output] = output
90
- end
91
-
92
- opts.on("-u","--test_url TEST_URL",
93
- "url to test (default" + TEST_URL + ")") do |test_url|
94
- @options[:test_url] = test_url
95
- end
96
-
97
- opts.on("-a","--apiary APIARY",
98
- "apiary url (default" + APIARY_URL + ")") do |apiary|
99
- @options[:apiary_url] = apiary
100
- end
101
-
102
- opts.on("-p","--params [PARAMS]",
103
- "show parameters" ) do |params|
104
- @options[:params] = true
105
- end
106
- end
107
-
108
- options_parser.parse!
109
-
110
- @options[:config_path] ||= CONFIG_PATH
111
- @options[:test_spec] = @options[:test_spec].gsub(' ','').split(',') if @options[:test_spec]
112
-
113
- @options
114
-
115
- rescue OptionParser::InvalidOption => e
116
- puts "\n"
117
- puts e
118
- Apiary::Okapi::Help.banner
119
- puts "\n"
120
- exit 1
121
- end
122
-
123
- end
124
- end
125
- end
data/lib/okapi/config.rb DELETED
@@ -1,13 +0,0 @@
1
- # encoding: utf-8
2
- module Apiary
3
- module Okapi
4
- CONFIG_PATH = "apiary.yaml"
5
- APIARY_URL = "https://api.apiary.io"
6
- GET_REQUESTS_PATH = "/tests/get-requests"
7
- GET_RESULTS_PATH = "/tests/get-test-results"
8
- BLUEPRINT_PATH = "apiary.apib"
9
- TEST_SPEC_PATHS = "tests.spec"
10
- TEST_URL = "http://127.0.0.1"
11
- OUTPUT = 'tap'
12
- end
13
- end
File without changes
data/lib/okapi/help.rb DELETED
@@ -1,37 +0,0 @@
1
- # encoding: utf-8
2
- module Apiary
3
- module Okapi
4
- class Help
5
- def self.show
6
- banner
7
- options
8
- end
9
-
10
- def self.banner
11
- puts "\nUsage: okapi [options]"
12
- puts "Try 'okapi help' for more information."
13
- end
14
-
15
- def self.options
16
- puts "\nCurrently available okapi options are:\n\n"
17
-
18
- puts "\t-b, --blueprint path to the blueprint (default: " + BLUEPRINT_PATH + " )"
19
- puts "\t-t, --test_spec path to the test specification (default: " + TEST_SPEC_PATHS + " )"
20
- #puts "\t-o, --output output format (default: " + OUTPUT + ")"
21
- puts "\t-u, --test_url url to test (default: " + TEST_URL + ")"
22
- puts "\t-a, --apiary apiary url (default: " + APIARY_URL + ")"
23
- puts "\t-s, --config config file (default: " + CONFIG_PATH + ")"
24
- puts "\t-p, --params prints used parameters"
25
- puts "\n"
26
- puts "\thelp Show this help"
27
- puts "\n"
28
- puts "\tversion Show version"
29
- puts "\n"
30
- end
31
-
32
- def self.okapi
33
- puts File.read(File.dirname(__FILE__) + '/okapi')
34
- end
35
- end
36
- end
37
- end
data/lib/okapi/okapi DELETED
@@ -1,43 +0,0 @@
1
-
2
- ,#.@:
3
- @;#@@#
4
- #+#@#@;
5
- :+#;#'+@#@#`
6
- @@##@+@;; ``` ,` ;,;@@@+',`
7
- ;@###@@. ,+#@@@@@@@@#@@@@@@@@@@#``
8
- #@@: `,@@#@#@#@@##@@@@@@@'#`+:+:`
9
- .#@` #+ ` ::` :`,.+;#`,``'`@.##:#`+`##;` `
10
- '@# ` , #+@#@+':@###@+;+.#@,@#`+`+#@@@#:.
11
- +@@` + `;#;++`'@@###@@+ @@,@@`#;@@#@#@@@#;+'
12
- :@@@@. `; ';#+@,##@####@;,@+,@#`:#':#+'@##@@#'@+`
13
- `@@@@###; ` ' @;+#@@#@#.@@'@@@``.'` +#:@'@@#@#@#;
14
- `,`#+`,#` `:;#;@#@;.#+;@@#:'`++ ` #.@@@:@,@@@#
15
- `:;##@##@:##@.'+:@#,#`.@#@:@@;@##+`
16
- #,#@+@@@##@##@#+:`#@@#@`+#;##++
17
- @@@@@@@@@@;'@+@#`#.'@@@@``,.,:#,
18
- ####@@@##'`#@'@@`#'#,@@@# `@#
19
- ;#@@+@@#'+@'@+@#`#@+@@@@@## #,#
20
- #@@##@#+##:@#@@,'@.@@@` :: ;#;
21
- '#,#`#@#.'.#@@#+,####` ` `'#
22
- + +:;+@@#@#.##@@#.@. `+`,
23
- ' `#+###@@@@@#@@@+`.:` .'#
24
- @` ##@#####@:@@##`` #,@
25
- @#'` #@@##@#,'### ` @'#
26
- ###' @ :##`#;;#, @.,
27
- ,+,+ .. ` +#+': . ``++,
28
- :':'@; +; `,,, `;
29
- #; `: @;#'`; :+``
30
-
31
- +` ` '+;' : .#`
32
- @@,@+ .+. ; +##;
33
- ;#,#@ ',+. `@##
34
- :#:#
35
- `+ .
36
- ##.#` + #
37
- #+,@. @ +
38
- #+ .` # `
39
- :; '`` `
40
- +## ###
41
- `@@: .##`
42
- '## ##:
43
- `# `
data/lib/okapi/output.rb DELETED
@@ -1,13 +0,0 @@
1
- Dir["#{File.dirname(__FILE__)}/outputs/*.rb"].each { |f| require(f) }
2
-
3
- module Apiary
4
- module Okapi
5
- class Output
6
- def self.get(output,resources, error)
7
- output = Apiary::Okapi::Outputs.const_get(output.to_s.capitalize).send(:new, resources, error)
8
- output.get()
9
- output.status
10
- end
11
- end
12
- end
13
- end
@@ -1,92 +0,0 @@
1
- module Apiary
2
- module Okapi
3
- module Outputs
4
- class BaseOutput
5
-
6
- attr_reader :status
7
-
8
- def initialize(resources, error)
9
- @resources = resources
10
- @error = error
11
- @results = {
12
- :count => 0,
13
- :give_up => false,
14
- }
15
- @status = true
16
- get_results
17
- end
18
-
19
- def get
20
- p @results[:count].to_s + ' tests'
21
- p @results[:give_up][:error].to_s if @results[:give_up]
22
- @results[:tests].each { |test|
23
- p '-------------------------------------------------'
24
- p test[:test_no]
25
- p test[:description]
26
- if test[:pass]
27
- p 'OK'
28
- else
29
- p "FAILED"
30
- p test[:exp]
31
- end
32
- }
33
- end
34
-
35
- def get_results
36
- @results[:count] = @resources.count
37
- @results[:tests] = []
38
- if @error
39
- @results[:give_up] = {:error => @error}
40
- @status = false
41
- else
42
- counter = 0
43
- @resources.each { |res|
44
- counter += 1
45
- test_res = {
46
- :test_no=> counter,
47
- :pass => (res.validation_result.status and res.response.validation_result.status),
48
- :description => (res.method + ' ' + res.uri) + ((res.expanded_uri and res.uri != res.expanded_uri['url']) ? " (#{res.expanded_uri['url']}) " : '')
49
- }
50
- if not test_res[:pass]
51
- test_res[:exp] = {:request => {:pass => false}, :response => {:pass => false}}
52
- if res.validation_result.status
53
- test_res[:exp][:request][:pass] = true
54
- else
55
- test_res[:exp][:request][:reasons] = get_fail_result(res.validation_result)
56
- @status = false
57
- end
58
-
59
- if res.response.validation_result.status
60
- test_res[:exp][:response][:pass] = true
61
- else
62
- test_res[:exp][:response][:reasons] = get_fail_result(res.response.validation_result)
63
- @status = false
64
- end
65
- end
66
- @results[:tests] << test_res
67
- }
68
- end
69
- end
70
-
71
- def get_fail_result(result)
72
- res = []
73
-
74
- if result.schema
75
- result.schema_res["errors"]["length"].times {|i|
76
- res << result.schema_res["errors"][i.to_s]["message"]
77
- }
78
- else
79
- if not result.body_pass
80
- res << 'Body does not match'
81
- end
82
- end
83
- if not result.header_pass
84
- res << 'Headers does not match'
85
- end
86
- res
87
- end
88
-
89
- end
90
- end
91
- end
92
- end
@@ -1,44 +0,0 @@
1
- require "#{File.dirname(__FILE__)}/base.rb"
2
- require 'yaml'
3
-
4
- module Apiary
5
- module Okapi
6
- module Outputs
7
- class Tap < Apiary::Okapi::Outputs::BaseOutput
8
-
9
- def get
10
- get_int
11
- puts "\n\n"
12
- end
13
-
14
- def get_int
15
- puts "TAP version 13"
16
- puts "1..#{@results[:count].to_s}"
17
- if @results[:give_up]
18
- puts "Bail out! #{@results[:give_up][:error].to_s.tr("\n"," ")}"
19
- return
20
- end
21
- @results[:tests].each { |test|
22
- if test[:pass]
23
- o = 'ok '
24
- else
25
- o = 'not ok '
26
- end
27
- puts o + test[:test_no].to_s + ' ' + test[:description]
28
- if not test[:pass]
29
- error_block(test)
30
- end
31
- }
32
- end
33
-
34
- def error_block(test)
35
- test[:exp].to_yaml.split(/\n/).each { |line|
36
- puts " #{line}"
37
- }
38
- puts " ..."
39
-
40
- end
41
- end
42
- end
43
- end
44
- end
@@ -1,54 +0,0 @@
1
- # encoding: utf-8
2
- module Apiary
3
- module Okapi
4
- class Resource
5
- attr_accessor :uri, :method, :params, :expanded_uri, :headers, :body, :response, :validation_result
6
-
7
- def initialize(uri, method, params, expanded_uri = nil, headers = nil, body = nil, response = nil, validation_result = nil)
8
- #p uri, method, params
9
- @uri = uri
10
- @method = method
11
- @params = params
12
- @expanded_uri = expanded_uri
13
- @headers = headers
14
- @body = body
15
- @response = response
16
- @validation_result = validation_result
17
- end
18
- end
19
-
20
- class Response
21
- attr_accessor :status, :headers, :body, :error, :validation_result
22
-
23
- def initialize(status = nil, headers = nil, body = nil, error = nil, validation_result = nil)
24
- @headers = headers
25
- @body = body
26
- @status = status
27
- @error = error
28
- @validation_result = validation_result
29
- end
30
- end
31
-
32
- class ValidationResult
33
- attr_accessor :status, :error, :schema_res , :body_pass, :body_diff, :header_pass, :header_diff
34
-
35
- def status
36
- @status ||= get_status
37
- end
38
-
39
- def get_status
40
- return true if not @error and @header_pass and ((schema and schema_pass) or (not schema and @body_pass))
41
- return false
42
- end
43
-
44
- def schema
45
- !(@schema_res == false)
46
- end
47
-
48
- def schema_pass
49
- not schema or schema and @schema_res and not @schema_res['errors']
50
- end
51
-
52
- end
53
- end
54
- end
@@ -1,83 +0,0 @@
1
- # encoding: utf-8
2
- require 'json'
3
-
4
- module Apiary
5
- module Okapi
6
- class Parser
7
-
8
- attr_reader :data, :resources, :proces_all_bp_resources, :global_vars
9
-
10
- def initialize(spec_path)
11
- if not File.exist? spec_path
12
- raise Exception, "Test spec. file '#{spec_path}' not found"
13
- end
14
- @data = read_file(spec_path)
15
- @proces_all_bp_resources = false
16
- end
17
-
18
- def resources
19
- @resources ||= parse_data
20
- end
21
-
22
- def read_file(path)
23
- @data = []
24
- File.open(path).each do |line|
25
- @data << line if line.strip != ""
26
- end
27
- @data
28
- end
29
-
30
- def substituite_vars(local, global)
31
- tmp = {}
32
- global.each {|k,v|
33
- tmp[k] = v
34
- }
35
- local.each {|k,v|
36
- tmp[k] = v
37
- }
38
- tmp
39
- end
40
-
41
- def parse_data
42
- global_vars = {}
43
- resources = []
44
- @data.each { |res|
45
- if res.index('CONTINUE') == 0
46
- @proces_all_bp_resources = true
47
- next
48
- end
49
-
50
- if res.index('VARS') == 0
51
- splited = res.split(' ',2)
52
- begin
53
- global_vars = JSON.parse splited[1] if splited[1] and splited[1] != ''
54
- rescue Exception => e
55
- raise Exception, "can not parse global parameters (#{e})"
56
- end
57
- next
58
- end
59
-
60
- splited = res.split(' ',3)
61
-
62
- begin
63
- splited[2] = JSON.parse splited[2] if splited[2] and splited[2] != ''
64
- rescue Exception => e
65
- raise Exception, 'can not parse parameters for resource:' + res + "(#{e})"
66
- end
67
-
68
- if splited[1] and splited[1] != '' and splited[0] and splited[0] != ''
69
- out = {
70
- 'resource' => splited[1],
71
- 'method' => splited[0],
72
- 'params' => substituite_vars(splited[2] || {}, global_vars)
73
- }
74
- resources << out
75
- end
76
- }
77
- @global_vars = global_vars
78
- resources
79
- end
80
-
81
- end
82
- end
83
- end
data/lib/okapi/test.rb DELETED
@@ -1,141 +0,0 @@
1
- # encoding: utf-8
2
- require 'rest_client'
3
-
4
- module Apiary
5
- module Okapi
6
- class Test
7
- def initialize(blueprint_path, test_spec_path, test_url, output, apiary_url)
8
- @blueprint_path = blueprint_path
9
- @test_spec_path = test_spec_path
10
- @test_url = test_url
11
- @output_format = output
12
- @apiary_url = apiary_url
13
- @req_path = GET_REQUESTS_PATH
14
- @res_path = GET_RESULTS_PATH
15
- @connector = Apiary::Okapi::ApiaryConnector.new(@apiary_url, @req_path, @res_path)
16
- @proces_all_bp_resources = false
17
- @output = []
18
- @resources = []
19
- @error = nil
20
- end
21
-
22
- def run
23
- begin
24
- test()
25
- rescue Exception => e
26
- @resources = []
27
- @error = e
28
- end
29
- Apiary::Okapi::Output.get(@output_format, @resources, @error)
30
- end
31
-
32
- def test
33
- prepare()
34
- if not @resources.empty?
35
- get_responses
36
- evaluate
37
- else
38
- raise Exception, 'No resources provided'
39
- end
40
- end
41
-
42
- def prepare
43
- @resources = []
44
- parser = get_test_spec_parser(@test_spec_path)
45
- resources = parser.resources
46
- counter = 0
47
-
48
- resources.each { |res|
49
- counter += 1
50
- raise Exception, "Rresource not defined for item #{counter.to_d} in #{@test_spec_path}" unless res["resource"]
51
- raise Exception, "Method not defined for resource #{res["resource"].to_s} in #{@test_spec_path}" unless res["method"]
52
- }
53
-
54
- @proces_all_bp_resources = parser.proces_all_bp_resources
55
- data = get_requests_spec(resources, parser.global_vars)
56
-
57
- if data[:error] or data[:code] != 200
58
- raise Exception, 'Can not get request data from Apiary: ' + data[:error] ? data[:error] : ''
59
- end
60
-
61
- data[:data].each do |res|
62
- raise Exception, 'Resource error "' + res['error'] + '" for resource "' + res["method"] + ' ' + res["uri"] + '"' if res['error']
63
- @resources << Apiary::Okapi::Resource.new(res["uri"], res["method"], res["params"], res["expandedUri"], res["headers"], res["body"])
64
- end
65
-
66
- @resources
67
- end
68
-
69
- def blueprint
70
- @blueprint ||= parse_blueprint(@blueprint_path)
71
- end
72
-
73
- def get_responses
74
- @resources.each { |resource|
75
- params = {:method => resource.method, :url => @test_url + resource.expanded_uri['url'], :headers => resource.headers || {}}
76
- begin
77
- response = RestClient::Request.execute(params)
78
-
79
- raw_headers = response.raw_headers.inject({}) do |out, (key, value)|
80
- out[key] = %w{ set-cookie }.include?(key.downcase) ? value : value.first
81
- out
82
- end
83
-
84
- resource.response = Apiary::Okapi::Response.new(response.code, raw_headers, response.body)
85
- rescue Exception => e
86
- raise Exception, 'Can not get response for: ' + params.to_json + ' (' + e.to_s + ')'
87
- end
88
- }
89
-
90
- end
91
-
92
- def evaluate
93
-
94
- data = @connector.get_results(@resources, blueprint)
95
- if data[:error] or data[:code] != 200
96
- raise Exception, 'Can not get evaluation data from apiary: ' + data[:error] ? data[:error] : ''
97
- end
98
-
99
- data[:data].each { |validation|
100
- @resources.each { |resource|
101
- if validation['resource']['uri'] == resource.uri and validation['resource']['method'] == resource.method
102
- resource.validation_result = Apiary::Okapi::ValidationResult.new()
103
- resource.validation_result.error = validation['errors']
104
- resource.validation_result.schema_res = validation["validations"]['reqSchemaValidations']
105
- resource.validation_result.body_pass = !validation["validations"]['reqData']['body']['isDifferent']
106
- resource.validation_result.body_diff = validation["validations"]['reqData']['body']['diff']
107
- resource.validation_result.header_pass = !validation["validations"]['reqData']['headers']['isDifferent']
108
- resource.validation_result.header_diff = validation["validations"]['reqData']['headers']['diff']
109
-
110
- resource.response.validation_result = Apiary::Okapi::ValidationResult.new()
111
- resource.response.validation_result.error = validation['errors']
112
- resource.response.validation_result.schema_res = validation["validations"]['resSchemaValidations']
113
- resource.response.validation_result.body_pass = !validation["validations"]['resData']['body']['isDifferent']
114
- resource.response.validation_result.body_diff = validation["validations"]['resData']['body']['diff']
115
- resource.response.validation_result.header_pass = !validation["validations"]['resData']['headers']['isDifferent']
116
- resource.response.validation_result.header_diff = validation["validations"]['resData']['headers']['diff']
117
- end
118
-
119
- }
120
- }
121
- end
122
-
123
- def get_test_spec_parser(test_spec)
124
- Apiary::Okapi::Parser.new(test_spec)
125
- end
126
-
127
- def parse_blueprint(blueprint_path)
128
- if not File.exist? blueprint_path
129
- raise Exception, "Blueprint file '#{blueprint_path}' not found"
130
- end
131
- File.read(blueprint_path)
132
- end
133
-
134
- def get_requests_spec(resources, global_vars)
135
- @connector.get_requests(resources, blueprint, @proces_all_bp_resources, global_vars)
136
- end
137
-
138
- end
139
- end
140
- end
141
-
data/lib/okapi/version.rb DELETED
@@ -1,6 +0,0 @@
1
- # encoding: utf-8
2
- module Apiary
3
- module Okapi
4
- VERSION = "0.1.0"
5
- end
6
- end
data/lib/okapi.rb DELETED
@@ -1,18 +0,0 @@
1
- # encoding: utf-8
2
- require 'rubygems'
3
- require "okapi/version"
4
- require "okapi/config"
5
- require "okapi/output"
6
- require "okapi/apiary_connector"
7
- require "okapi/resources"
8
- require "okapi/spec_parser"
9
- require "okapi/test"
10
- require "okapi/cli"
11
- require "okapi/help"
12
-
13
-
14
-
15
-
16
- module Okapi
17
-
18
- end