apimatic-testing-calculator 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,23 @@
1
+ # apimatic_testing_calculator
2
+ #
3
+ # This file was automatically generated by
4
+ # APIMATIC v2.0 ( https://apimatic.io ).
5
+
6
+ module ApimaticTestingCalculator
7
+ # Http response received.
8
+ class HttpResponse
9
+ attr_accessor :status_code, :headers, :raw_body
10
+
11
+ # The constructor
12
+ # @param [Integer] The status code returned by the server.
13
+ # @param [Hash] The headers sent by the server in the response.
14
+ # @param [String] The raw body of the response.
15
+ def initialize(status_code,
16
+ headers,
17
+ raw_body)
18
+ @status_code = status_code
19
+ @headers = headers
20
+ @raw_body = raw_body
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,36 @@
1
+ # apimatic_testing_calculator
2
+ #
3
+ # This file was automatically generated by
4
+ # APIMATIC v2.0 ( https://apimatic.io ).
5
+
6
+ module ApimaticTestingCalculator
7
+ # Base model.
8
+ class BaseModel
9
+ # Returns a Hash representation of the current object.
10
+ def to_hash
11
+ hash = {}
12
+ instance_variables.each do |name|
13
+ value = instance_variable_get(name)
14
+ name = name[1..-1]
15
+ key = self.class.names.key?(name) ? self.class.names[name] : name
16
+ if value.instance_of? Array
17
+ hash[key] = value.map { |v| v.is_a?(BaseModel) ? v.to_hash : v }
18
+ elsif value.instance_of? Hash
19
+ hash[key] = {}
20
+ value.each do |k, v|
21
+ hash[key][k] = v.is_a?(BaseModel) ? v.to_hash : v
22
+ end
23
+ else
24
+ hash[key] = value.is_a?(BaseModel) ? value.to_hash : value
25
+ end
26
+ end
27
+ hash
28
+ end
29
+
30
+ # Returns a JSON representation of the curent object.
31
+ def to_json(options = {})
32
+ hash = to_hash
33
+ hash.to_json(options)
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,23 @@
1
+ # apimatic_testing_calculator
2
+ #
3
+ # This file was automatically generated by
4
+ # APIMATIC v2.0 ( https://apimatic.io ).
5
+
6
+ module ApimaticTestingCalculator
7
+ # Operations types include: SUM, SUBTRACT, DIVIDE, MULTIPLY
8
+ class OperationTypeEnum
9
+ OPERATION_TYPE_ENUM = [
10
+ # Adds the specified variables.
11
+ SUM = 'SUM'.freeze,
12
+
13
+ # Subtracts the specified variables.
14
+ SUBTRACT = 'SUBTRACT'.freeze,
15
+
16
+ # Multiplies the specified variables.
17
+ MULTIPLY = 'MULTIPLY'.freeze,
18
+
19
+ # Divides the specified variables.
20
+ DIVIDE = 'DIVIDE'.freeze
21
+ ].freeze
22
+ end
23
+ end
@@ -0,0 +1,33 @@
1
+ # apimatic_testing_calculator
2
+ #
3
+ # This file was automatically generated by
4
+ # APIMATIC v2.0 ( https://apimatic.io ).
5
+
6
+ require 'json'
7
+ require 'test/unit'
8
+ require 'apimatic_testing_calculator.rb'
9
+ require_relative '../test_helper.rb'
10
+ require_relative '../http_response_catcher.rb'
11
+
12
+ class ControllerTestBase < Test::Unit::TestCase
13
+ include ApimaticTestingCalculator
14
+
15
+ class << self
16
+ attr_accessor :controller
17
+ end
18
+
19
+ # Called only once for a test class before any test has executed.
20
+ def self.startup
21
+ @@api_client = ApimaticTestingCalculatorClient.new
22
+ @@request_timeout = 30
23
+ @@assert_precision = 0.01
24
+
25
+
26
+ end
27
+
28
+ # Called once before every test case.
29
+ def setup
30
+ @response_catcher = HttpResponseCatcher.new
31
+ self.class.controller.http_call_back = @response_catcher
32
+ end
33
+ end
@@ -0,0 +1,86 @@
1
+ # apimatic_testing_calculator
2
+ #
3
+ # This file was automatically generated by
4
+ # APIMATIC v2.0 ( https://apimatic.io ).
5
+
6
+ require_relative 'controller_test_base'
7
+
8
+ class SimpleCalculatorControllerTests < ControllerTestBase
9
+ # Called only once for the class before any test has executed
10
+ def self.startup
11
+ self.controller = @@api_client.simple_calculator
12
+ end
13
+
14
+ # Checks if the test case returns the correct value after adding the input variables.
15
+ def test_test_sum()
16
+ # Parameters for the API call
17
+ operation = 'SUM'
18
+ x = 20
19
+ y = 30
20
+
21
+ # Perform the API call through the SDK function
22
+ result = self.class.controller.get_calculate(operation, x, y)
23
+
24
+ # Test response code
25
+ assert_equal(@response_catcher.response.status_code, 200)
26
+
27
+ # Test whether the captured response is as we expected
28
+ assert_not_nil(result)
29
+ assert_equal('50', @response_catcher.response.raw_body)
30
+ end
31
+
32
+ # Checks if the test case returns the correct value after subtracting the input variables.
33
+ def test_test_subtract()
34
+ # Parameters for the API call
35
+ operation = 'SUBTRACT'
36
+ x = 30
37
+ y = 20
38
+
39
+ # Perform the API call through the SDK function
40
+ result = self.class.controller.get_calculate(operation, x, y)
41
+
42
+ # Test response code
43
+ assert_equal(@response_catcher.response.status_code, 200)
44
+
45
+ # Test whether the captured response is as we expected
46
+ assert_not_nil(result)
47
+ assert_equal('10', @response_catcher.response.raw_body)
48
+ end
49
+
50
+ # Checks if the test case returns the correct value after multiplying the input variables.
51
+ def test_test_multiply()
52
+ # Parameters for the API call
53
+ operation = 'MULTIPLY'
54
+ x = 20
55
+ y = 3.5
56
+
57
+ # Perform the API call through the SDK function
58
+ result = self.class.controller.get_calculate(operation, x, y)
59
+
60
+ # Test response code
61
+ assert_equal(@response_catcher.response.status_code, 200)
62
+
63
+ # Test whether the captured response is as we expected
64
+ assert_not_nil(result)
65
+ assert_equal('70', @response_catcher.response.raw_body)
66
+ end
67
+
68
+ # Checks if the test case returns the correct value after dividing the input variables.
69
+ def test_test_divide()
70
+ # Parameters for the API call
71
+ operation = 'DIVIDE'
72
+ x = 30
73
+ y = 2
74
+
75
+ # Perform the API call through the SDK function
76
+ result = self.class.controller.get_calculate(operation, x, y)
77
+
78
+ # Test response code
79
+ assert_equal(@response_catcher.response.status_code, 200)
80
+
81
+ # Test whether the captured response is as we expected
82
+ assert_not_nil(result)
83
+ assert_equal('15', @response_catcher.response.raw_body)
84
+ end
85
+
86
+ end
@@ -0,0 +1,20 @@
1
+ # apimatic_testing_calculator
2
+ #
3
+ # This file was automatically generated by
4
+ # APIMATIC v2.0 ( https://apimatic.io ).
5
+
6
+
7
+ # HttpResponseCatcher
8
+ class HttpResponseCatcher < ApimaticTestingCalculator::HttpCallBack
9
+ attr_accessor :response
10
+
11
+ def on_before_request(request) end
12
+
13
+ # Catching the response
14
+ def on_after_response(context)
15
+ @response = context.response
16
+ end
17
+ end
18
+
19
+
20
+
@@ -0,0 +1,99 @@
1
+ # apimatic_testing_calculator
2
+ #
3
+ # This file was automatically generated by
4
+ # APIMATIC v2.0 ( https://apimatic.io ).
5
+
6
+ require 'tempfile'
7
+ require 'open-uri'
8
+ # TestHelper Class
9
+ class TestHelper
10
+ @cache = Hash.new
11
+
12
+ # Class method to compare the received headers with the expected headers.
13
+ # @param [Hash] A hash of expected headers (keys in lower case).
14
+ # @param [Hash] A hash of received headers.
15
+ # @param [Boolean, optional] A flag which determines if we allow
16
+ # extra headers.
17
+ def self.match_headers(expected_headers,
18
+ received_headers,
19
+ allow_extra: true)
20
+ return false if (received_headers.length < expected_headers.length) ||
21
+ ((allow_extra == false) &&
22
+ (received_headers.length > expected_headers.length))
23
+
24
+ received_headers = Hash[received_headers.map { |k, v| [k.to_s.downcase, v] }]
25
+ expected_headers.each do |e_key, e_value|
26
+ return false unless received_headers.key?(e_key)
27
+ return false if (e_value != nil) &&
28
+ (e_value != received_headers[e_key])
29
+ end
30
+
31
+ true
32
+ end
33
+
34
+ # Class method to compare the received body with the expected body.
35
+ # @param [Dynamic] The expected body.
36
+ # @param [Dynamic] The received body.
37
+ # @param [Boolean, optional] A flag which determines if we check values
38
+ # in dictionaries.
39
+ # @param [Boolean, optional] A flag which determines if we check the order
40
+ # of array elements.
41
+ # @param [Boolean, optional] A flag which determines if we check the count
42
+ # of array elements.
43
+ def self.match_body(expected_body,
44
+ received_body,
45
+ check_values: false,
46
+ check_order: false,
47
+ check_count: false)
48
+ if expected_body.instance_of? Hash
49
+ return false unless received_body.instance_of? Hash
50
+ for key in expected_body.keys
51
+ return false unless received_body.keys.include? key
52
+ if check_values or expected_body[key].instance_of? Hash
53
+ return false unless TestHelper.match_body(expected_body[key],
54
+ received_body[key],
55
+ check_values: check_values,
56
+ check_order: check_order,
57
+ check_count: check_count)
58
+ end
59
+ end
60
+ elsif expected_body.instance_of? Array
61
+ return False unless received_body.instance_of? Array
62
+ if check_count == true && (expected_body.length != received_body.length)
63
+ return false
64
+ else
65
+ previous_matches = Array.new
66
+ expected_body.each.with_index do |expected_element, i|
67
+ matches = (received_body.map.with_index do |received_element, j|
68
+ j if TestHelper.match_body(expected_element,
69
+ received_element,
70
+ check_values: check_values,
71
+ check_order: check_order,
72
+ check_count: check_count)
73
+ end).compact
74
+ return false if matches.length == 0
75
+ if check_order == true
76
+ return false if i != 0 && matches.map { |x| previous_matches.map { |y| y > x }.all? }.all?
77
+ previous_matches = matches
78
+ end
79
+ end
80
+ end
81
+ elsif expected_body != received_body
82
+ return false
83
+ end
84
+ true
85
+ end
86
+
87
+ # Class method which takes a URL, downloads the file
88
+ # (if not already downloaded for this test session)
89
+ # and returns the path of the file.
90
+ # @param [String] The URL of the required file.
91
+ def self.get_file(url)
92
+ unless @cache.keys.include? url
93
+ @cache[url] = Tempfile.new('APIMatic')
94
+ @cache[url].binmode
95
+ @cache[url].write(open(url, { ssl_ca_cert: Certifi.where }).read)
96
+ end
97
+ @cache[url].path
98
+ end
99
+ end
metadata ADDED
@@ -0,0 +1,161 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: apimatic-testing-calculator
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Nida
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2020-11-30 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: logging
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '2.0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '2.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: faraday
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '0.10'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '0.10'
41
+ - !ruby/object:Gem::Dependency
42
+ name: faraday_middleware
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: 0.13.1
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: 0.13.1
55
+ - !ruby/object:Gem::Dependency
56
+ name: test-unit
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '3.1'
62
+ - - ">="
63
+ - !ruby/object:Gem::Version
64
+ version: 3.1.5
65
+ type: :runtime
66
+ prerelease: false
67
+ version_requirements: !ruby/object:Gem::Requirement
68
+ requirements:
69
+ - - "~>"
70
+ - !ruby/object:Gem::Version
71
+ version: '3.1'
72
+ - - ">="
73
+ - !ruby/object:Gem::Version
74
+ version: 3.1.5
75
+ - !ruby/object:Gem::Dependency
76
+ name: certifi
77
+ requirement: !ruby/object:Gem::Requirement
78
+ requirements:
79
+ - - "~>"
80
+ - !ruby/object:Gem::Version
81
+ version: '2016'
82
+ type: :runtime
83
+ prerelease: false
84
+ version_requirements: !ruby/object:Gem::Requirement
85
+ requirements:
86
+ - - "~>"
87
+ - !ruby/object:Gem::Version
88
+ version: '2016'
89
+ - !ruby/object:Gem::Dependency
90
+ name: faraday-http-cache
91
+ requirement: !ruby/object:Gem::Requirement
92
+ requirements:
93
+ - - "~>"
94
+ - !ruby/object:Gem::Version
95
+ version: '1.2'
96
+ - - ">="
97
+ - !ruby/object:Gem::Version
98
+ version: 1.2.2
99
+ type: :runtime
100
+ prerelease: false
101
+ version_requirements: !ruby/object:Gem::Requirement
102
+ requirements:
103
+ - - "~>"
104
+ - !ruby/object:Gem::Version
105
+ version: '1.2'
106
+ - - ">="
107
+ - !ruby/object:Gem::Version
108
+ version: 1.2.2
109
+ description: Calculator API built with APIMATIC
110
+ email: nida.zamir@apimatic.io
111
+ executables: []
112
+ extensions: []
113
+ extra_rdoc_files: []
114
+ files:
115
+ - LICENSE
116
+ - README.md
117
+ - lib/apimatic_testing_calculator.rb
118
+ - lib/apimatic_testing_calculator/api_helper.rb
119
+ - lib/apimatic_testing_calculator/apimatic_testing_calculator_client.rb
120
+ - lib/apimatic_testing_calculator/configuration.rb
121
+ - lib/apimatic_testing_calculator/controllers/base_controller.rb
122
+ - lib/apimatic_testing_calculator/controllers/simple_calculator_controller.rb
123
+ - lib/apimatic_testing_calculator/exceptions/api_exception.rb
124
+ - lib/apimatic_testing_calculator/http/faraday_client.rb
125
+ - lib/apimatic_testing_calculator/http/http_call_back.rb
126
+ - lib/apimatic_testing_calculator/http/http_client.rb
127
+ - lib/apimatic_testing_calculator/http/http_context.rb
128
+ - lib/apimatic_testing_calculator/http/http_method_enum.rb
129
+ - lib/apimatic_testing_calculator/http/http_request.rb
130
+ - lib/apimatic_testing_calculator/http/http_response.rb
131
+ - lib/apimatic_testing_calculator/models/base_model.rb
132
+ - lib/apimatic_testing_calculator/models/operation_type_enum.rb
133
+ - test/controllers/controller_test_base.rb
134
+ - test/controllers/test_simple_calculator_controller.rb
135
+ - test/http_response_catcher.rb
136
+ - test/test_helper.rb
137
+ homepage: https://apimatic.io
138
+ licenses:
139
+ - MIT
140
+ metadata: {}
141
+ post_install_message:
142
+ rdoc_options: []
143
+ require_paths:
144
+ - lib
145
+ required_ruby_version: !ruby/object:Gem::Requirement
146
+ requirements:
147
+ - - "~>"
148
+ - !ruby/object:Gem::Version
149
+ version: '2.0'
150
+ required_rubygems_version: !ruby/object:Gem::Requirement
151
+ requirements:
152
+ - - ">="
153
+ - !ruby/object:Gem::Version
154
+ version: '0'
155
+ requirements: []
156
+ rubyforge_project:
157
+ rubygems_version: 2.7.6
158
+ signing_key:
159
+ specification_version: 4
160
+ summary: apimatic_testing_calculator
161
+ test_files: []