moesif_api 1.0.3 → 1.0.4

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,28 +1,28 @@
1
-
2
-
3
- require 'json'
4
- require 'test/unit'
5
- require 'moesif_api.rb'
6
- require_relative '../test_helper.rb'
7
- require_relative '../http_response_catcher.rb'
8
-
9
- class ControllerTestBase < Test::Unit::TestCase
10
- include MoesifApi
11
-
12
- class << self
13
- attr_accessor :controller
14
- end
15
-
16
- # Called only once for a test class before any test has executed.
17
- def self.startup
18
- @@api_client = MoesifAPIClient.new("eyJhcHAiOiIzNjU6NiIsInZlciI6IjIuMCIsIm9yZyI6IjM1OTo0IiwiaWF0IjoxNDczMzc5MjAwfQ.9WOx3D357PGMxrXzFm3pV3IzJSYNsO4oRudiMI8mQ3Q")
19
- @@request_timeout = 30
20
- @@assert_precision = 0.01
21
- end
22
-
23
- # Called once before every test case.
24
- def setup
25
- @response_catcher = HttpResponseCatcher.new
26
- self.class.controller.http_call_back = @response_catcher
27
- end
28
- end
1
+
2
+
3
+ require 'json'
4
+ require 'test/unit'
5
+ require 'moesif_api.rb'
6
+ require_relative '../test_helper.rb'
7
+ require_relative '../http_response_catcher.rb'
8
+
9
+ class ControllerTestBase < Test::Unit::TestCase
10
+ include MoesifApi
11
+
12
+ class << self
13
+ attr_accessor :controller
14
+ end
15
+
16
+ # Called only once for a test class before any test has executed.
17
+ def self.startup
18
+ @@api_client = MoesifAPIClient.new("eyJhcHAiOiIzNjU6NiIsInZlciI6IjIuMCIsIm9yZyI6IjM1OTo0IiwiaWF0IjoxNDczMzc5MjAwfQ.9WOx3D357PGMxrXzFm3pV3IzJSYNsO4oRudiMI8mQ3Q")
19
+ @@request_timeout = 30
20
+ @@assert_precision = 0.01
21
+ end
22
+
23
+ # Called once before every test case.
24
+ def setup
25
+ @response_catcher = HttpResponseCatcher.new
26
+ self.class.controller.http_call_back = @response_catcher
27
+ end
28
+ end
@@ -1,16 +1,16 @@
1
-
2
-
3
- class HttpResponseCatcher < MoesifApi::HttpCallBack
4
- attr_accessor :response
5
-
6
- def on_before_request(request)
7
- end
8
-
9
- # Catching the response
10
- def on_after_response(context)
11
- @response = context.response
12
- end
13
- end
14
-
15
-
16
-
1
+
2
+
3
+ class HttpResponseCatcher < MoesifApi::HttpCallBack
4
+ attr_accessor :response
5
+
6
+ def on_before_request(request)
7
+ end
8
+
9
+ # Catching the response
10
+ def on_after_response(context)
11
+ @response = context.response
12
+ end
13
+ end
14
+
15
+
16
+
data/test/test_helper.rb CHANGED
@@ -1,94 +1,94 @@
1
-
2
-
3
- require 'tempfile'
4
- require 'open-uri'
5
-
6
- class TestHelper
7
-
8
- @cache = Hash.new
9
-
10
- # Class method to compare the received headers with the expected headers.
11
- # @param [Hash] A hash of expected headers (keys in lower case).
12
- # @param [Hash] A hash of received headers.
13
- # @param [Boolean, optional] A flag which determines if we allow extra headers.
14
- def self.match_headers(expected_headers,
15
- received_headers,
16
- allow_extra: true)
17
- return false if ((received_headers.length < expected_headers.length) ||
18
- ((allow_extra == false) && (received_headers.length > expected_headers.length)))
19
-
20
- received_headers = Hash[received_headers.map{|k, v| [k.to_s.downcase, v]}]
21
- expected_headers.each do |e_key, e_value|
22
- return false unless received_headers.key?(e_key)
23
- return false if ((e_value != nil) &&
24
- (e_value != received_headers[e_key]))
25
- end
26
-
27
- return true
28
- end
29
-
30
- # Class method to compare the received body with the expected body.
31
- # @param [Dynamic] The expected body.
32
- # @param [Dynamic] The received body.
33
- # @param [Boolean, optional] A flag which determines if we check values in dictionaries.
34
- # @param [Boolean, optional] A flag which determines if we check the order of array elements.
35
- # @param [Boolean, optional] A flag which determines if we check the count of array elements.
36
- def self.match_body(expected_body,
37
- received_body,
38
- check_values: false,
39
- check_order: false,
40
- check_count: false)
41
- if expected_body.instance_of? Hash
42
- return False if not received_body.instance_of? Hash
43
- for key in expected_body.keys
44
- return false if not received_body.keys.include? key
45
- if check_values or expected_body[key].instance_of? Hash
46
- return false if not TestHelper.match_body(expected_body[key],
47
- received_body[key],
48
- check_values: check_values,
49
- check_order: check_order,
50
- check_count: check_count)
51
- end
52
- end
53
- elsif expected_body.instance_of? Array
54
- return False if not received_body.instance_of? Array
55
- if check_count == true && (expected_body.length != received_body.length)
56
- return false
57
- else
58
- previous_matches = Array.new
59
- expected_body.each.with_index do |expected_element, i|
60
- matches = (received_body.map.with_index do |received_element, j|
61
- j if TestHelper.match_body(expected_element,
62
- received_element,
63
- check_values: check_values,
64
- check_order: check_order,
65
- check_count: check_count)
66
- end).compact
67
- return false if matches.length == 0
68
- if check_order == true
69
- return false if (i != 0 && matches.map{|x| previous_matches.map{|y| y > x}.all?}.all?)
70
- previous_matches = matches
71
- end
72
- end
73
- end
74
- elsif expected_body != received_body
75
- return false
76
- end
77
- return true
78
- end
79
-
80
- # Class method which takes a URL, downloads the file (if not already downloaded
81
- # for this test session) and returns a file object for the file in read-binary mode.
82
- # @param [String] The URL of the required file.
83
- def self.get_file(url)
84
- if not @cache.keys.include? url
85
- @cache[url] = Tempfile.new('APIMatic')
86
- @cache[url].binmode
87
- @cache[url].write(open(url, {ssl_verify_mode: OpenSSL::SSL::VERIFY_NONE}).read)
88
- else
89
- @cache[url].open
90
- @cache[url].binmode
91
- end
92
- return @cache[url]
93
- end
94
- end
1
+
2
+
3
+ require 'tempfile'
4
+ require 'open-uri'
5
+
6
+ class TestHelper
7
+
8
+ @cache = Hash.new
9
+
10
+ # Class method to compare the received headers with the expected headers.
11
+ # @param [Hash] A hash of expected headers (keys in lower case).
12
+ # @param [Hash] A hash of received headers.
13
+ # @param [Boolean, optional] A flag which determines if we allow extra headers.
14
+ def self.match_headers(expected_headers,
15
+ received_headers,
16
+ allow_extra: true)
17
+ return false if ((received_headers.length < expected_headers.length) ||
18
+ ((allow_extra == false) && (received_headers.length > expected_headers.length)))
19
+
20
+ received_headers = Hash[received_headers.map{|k, v| [k.to_s.downcase, v]}]
21
+ expected_headers.each do |e_key, e_value|
22
+ return false unless received_headers.key?(e_key)
23
+ return false if ((e_value != nil) &&
24
+ (e_value != received_headers[e_key]))
25
+ end
26
+
27
+ return true
28
+ end
29
+
30
+ # Class method to compare the received body with the expected body.
31
+ # @param [Dynamic] The expected body.
32
+ # @param [Dynamic] The received body.
33
+ # @param [Boolean, optional] A flag which determines if we check values in dictionaries.
34
+ # @param [Boolean, optional] A flag which determines if we check the order of array elements.
35
+ # @param [Boolean, optional] A flag which determines if we check the count of array elements.
36
+ def self.match_body(expected_body,
37
+ received_body,
38
+ check_values: false,
39
+ check_order: false,
40
+ check_count: false)
41
+ if expected_body.instance_of? Hash
42
+ return False if not received_body.instance_of? Hash
43
+ for key in expected_body.keys
44
+ return false if not received_body.keys.include? key
45
+ if check_values or expected_body[key].instance_of? Hash
46
+ return false if not TestHelper.match_body(expected_body[key],
47
+ received_body[key],
48
+ check_values: check_values,
49
+ check_order: check_order,
50
+ check_count: check_count)
51
+ end
52
+ end
53
+ elsif expected_body.instance_of? Array
54
+ return False if not received_body.instance_of? Array
55
+ if check_count == true && (expected_body.length != received_body.length)
56
+ return false
57
+ else
58
+ previous_matches = Array.new
59
+ expected_body.each.with_index do |expected_element, i|
60
+ matches = (received_body.map.with_index do |received_element, j|
61
+ j if TestHelper.match_body(expected_element,
62
+ received_element,
63
+ check_values: check_values,
64
+ check_order: check_order,
65
+ check_count: check_count)
66
+ end).compact
67
+ return false if matches.length == 0
68
+ if check_order == true
69
+ return false if (i != 0 && matches.map{|x| previous_matches.map{|y| y > x}.all?}.all?)
70
+ previous_matches = matches
71
+ end
72
+ end
73
+ end
74
+ elsif expected_body != received_body
75
+ return false
76
+ end
77
+ return true
78
+ end
79
+
80
+ # Class method which takes a URL, downloads the file (if not already downloaded
81
+ # for this test session) and returns a file object for the file in read-binary mode.
82
+ # @param [String] The URL of the required file.
83
+ def self.get_file(url)
84
+ if not @cache.keys.include? url
85
+ @cache[url] = Tempfile.new('APIMatic')
86
+ @cache[url].binmode
87
+ @cache[url].write(open(url, {ssl_verify_mode: OpenSSL::SSL::VERIFY_NONE}).read)
88
+ else
89
+ @cache[url].open
90
+ @cache[url].binmode
91
+ end
92
+ return @cache[url]
93
+ end
94
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: moesif_api
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.3
4
+ version: 1.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Moesif, Inc
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2016-10-10 00:00:00.000000000 Z
12
+ date: 2016-10-19 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: test-unit
@@ -87,7 +87,7 @@ files:
87
87
  - test/test_helper.rb
88
88
  homepage: https://moesif.com
89
89
  licenses:
90
- - MIT
90
+ - Apache-2.0
91
91
  metadata: {}
92
92
  post_install_message:
93
93
  rdoc_options: []
@@ -105,7 +105,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
105
105
  version: '0'
106
106
  requirements: []
107
107
  rubyforge_project:
108
- rubygems_version: 2.5.1
108
+ rubygems_version: 2.6.7
109
109
  signing_key:
110
110
  specification_version: 4
111
111
  summary: moesif_api