Class: QaServer::ScenarioLogger

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
app/loggers/qa_server/scenario_logger.rb

Constant Summary collapse

PASS =
QaServer::ScenarioValidator::PASS
FAIL =
QaServer::ScenarioValidator::FAIL
UNKNOWN =
QaServer::ScenarioValidator::UNKNOWN

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(test_count = 0, failure_count = 0) ⇒ ScenarioLogger

Returns a new instance of ScenarioLogger.



16
17
18
19
20
# File 'app/loggers/qa_server/scenario_logger.rb', line 16

def initialize(test_count = 0, failure_count = 0)
  @log = []
  @test_count = test_count
  @failure_count = failure_count
end

Instance Attribute Details

#failure_countObject (readonly)

Returns the value of attribute failure_count.



10
11
12
# File 'app/loggers/qa_server/scenario_logger.rb', line 10

def failure_count
  @failure_count
end

#test_countObject (readonly)

Returns the value of attribute test_count.



10
11
12
# File 'app/loggers/qa_server/scenario_logger.rb', line 10

def test_count
  @test_count
end

Instance Method Details

#add(status_info) ⇒ Object

Add a scenario to the log

Parameters:

  • status_info (Hash)

    holding information to be logged

  • authority_name (Hash)

    a customizable set of options

  • status (Hash)

    a customizable set of options

  • validation_type (Hash)

    a customizable set of options

  • subauth (Hash)

    a customizable set of options

  • service (Hash)

    a customizable set of options

  • action (Hash)

    a customizable set of options

  • url (Hash)

    a customizable set of options

  • request_data (Hash)

    a customizable set of options

  • error_message (Hash)

    a customizable set of options

  • expected (Hash)

    a customizable set of options

  • actual (Hash)

    a customizable set of options

  • target (Hash)

    a customizable set of options

  • request_run_time (Hash)

    a customizable set of options

  • normalization_run_time (Hash)

    a customizable set of options



38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'app/loggers/qa_server/scenario_logger.rb', line 38

def add(status_info) # rubocop:disable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity, Metrics/MethodLength
  @test_count += 1
  @failure_count += 1 unless status_info[:status] == PASS
  @log << { type: status_info[:validation_type] || '',
            status: status_info[:status] || '',
            authority_name: status_info[:authority_name] || '',
            subauthority_name: status_info[:subauth] || '',
            service: status_info[:service] || '',
            action: status_info[:action] || '',
            url: status_info[:url] || '',
            request_data: status_info[:request_data] || '',
            expected: status_info[:expected] || nil,
            actual: status_info[:actual] || nil,
            target: status_info[:target] || nil,
            err_message: status_info[:error_message] || '',
            request_run_time: status_info[:request_run_time] || nil,
            normalization_run_time: status_info[:normalization_run_time] || nil,
            pending: status_info[:pending] || false }
end

#append(other) ⇒ Object

Append a log to this log.

Parameters:

  • the (ScenarioLog)

    log to append to this log



65
66
67
68
69
70
# File 'app/loggers/qa_server/scenario_logger.rb', line 65

def append(other)
  return if other.blank?
  @log += other.to_a
  @test_count += other.test_count
  @failure_count += other.failure_count
end

#delete_passingObject

Delete from the log any tests that passed.



59
60
61
# File 'app/loggers/qa_server/scenario_logger.rb', line 59

def delete_passing
  @log.delete_if { |entry| entry[:status] == PASS }
end

#filter(type: nil, group: false) ⇒ Object

Returns selected scenario test results data as an array limited to the specified type or all scenarios if type is nil.

Examples:

ungrouped

[ { type: :accuracy_test,
    status: :PASS,
    authority_name: 'CERL_LD4L_CACHE',
    subauthority_name: 'imprint',
    service: 'ld4l_cache',
    action: 'search',
    url: '/qa/search/linked_data/cerl_ld4l_cache/imprint?q=Plantin&maxRecords=8',
    request_data: 'Plantin',
    expected: 1,
    actual: 1,
    target: 'http://thesaurus.cerl.org/record/cni00007649',
    err_message: '',
    request_run_time: 0.032,
    normalization_run_time: 0.011,
    pending: false },
    ... ]

grouped

{ CERL_LD4L_CACHE =
    [ { type: :accuracy_test,
        status: :PASS,
        authority_name: 'CERL_LD4L_CACHE',
        subauthority_name: 'imprint',
        service: 'ld4l_cache',
        action: 'search',
        url: '/qa/search/linked_data/cerl_ld4l_cache/imprint?q=Plantin&maxRecords=8',
        request_data: 'Plantin',
        expected: 1,
        actual: 1,
        target: 'http://thesaurus.cerl.org/record/cni00007649',
        err_message: '',
        request_run_time: 0.032,
        normalization_run_time: 0.011,
        pending: false },
        ... # all others for CERL_LD4L_CACHE
    ],
  CERL_NEW_LD4L_CACHE =
    [ { type: :accuracy_test,
        status: :PASS,
        authority_name: 'CERL_NEW_LD4L_CACHE',
        subauthority_name: 'imprint',
        service: 'ld4l_cache',
        action: 'search',
        url: '/qa/search/linked_data/cerl_new_ld4l_cache/imprint?q=Plantin&maxRecords=8',
        request_data: 'Plantin',
        expected: 1,
        actual: 1,
        target: 'http://thesaurus.cerl.org/record/cni00007649',
        err_message: '',
        request_run_time: 0.022,
        normalization_run_time: 0.011,
        pending: false },
        ... # all others for CERL_NEW_LD4L_CACHE
    ]
}

Returns:

  • selected scenario test results data as an array limited to the specified type or all scenarios if type is nil



128
129
130
131
132
133
# File 'app/loggers/qa_server/scenario_logger.rb', line 128

def filter(type: nil, group: false)
  return group_data(@log) if group && type.blank?
  return @log if type.blank?
  filtered_log = @log.select { |entry| entry[:type] == type }
  group ? group_data(filtered_log) : filtered_log
end

#group_data(log) ⇒ Object



135
136
137
138
139
140
141
142
143
# File 'app/loggers/qa_server/scenario_logger.rb', line 135

def group_data(log)
  grouped_data = {}
  log.each do |datum|
    auth_name = datum[:authority_name]
    grouped_data[auth_name] = [] unless grouped_data.key? auth_name
    grouped_data[auth_name] << datum
  end
  grouped_data
end

#sizeObject

Returns the number of scenarios recorded in the log.

Returns:

  • the number of scenarios recorded in the log



8
# File 'app/loggers/qa_server/scenario_logger.rb', line 8

delegate :size, :each, to: :@log

#to_aObject

Returns the scenario test results data as an array.

Returns:

  • the scenario test results data as an array



146
147
148
# File 'app/loggers/qa_server/scenario_logger.rb', line 146

def to_a
  @log
end