apirunner 0.2.1 → 0.2.2
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/VERSION +1 -1
 - data/apirunner.gemspec +2 -2
 - data/lib/api_runner.rb +4 -4
 - data/lib/http_client.rb +26 -12
 - metadata +4 -4
 
    
        data/VERSION
    CHANGED
    
    | 
         @@ -1 +1 @@ 
     | 
|
| 
       1 
     | 
    
         
            -
            0.2. 
     | 
| 
      
 1 
     | 
    
         
            +
            0.2.2
         
     | 
    
        data/apirunner.gemspec
    CHANGED
    
    | 
         @@ -5,11 +5,11 @@ 
     | 
|
| 
       5 
5 
     | 
    
         | 
| 
       6 
6 
     | 
    
         
             
            Gem::Specification.new do |s|
         
     | 
| 
       7 
7 
     | 
    
         
             
              s.name = %q{apirunner}
         
     | 
| 
       8 
     | 
    
         
            -
              s.version = "0.2. 
     | 
| 
      
 8 
     | 
    
         
            +
              s.version = "0.2.2"
         
     | 
| 
       9 
9 
     | 
    
         | 
| 
       10 
10 
     | 
    
         
             
              s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
         
     | 
| 
       11 
11 
     | 
    
         
             
              s.authors = ["jan@moviepilot.com"]
         
     | 
| 
       12 
     | 
    
         
            -
              s.date = %q{2010-09- 
     | 
| 
      
 12 
     | 
    
         
            +
              s.date = %q{2010-09-29}
         
     | 
| 
       13 
13 
     | 
    
         
             
              s.description = %q{apirunner is a testsuite to query your RESTful JSON API and match response with your defined expectations}
         
     | 
| 
       14 
14 
     | 
    
         
             
              s.email = %q{developers@moviepilot.com}
         
     | 
| 
       15 
15 
     | 
    
         
             
              s.extra_rdoc_files = [
         
     | 
    
        data/lib/api_runner.rb
    CHANGED
    
    | 
         @@ -17,7 +17,7 @@ class ApiRunner 
     | 
|
| 
       17 
17 
     | 
    
         
             
                load_config(env)
         
     | 
| 
       18 
18 
     | 
    
         
             
                load_excludes(env)
         
     | 
| 
       19 
19 
     | 
    
         
             
                load_url_spec
         
     | 
| 
       20 
     | 
    
         
            -
                @http_client = HttpClient.new(@configuration.host, @configuration.port, @configuration.namespace)
         
     | 
| 
      
 20 
     | 
    
         
            +
                @http_client = HttpClient.new(@configuration.protocol, @configuration.host, @configuration.port, @configuration.namespace)
         
     | 
| 
       21 
21 
     | 
    
         
             
                @expectation = ExpectationMatcher.new(@excludes)
         
     | 
| 
       22 
22 
     | 
    
         
             
              end
         
     | 
| 
       23 
23 
     | 
    
         | 
| 
         @@ -38,7 +38,7 @@ class ApiRunner 
     | 
|
| 
       38 
38 
     | 
    
         
             
              # runs all testcases that are provided by the testclass an fills errors if there are any
         
     | 
| 
       39 
39 
     | 
    
         
             
              def run_tests
         
     | 
| 
       40 
40 
     | 
    
         
             
                @spec.each do |test_case|
         
     | 
| 
       41 
     | 
    
         
            -
                  response = send_request(test_case['request']['method'].downcase.to_sym, test_case['request']['path'], test_case['request']['headers'], test_case['request']['body'])
         
     | 
| 
      
 41 
     | 
    
         
            +
                  response = send_request(test_case['request']['method'].downcase.to_sym, test_case['request']['path'], test_case['request']['headers'], test_case['request']['body'], test_case['request']['parameters'])
         
     | 
| 
       42 
42 
     | 
    
         
             
                  @expectation.test_types.each do |test_type|
         
     | 
| 
       43 
43 
     | 
    
         
             
                    result = @expectation.check(test_type, response, test_case)
         
     | 
| 
       44 
44 
     | 
    
         
             
                    if not result.succeeded
         
     | 
| 
         @@ -56,8 +56,8 @@ class ApiRunner 
     | 
|
| 
       56 
56 
     | 
    
         
             
              end
         
     | 
| 
       57 
57 
     | 
    
         | 
| 
       58 
58 
     | 
    
         
             
              # sends http request and fetches response using the given http client
         
     | 
| 
       59 
     | 
    
         
            -
              def send_request(method, uri, headers, data)
         
     | 
| 
       60 
     | 
    
         
            -
                @http_client.send_request(method, uri, headers, data)
         
     | 
| 
      
 59 
     | 
    
         
            +
              def send_request(method, uri, headers, data, params)
         
     | 
| 
      
 60 
     | 
    
         
            +
                @http_client.send_request(method, uri, headers, data, params)
         
     | 
| 
       61 
61 
     | 
    
         
             
              end
         
     | 
| 
       62 
62 
     | 
    
         | 
| 
       63 
63 
     | 
    
         
             
              # builds target uri from base uri generated of host port and namespace as well as the ressource path
         
     | 
    
        data/lib/http_client.rb
    CHANGED
    
    | 
         @@ -1,15 +1,16 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            class HttpClient
         
     | 
| 
       2 
2 
     | 
    
         
             
              require 'net/http'
         
     | 
| 
       3 
3 
     | 
    
         | 
| 
       4 
     | 
    
         
            -
              def initialize(host, port, namespace)
         
     | 
| 
      
 4 
     | 
    
         
            +
              def initialize(protocol, host, port, namespace)
         
     | 
| 
       5 
5 
     | 
    
         
             
                @http = Net::HTTP.new(host, port)
         
     | 
| 
      
 6 
     | 
    
         
            +
                @protocol = protocol
         
     | 
| 
       6 
7 
     | 
    
         
             
                @host = host
         
     | 
| 
       7 
8 
     | 
    
         
             
                @port = port
         
     | 
| 
       8 
9 
     | 
    
         
             
                @namespace = namespace
         
     | 
| 
       9 
10 
     | 
    
         
             
              end
         
     | 
| 
       10 
11 
     | 
    
         | 
| 
       11 
     | 
    
         
            -
              def send_request(method, resource, headers=nil, data=nil)
         
     | 
| 
       12 
     | 
    
         
            -
                build_response(self.send(method.to_s.downcase, headers, resource, data))
         
     | 
| 
      
 12 
     | 
    
         
            +
              def send_request(method, resource, headers=nil, data=nil, params=nil)
         
     | 
| 
      
 13 
     | 
    
         
            +
                build_response(self.send(method.to_s.downcase, headers, resource, data, params))
         
     | 
| 
       13 
14 
     | 
    
         
             
              end
         
     | 
| 
       14 
15 
     | 
    
         | 
| 
       15 
16 
     | 
    
         
             
              protected
         
     | 
| 
         @@ -22,37 +23,50 @@ class HttpClient 
     | 
|
| 
       22 
23 
     | 
    
         
             
                response.code = raw_response.code
         
     | 
| 
       23 
24 
     | 
    
         
             
                response.message = raw_response.message
         
     | 
| 
       24 
25 
     | 
    
         
             
                response.body = raw_response.body
         
     | 
| 
       25 
     | 
    
         
            -
                # response.headers = raw_response.header
         
     | 
| 
       26 
     | 
    
         
            -
                # TODO improve me!
         
     | 
| 
       27 
26 
     | 
    
         
             
                response.headers = JSON.parse(raw_response.header.to_json) rescue nil
         
     | 
| 
       28 
27 
     | 
    
         
             
                response
         
     | 
| 
       29 
28 
     | 
    
         
             
              end
         
     | 
| 
       30 
29 
     | 
    
         | 
| 
       31 
     | 
    
         
            -
               
     | 
| 
       32 
     | 
    
         
            -
             
     | 
| 
      
 30 
     | 
    
         
            +
              # sends GET request and returns response
         
     | 
| 
      
 31 
     | 
    
         
            +
              def get(headers, resource, data, params)
         
     | 
| 
      
 32 
     | 
    
         
            +
                request = Net::HTTP::Get.new(build_uri(resource, params).request_uri, initheader = headers)
         
     | 
| 
       33 
33 
     | 
    
         
             
                @http.request(request)
         
     | 
| 
       34 
34 
     | 
    
         
             
              end
         
     | 
| 
       35 
35 
     | 
    
         | 
| 
       36 
     | 
    
         
            -
               
     | 
| 
      
 36 
     | 
    
         
            +
              # sends PUT request and returns response
         
     | 
| 
      
 37 
     | 
    
         
            +
              def put(headers, resource, data, params)
         
     | 
| 
       37 
38 
     | 
    
         
             
                request = Net::HTTP::Put.new(resource_path(resource), initheader = headers)
         
     | 
| 
       38 
39 
     | 
    
         
             
                request.body = data.to_json
         
     | 
| 
       39 
40 
     | 
    
         
             
                @http.request(request)
         
     | 
| 
       40 
41 
     | 
    
         
             
              end
         
     | 
| 
       41 
42 
     | 
    
         | 
| 
       42 
     | 
    
         
            -
               
     | 
| 
      
 43 
     | 
    
         
            +
              # sends POST request and returns response
         
     | 
| 
      
 44 
     | 
    
         
            +
              def post(headers, resource, data, params)
         
     | 
| 
       43 
45 
     | 
    
         
             
                request = Net::HTTP::Post.new(resource_path(resource), initheader = headers)
         
     | 
| 
       44 
46 
     | 
    
         
             
                request.body = data.to_json
         
     | 
| 
       45 
47 
     | 
    
         
             
                @http.request(request)
         
     | 
| 
       46 
48 
     | 
    
         
             
              end
         
     | 
| 
       47 
49 
     | 
    
         | 
| 
       48 
     | 
    
         
            -
             
     | 
| 
       49 
     | 
    
         
            -
              def delete(headers, resource, params)
         
     | 
| 
      
 50 
     | 
    
         
            +
              # sends DELETE request and returns response
         
     | 
| 
      
 51 
     | 
    
         
            +
              def delete(headers, resource, data, params)
         
     | 
| 
       50 
52 
     | 
    
         
             
                request = Net::HTTP::Delete.new(resource_path(resource), initheader = headers)
         
     | 
| 
       51 
53 
     | 
    
         
             
                @http.request(request)
         
     | 
| 
       52 
54 
     | 
    
         
             
              end
         
     | 
| 
       53 
55 
     | 
    
         | 
| 
      
 56 
     | 
    
         
            +
              # redefines the resource path including the namespace
         
     | 
| 
       54 
57 
     | 
    
         
             
              def resource_path(resource)
         
     | 
| 
      
 58 
     | 
    
         
            +
                @namespace.nil? ? resource : "/" + @namespace + resource
         
     | 
| 
       55 
59 
     | 
    
         
             
                "/" + @namespace + resource
         
     | 
| 
       56 
60 
     | 
    
         
             
              end
         
     | 
| 
       57 
     | 
    
         
            -
            end
         
     | 
| 
       58 
61 
     | 
    
         | 
| 
      
 62 
     | 
    
         
            +
              # rebuild a uri in details, so that another protocol, host, port and GET params can be specified, after Net::HTTP was created
         
     | 
| 
      
 63 
     | 
    
         
            +
              def build_uri(resource, params=nil)
         
     | 
| 
      
 64 
     | 
    
         
            +
                uri = URI.parse(@protocol + "://" + @host + ((@port.nil? || @port != "80") ? ":#{@port}" : ""))
         
     | 
| 
      
 65 
     | 
    
         
            +
                uri.scheme = @protocol
         
     | 
| 
      
 66 
     | 
    
         
            +
                uri.host = @host
         
     | 
| 
      
 67 
     | 
    
         
            +
                uri.port = @port
         
     | 
| 
      
 68 
     | 
    
         
            +
                uri.query = "".concat(params.collect { |k,v| "#{k}=#{CGI::escape(v.to_s)}" }.reverse.join('&')) if not params.nil?
         
     | 
| 
      
 69 
     | 
    
         
            +
                uri.path = resource_path(resource)
         
     | 
| 
      
 70 
     | 
    
         
            +
                uri
         
     | 
| 
      
 71 
     | 
    
         
            +
              end
         
     | 
| 
      
 72 
     | 
    
         
            +
            end
         
     | 
    
        metadata
    CHANGED
    
    | 
         @@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version 
     | 
|
| 
       5 
5 
     | 
    
         
             
              segments: 
         
     | 
| 
       6 
6 
     | 
    
         
             
              - 0
         
     | 
| 
       7 
7 
     | 
    
         
             
              - 2
         
     | 
| 
       8 
     | 
    
         
            -
              -  
     | 
| 
       9 
     | 
    
         
            -
              version: 0.2. 
     | 
| 
      
 8 
     | 
    
         
            +
              - 2
         
     | 
| 
      
 9 
     | 
    
         
            +
              version: 0.2.2
         
     | 
| 
       10 
10 
     | 
    
         
             
            platform: ruby
         
     | 
| 
       11 
11 
     | 
    
         
             
            authors: 
         
     | 
| 
       12 
12 
     | 
    
         
             
            - jan@moviepilot.com
         
     | 
| 
         @@ -14,7 +14,7 @@ autorequire: 
     | 
|
| 
       14 
14 
     | 
    
         
             
            bindir: bin
         
     | 
| 
       15 
15 
     | 
    
         
             
            cert_chain: []
         
     | 
| 
       16 
16 
     | 
    
         | 
| 
       17 
     | 
    
         
            -
            date: 2010-09- 
     | 
| 
      
 17 
     | 
    
         
            +
            date: 2010-09-29 00:00:00 +02:00
         
     | 
| 
       18 
18 
     | 
    
         
             
            default_executable: 
         
     | 
| 
       19 
19 
     | 
    
         
             
            dependencies: 
         
     | 
| 
       20 
20 
     | 
    
         
             
            - !ruby/object:Gem::Dependency 
         
     | 
| 
         @@ -271,7 +271,7 @@ required_ruby_version: !ruby/object:Gem::Requirement 
     | 
|
| 
       271 
271 
     | 
    
         
             
              requirements: 
         
     | 
| 
       272 
272 
     | 
    
         
             
              - - ">="
         
     | 
| 
       273 
273 
     | 
    
         
             
                - !ruby/object:Gem::Version 
         
     | 
| 
       274 
     | 
    
         
            -
                  hash: - 
     | 
| 
      
 274 
     | 
    
         
            +
                  hash: -4005892316896513096
         
     | 
| 
       275 
275 
     | 
    
         
             
                  segments: 
         
     | 
| 
       276 
276 
     | 
    
         
             
                  - 0
         
     | 
| 
       277 
277 
     | 
    
         
             
                  version: "0"
         
     |