Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
127 changes: 127 additions & 0 deletions spec/services/deepblue/deleted_works_log_reporter_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
require 'rails_helper'


describe Deepblue::DeletedWorksLogReporter do

subject { described_class.new( input: "input" ) }


describe "#initialize" do
it "calls super" do
expect(Deepblue::EventLogFilter).to receive(:new)
Deepblue::DeletedWorksLogReporter::DeletedLogFilter.new options: {"optional" => "true"}
end

skip "Add a test that includes initialize parameters"
end


describe "#initialize" do
context "when DeletedLogFilter is blank and DataSetLogFilter is blank" do
it "calls super, calls new on DeletedLogFilter and DataSetLogFilter" do
expect(Deepblue::LogReporter).to receive(:new).with(filter: "filter", input: "stuff", options: {})
Deepblue::DeletedWorksLogReporter.new(filter: "filter", input: "stuff", options: {})
end
end

skip "Add a test where DeletedLogFilter and DataSetLogFilter are not blank"
end


describe "#report" do

before {
allow(subject).to receive(:run)
allow(subject).to receive(:deleted_ids).and_return ["alpha"]
allow(subject).to receive(:deleted_id_to_key_values_map).and_return(
{"alpha" => {"timestamp" => "stamping time", "authoremail" => "auteur email", "event_note" => "eventful", "creator" => ["artisan", "artiste"]}})
allow(subject).to receive(:puts).with("id,deleted,event_note,url,authoremail,creator")
allow(subject).to receive(:puts).with("\"alpha\",stamping time,eventful,https://deepbluedata.lib.umich.edu/provenance_log/alpha,auteur email,\"artisan;artiste\"")
}

context "when verbose" do
before {
allow(subject).to receive(:verbose).and_return true
allow(subject).to receive(:timestamp_first).and_return "first time"
allow(subject).to receive(:timestamp_last).and_return "last time"
allow(subject).to receive(:puts).with("timestamp_first = first time")
allow(subject).to receive(:puts).with("timestamp_last = last time")

allow(subject).to receive(:puts).with("deleted_ids.size = 1")
}
it "calls run and calls puts five times" do
expect(subject).to receive(:run)
expect(subject).to receive(:puts).with("timestamp_first = first time")
expect(subject).to receive(:puts).with("timestamp_last = last time")
expect(subject).to receive(:puts).with("deleted_ids.size = 1")
expect(subject).to receive(:puts).with("id,deleted,event_note,url,authoremail,creator")
expect(subject).to receive(:puts).with("\"alpha\",stamping time,eventful,https://deepbluedata.lib.umich.edu/provenance_log/alpha,auteur email,\"artisan;artiste\"")

subject.report
end
end

context "when not verbose" do
before {
allow(subject).to receive(:verbose).and_return false
}
it "calls run and calls puts twice" do
expect(subject).to receive(:run)
expect(subject).to receive(:puts).with("id,deleted,event_note,url,authoremail,creator")
expect(subject).to receive(:puts).with("\"alpha\",stamping time,eventful,https://deepbluedata.lib.umich.edu/provenance_log/alpha,auteur email,\"artisan;artiste\"")

subject.report
end
end
end


# protected methods

describe "#initialize_report_values" do
it "sets instance variables" do
subject.send(:initialize_report_values)

#testing super method
subject.instance_variable_get(:@lines_reported) == 0
subject.instance_variable_get(:@timestamp_first).blank?
subject.instance_variable_get(:@timestamp_last).blank?
subject.instance_variable_get(:@events).empty?
subject.instance_variable_get(:@class_events).empty?
subject.instance_variable_get(:@ids).empty?

subject.instance_variable_get(:@deleted_ids).empty?
subject.instance_variable_get(:@deleted_id_to_key_values_map).empty?
end
end


describe "#line_read" do
before {
subject.instance_variable_set(:@lines_reported, 0)
subject.instance_variable_set(:@ids, {})
subject.instance_variable_set(:@events, {"event" => 3})
subject.instance_variable_set(:@class_events, {"class event key" => 7})
allow(subject).to receive(:class_event_key).with(class_name: "classy name", event: "event").and_return "class event key"

subject.instance_variable_set(:@deleted_ids, ["previous ID"])
subject.instance_variable_set(:@deleted_id_to_key_values_map, {})
allow(Deepblue::ProvenanceHelper).to receive(:parse_log_line_key_values).with("raw key values").and_return "key values"
}
it "sets and updates instance variables" do
#testing super method
subject.instance_variable_get(:@lines_reported) == 1
subject.instance_variable_get(:@timestamp_first) == "time to stamp"
subject.instance_variable_get(:@timestamp_last) == "time to stamp"
subject.instance_variable_get(:@ids)["ID"] == true
subject.instance_variable_get(:@events)["event"] == 4
subject.instance_variable_get(:@class_events)["class event key"] == 8

subject.instance_variable_get(:@deleted_ids) == ["previous ID","ID"]
subject.instance_variable_get(:@deleted_id_to_key_values_map)["ID"] == "key values"

subject.send(:line_read, "line", "time to stamp", "event", "event note", "classy name", "ID", "raw key values")
end
end

end
119 changes: 119 additions & 0 deletions spec/services/deepblue/ingest_fixity_log_reporter_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
require 'rails_helper'


describe Deepblue::IngestFixityLogReporter do

subject { described_class.new( input: "stuff" ) }

describe "#initialize" do
context "when filter is not present" do
before {
allow(Deepblue::LogReporter).to receive(:new).with(filter: "filtration", input: "input", options: {})
}
it "calls super" do
expect(Deepblue::LogReporter).to receive(:new).with(filter: "filtration", input: "input", options: {})

Deepblue::IngestFixityLogReporter.new(filter: "filtration", input: "input", options: {})
end

skip "test with Deepblue::FixityCheckLogFilter"
end

context "when filter is present" do
it "calls super and filter_and" do
skip "Add a test"
end
end
end


describe "#report" do
before {
allow(subject).to receive(:run)

allow(subject).to receive(:timestamp_first).and_return "first time"
allow(subject).to receive(:timestamp_last).and_return "last time"
allow(subject).to receive(:fixity_check_passed_id).and_return ["crocus", "daffodil", "snowdrop"]
allow(subject).to receive(:fixity_check_failed_id).and_return ["maple", "butterscotch", "caramel", "molasses"]

allow(subject).to receive(:puts).with("timestamp_first = first time")
allow(subject).to receive(:puts).with("timestamp_last = last time")
allow(subject).to receive(:puts).with("fixity_check_passed_count = 3")
allow(subject).to receive(:puts).with("fixity_check_failed_count = 4")
}
it "calls run and calls puts four times" do
expect(subject).to receive(:run)
expect(subject).to receive(:puts).with("timestamp_first = first time")
expect(subject).to receive(:puts).with("timestamp_last = last time")
expect(subject).to receive(:puts).with("fixity_check_passed_count = 3")
expect(subject).to receive(:puts).with("fixity_check_failed_count = 4")
subject.report
end
end


# protected methods

describe "#initialize_report_values" do
it "calls super and sets instance variables" do
subject.send(:initialize_report_values)

#testing super method
subject.instance_variable_get(:@lines_reported) == 0
subject.instance_variable_get(:@timestamp_first).blank?
subject.instance_variable_get(:@timestamp_last).blank?
subject.instance_variable_get(:@events).empty?
subject.instance_variable_get(:@class_events).empty?
subject.instance_variable_get(:@ids).empty?

subject.instance_variable_get(:@fixity_check_failed_id).empty?
subject.instance_variable_get(:@fixity_check_passed_id).empty?
end
end


describe "#line_read" do
before {
subject.instance_variable_set(:@lines_reported, 13)
subject.instance_variable_set(:@timestamp_first, "earlier stamp time")
subject.instance_variable_set(:@ids, {})
subject.instance_variable_set(:@events, {"event" => 3})
subject.instance_variable_set(:@class_events, {"class event key" => 7})
allow(subject).to receive(:class_event_key).with(class_name: "classy name", event: "event").and_return "class event key"
subject.instance_variable_set(:@fixity_check_failed_id, ["once ID"])
subject.instance_variable_set(:@fixity_check_passed_id, ["old ID"])
}

context "on success" do
it "sets and updates instance variables including @fixity_check_passed_id" do
#testing super method
subject.instance_variable_get(:@lines_reported) == 14
subject.instance_variable_get(:@timestamp_first) == "earlier stamp time"
subject.instance_variable_get(:@timestamp_last) == "time to stamp"
subject.instance_variable_get(:@ids)["ID"] == true
subject.instance_variable_get(:@events)["event"] == 4
subject.instance_variable_get(:@class_events)["class event key"] == 8

subject.instance_variable_get(:@fixity_check_passed_id) == ["old ID","ID"]

subject.send(:line_read, "line", "time to stamp", "event", "success", "classy name", "ID", "raw key values")
end
end

context "when not success" do
it "sets and updates instance variables including @fixity_check_failed_id" do
#testing super method
subject.instance_variable_get(:@lines_reported) == 14
subject.instance_variable_get(:@timestamp_first) == "earlier stamp time"
subject.instance_variable_get(:@timestamp_last) == "time to stamp"
subject.instance_variable_get(:@ids)["ID"] == true
subject.instance_variable_get(:@events)["event"] == 4
subject.instance_variable_get(:@class_events)["class event key"] == 8

subject.instance_variable_get(:@fixity_check_failed_id) == ["once ID","ID"]

subject.send(:line_read, "line", "time to stamp", "event", "event note", "classy name", "ID", "raw key values")
end
end
end
end
90 changes: 88 additions & 2 deletions spec/services/deepblue/log_exporter_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@ class OutputMock
def puts (text)
text
end

def flush
end

def close
end
end

RSpec.describe Deepblue::LogExporter do
Expand Down Expand Up @@ -48,12 +54,14 @@ def puts (text)
end

context "when pp_export is equivalent to false" do
mockoutput = OutputMock.new
before {
allow(subject).to receive(:pp_export).and_return false
subject.instance_variable_set(:@output, mockoutput)
}
it "calls @output.puts" do
expect(subject.export_line"line", "timestamp", "event", "event_note", "class_name", "id", "raw")
.to eq "line"
expect(mockoutput).to receive(:puts).with "line"
subject.export_line "line", "timestamp", "event", "event_note", "class_name", "id", "raw"
end
end
end
Expand Down Expand Up @@ -149,4 +157,82 @@ def puts (text)
end
end


# protected methods

describe "#log_close_output" do
context "when @output_close is false" do
it "returns nil" do
expect(subject.send(:log_close_output)).to be_blank
end
end

context "when @output_close is true" do
out_put = OutputMock.new
before {
subject.instance_variable_set(:@output_close, true)
}

context "when @output is nil" do
before {
subject.instance_variable_set(:@output, nil)
}
it "nothing happens" do
expect(out_put).not_to receive(:flush)
expect(out_put).not_to receive(:close)
subject.send(:log_close_output)
end
end
context "when @output is not nil" do
before {
subject.instance_variable_set(:@output, out_put)
}
it "calls flush and close on @output" do
expect(out_put).to receive(:flush)
expect(out_put).to receive(:close)
subject.send(:log_close_output)
end
end
end
end


describe "#log_open_output" do
before {
allow(subject).to receive(:output_mode).and_return "output mode"
}

context "when @output is a string" do
before {
subject.instance_variable_set(:@output, "things")
allow(Pathname).to receive(:new).with("things").and_return "string output pathname"
allow(subject).to receive(:open).with("string output pathname", "output mode").and_return "string output"
}
it "creates Pathname from string" do
subject.send(:log_open_output)

expect(subject.instance_variable_get(:@output_pathname)).to eq "string output pathname"
expect(subject.instance_variable_get(:@output)).to eq "string output"
end
end

context "when @output is a Pathname" do
path_name = Pathname.new("path name")
before {
subject.instance_variable_set(:@output, path_name)
allow(subject).to receive(:open).with(path_name, "output mode").and_return "pathname output"
}
it "uses Pathname" do
subject.send(:log_open_output)

expect(subject.instance_variable_get(:@output_pathname)).to eq path_name
expect(subject.instance_variable_get(:@output)).to eq "pathname output"
end
end

after {
expect(subject.instance_variable_get(:@output_close)).to eq true
}
end

end
Loading