ae_easy-qa 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/ae_easy/qa/validate_external.rb +24 -0
- data/lib/ae_easy/qa/validate_groups.rb +48 -0
- data/lib/ae_easy/qa/validate_internal.rb +92 -0
- data/lib/ae_easy/qa/validate_rules.rb +26 -17
- data/lib/ae_easy/qa/validate_type.rb +2 -2
- data/lib/ae_easy/qa/version.rb +1 -1
- data/lib/ae_easy/qa.rb +16 -14
- metadata +19 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 363c9d9b41cd90e575c4f64e77c044f71ec0e9785e71a69659150ff215411e1f
|
4
|
+
data.tar.gz: 5e236351848333d7634534634d77b8f12068a972c20d1f9a592378570a302639
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3d1e88121ee00124767981264022b66271a5aaa3ccbaf74e0518d201e7c1bae5b1bf279c931cece1217f6550e369dc2fed3b57c5b3247b03f0876b2534805a16
|
7
|
+
data.tar.gz: 96a35e2965262a2fdbc8ea9b4412b1d3943a2f728774bd6bb6a9367148134e38953028e3ed0b6cfd7798675066b7957369d21a6686191024895c7b63e870a108
|
@@ -0,0 +1,24 @@
|
|
1
|
+
module AeEasy
|
2
|
+
module Qa
|
3
|
+
class ValidateExternal
|
4
|
+
attr_reader :data, :errors, :config
|
5
|
+
|
6
|
+
def initialize(data, errors, config)
|
7
|
+
@data = data
|
8
|
+
@errors = errors
|
9
|
+
@config = config
|
10
|
+
end
|
11
|
+
|
12
|
+
def run
|
13
|
+
begin
|
14
|
+
ValidateGroups.new(data, errors).run
|
15
|
+
ValidateRules.new(data, errors, config['individual_validations']).run if config
|
16
|
+
return errors
|
17
|
+
rescue StandardError => e
|
18
|
+
puts "An error has occurred: #{e}"
|
19
|
+
return nil
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,48 @@
|
|
1
|
+
module AeEasy
|
2
|
+
module Qa
|
3
|
+
class ValidateGroups
|
4
|
+
attr_reader :data, :errors
|
5
|
+
|
6
|
+
def initialize(data, errors)
|
7
|
+
@data = data
|
8
|
+
@errors = errors
|
9
|
+
end
|
10
|
+
|
11
|
+
def run
|
12
|
+
if group_validations_present?
|
13
|
+
load_module
|
14
|
+
include_module
|
15
|
+
call_validation_methods
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
private
|
20
|
+
|
21
|
+
def fail_validation(name)
|
22
|
+
errors[name.to_sym] = 'fail'
|
23
|
+
end
|
24
|
+
|
25
|
+
def load_module
|
26
|
+
load group_validations_path
|
27
|
+
end
|
28
|
+
|
29
|
+
def include_module
|
30
|
+
self.class.send(:include, GroupValidations)
|
31
|
+
end
|
32
|
+
|
33
|
+
def call_validation_methods
|
34
|
+
GroupValidations.public_instance_methods.each do |method|
|
35
|
+
self.send(method)
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
def group_validations_present?
|
40
|
+
File.exists?(group_validations_path)
|
41
|
+
end
|
42
|
+
|
43
|
+
def group_validations_path
|
44
|
+
@group_validations_path ||= File.expand_path('group_validations.rb', Dir.pwd)
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
@@ -0,0 +1,92 @@
|
|
1
|
+
module AeEasy
|
2
|
+
module Qa
|
3
|
+
class ValidateInternal
|
4
|
+
attr_reader :scrapers, :rules
|
5
|
+
|
6
|
+
def initialize(config)
|
7
|
+
@scrapers = config['scrapers']
|
8
|
+
@rules = config['individual_validations']
|
9
|
+
end
|
10
|
+
|
11
|
+
def run
|
12
|
+
begin
|
13
|
+
scrapers.each do |scraper_name, collections|
|
14
|
+
ValidateScraper.new(scraper_name, collections, rules).run
|
15
|
+
end
|
16
|
+
rescue StandardError => e
|
17
|
+
puts "An error has occurred: #{e}"
|
18
|
+
return nil
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
class ValidateScraper
|
24
|
+
attr_reader :scraper_name, :collections, :rules
|
25
|
+
|
26
|
+
def initialize(scraper_name, collections, rules)
|
27
|
+
@scraper_name = scraper_name
|
28
|
+
@collections = collections
|
29
|
+
@rules = rules
|
30
|
+
end
|
31
|
+
|
32
|
+
def run
|
33
|
+
collections.each do |collection_name|
|
34
|
+
ValidateCollection.new(scraper_name, collection_name, total_records(collection_name), rules).run
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
private
|
39
|
+
|
40
|
+
def total_records(collection_name)
|
41
|
+
collection_counts.find{|collection_hash| collection_hash['collection'] == collection_name }['count']
|
42
|
+
end
|
43
|
+
|
44
|
+
def collection_counts
|
45
|
+
@collection_counts ||= AnswersEngine::Client::ScraperJobOutput.new.collections(scraper_name)
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
class ValidateCollection
|
50
|
+
attr_reader :scraper_name, :collection_name, :total_records, :rules, :errors
|
51
|
+
|
52
|
+
def initialize(scraper_name, collection_name, total_records, rules)
|
53
|
+
@scraper_name = scraper_name
|
54
|
+
@collection_name = collection_name
|
55
|
+
@total_records = total_records
|
56
|
+
@rules = rules
|
57
|
+
@errors = { errored_items: [] }
|
58
|
+
end
|
59
|
+
|
60
|
+
def run
|
61
|
+
ValidateGroups.new(data, errors).run
|
62
|
+
#could create the errors hash inside ValidateRules?
|
63
|
+
#errors = ValidateRules.new(data, config).run
|
64
|
+
ValidateRules.new(data, errors, rules).run
|
65
|
+
#should have a class that saves the output and the summary output
|
66
|
+
#SaveOutput.new(errors, output_collection_name).run
|
67
|
+
end
|
68
|
+
|
69
|
+
private
|
70
|
+
|
71
|
+
def output_collection_name
|
72
|
+
@output_collection_name ||= "#{scraper_name}_#{collection_name}"
|
73
|
+
end
|
74
|
+
|
75
|
+
def data
|
76
|
+
@data ||= begin
|
77
|
+
data = []
|
78
|
+
page = 1
|
79
|
+
while data.count < total_records
|
80
|
+
records = AnswersEngine::Client::ScraperJobOutput.new(per_page:500, page: page).all(scraper_name, collection_name).parsed_response
|
81
|
+
records.each do |record|
|
82
|
+
data << record
|
83
|
+
end
|
84
|
+
page += 1
|
85
|
+
end
|
86
|
+
data
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
end
|
91
|
+
end
|
92
|
+
end
|
@@ -9,7 +9,7 @@ module AeEasy
|
|
9
9
|
def initialize(data, errors, rules)
|
10
10
|
@data = data
|
11
11
|
@errors = errors
|
12
|
-
@rules = rules
|
12
|
+
@rules = rules
|
13
13
|
end
|
14
14
|
|
15
15
|
def run
|
@@ -22,31 +22,40 @@ module AeEasy
|
|
22
22
|
data.each do |data_hash|
|
23
23
|
reset_errored_item
|
24
24
|
rules.each{|field_to_validate, options|
|
25
|
-
options
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
25
|
+
if passes_required_check?(options, data_hash, field_to_validate)
|
26
|
+
options.each{|validation, value|
|
27
|
+
case validation
|
28
|
+
when 'type'
|
29
|
+
ValidateType.new(data_hash, field_to_validate, value, rules, errored_item).run if options['required']
|
30
|
+
when 'value'
|
31
|
+
ValidateValue.new(data_hash, field_to_validate, value, errored_item).run if options['required']
|
32
|
+
when 'length'
|
33
|
+
validate_length(data_hash, field_to_validate, value) if options['required']
|
34
|
+
when 'required'
|
35
|
+
nil
|
36
|
+
else
|
37
|
+
unknown_validation_error(validation) if validation !~ /format/
|
38
|
+
end
|
39
|
+
}
|
40
|
+
end
|
39
41
|
}
|
40
42
|
errors[:errored_items].push(errored_item) if errored_item && !errored_item[:failures].empty?
|
41
43
|
end
|
42
44
|
end
|
43
45
|
|
44
|
-
def
|
45
|
-
if
|
46
|
+
def passes_required_check?(options, data_hash, field_to_validate)
|
47
|
+
if options['required'] == true && fails_required_check?(data_hash, field_to_validate)
|
46
48
|
add_errored_item(data_hash, field_to_validate, 'required')
|
49
|
+
false
|
50
|
+
else
|
51
|
+
true
|
47
52
|
end
|
48
53
|
end
|
49
54
|
|
55
|
+
def fails_required_check?(data_hash, field_to_validate)
|
56
|
+
data_hash[field_to_validate].nil? || (data_hash[field_to_validate].class == String && data_hash[field_to_validate].empty?)
|
57
|
+
end
|
58
|
+
|
50
59
|
def validate_length(data_hash, field_to_validate, length)
|
51
60
|
add_errored_item(data_hash, field_to_validate, 'length') if data_hash[field_to_validate].to_s.length != length
|
52
61
|
end
|
@@ -24,9 +24,9 @@ module AeEasy
|
|
24
24
|
when 'String'
|
25
25
|
add_errored_item(data_hash, field_to_validate, 'type') if data_hash[field_to_validate].class != String
|
26
26
|
when 'Integer'
|
27
|
-
add_errored_item(data_hash, field_to_validate, 'type') unless data_hash[field_to_validate].class == Fixnum || data_hash[field_to_validate].to_s.strip =~ /\A\d+(\.\d+)?\z/
|
27
|
+
add_errored_item(data_hash, field_to_validate, 'type') unless data_hash[field_to_validate].class == Fixnum || data_hash[field_to_validate].to_s.strip =~ /\A\d+(\,\d+)?(\.\d+)?\z/
|
28
28
|
when 'Float'
|
29
|
-
add_errored_item(data_hash, field_to_validate, 'type') unless data_hash[field_to_validate].class == Float || data_hash[field_to_validate].to_s.strip =~ /\A\d+(\.\d+)?\z/
|
29
|
+
add_errored_item(data_hash, field_to_validate, 'type') unless data_hash[field_to_validate].class == Float || data_hash[field_to_validate].to_s.strip =~ /\A\d+(\,\d+)?(\.\d+)?\z/
|
30
30
|
when 'Date'
|
31
31
|
validate_date_type
|
32
32
|
when 'Url'
|
data/lib/ae_easy/qa/version.rb
CHANGED
data/lib/ae_easy/qa.rb
CHANGED
@@ -1,36 +1,38 @@
|
|
1
1
|
require 'ae_easy/qa/helpers'
|
2
2
|
require 'ae_easy/qa/version'
|
3
|
+
require 'ae_easy/qa/validate_internal'
|
4
|
+
require 'ae_easy/qa/validate_external'
|
3
5
|
require 'ae_easy/qa/validate_rules'
|
4
6
|
require 'ae_easy/qa/validate_type'
|
5
7
|
require 'ae_easy/qa/validate_value'
|
8
|
+
require 'ae_easy/qa/validate_groups'
|
9
|
+
require 'answersengine'
|
6
10
|
require 'time'
|
7
11
|
|
8
12
|
module AeEasy
|
9
13
|
module Qa
|
10
|
-
class
|
11
|
-
attr_accessor :
|
14
|
+
class Validator
|
15
|
+
attr_accessor :config
|
12
16
|
attr_reader :data, :errors
|
13
17
|
|
14
|
-
def initialize(data, options={})
|
15
|
-
|
18
|
+
def initialize(data=nil, options={})
|
19
|
+
load_config
|
16
20
|
@data = data
|
17
21
|
@errors = { errored_items: [] }
|
18
22
|
end
|
19
23
|
|
20
|
-
def
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
return nil
|
27
|
-
end
|
24
|
+
def validate_internal
|
25
|
+
ValidateInternal.new(config).run
|
26
|
+
end
|
27
|
+
|
28
|
+
def validate_external
|
29
|
+
ValidateExternal.new(data, errors, config).run
|
28
30
|
end
|
29
31
|
|
30
32
|
private
|
31
33
|
|
32
|
-
def
|
33
|
-
self.
|
34
|
+
def load_config
|
35
|
+
self.config = YAML.load(File.open(config_path))['qa'] if File.exists?(config_path)
|
34
36
|
end
|
35
37
|
|
36
38
|
def config_path
|
metadata
CHANGED
@@ -1,15 +1,29 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ae_easy-qa
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- David Lynam
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-06-
|
11
|
+
date: 2019-06-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: answersengine
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
13
27
|
- !ruby/object:Gem::Dependency
|
14
28
|
name: bundler
|
15
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -64,6 +78,9 @@ files:
|
|
64
78
|
- bin/setup
|
65
79
|
- lib/ae_easy/qa.rb
|
66
80
|
- lib/ae_easy/qa/helpers.rb
|
81
|
+
- lib/ae_easy/qa/validate_external.rb
|
82
|
+
- lib/ae_easy/qa/validate_groups.rb
|
83
|
+
- lib/ae_easy/qa/validate_internal.rb
|
67
84
|
- lib/ae_easy/qa/validate_rules.rb
|
68
85
|
- lib/ae_easy/qa/validate_type.rb
|
69
86
|
- lib/ae_easy/qa/validate_value.rb
|