From 3d59f09fccbcc74722e02b0992116d264f581b3a Mon Sep 17 00:00:00 2001 From: wkdewey Date: Fri, 20 Sep 2024 16:47:37 -0500 Subject: [PATCH] update tests to match new schema --- test/csv_to_es_test.rb | 12 +++++++----- test/helpers_test.rb | 2 +- test/html_to_es_test.rb | 2 +- test/tei_to_es_test.rb | 35 ++++++++++++++++++----------------- test/test_helper.rb | 3 ++- test/vra_to_es_test.rb | 6 +++--- test/webs_to_es_test.rb | 2 +- 7 files changed, 33 insertions(+), 29 deletions(-) diff --git a/test/csv_to_es_test.rb b/test/csv_to_es_test.rb index ba4cd35db..6f3d93d03 100644 --- a/test/csv_to_es_test.rb +++ b/test/csv_to_es_test.rb @@ -4,26 +4,28 @@ class CsvToEsTest < Minitest::Test def setup path = File.join($fixture_path, "csv", "testing.csv") - csv = CSV.read(path, headers: true) - + csv = CSV.read(path, **{ + encoding: "utf-8", + headers: true, + }) + $options["api_version"] = "2.0" @test1 = CsvToEs.new(csv[0], $options, csv) @test2 = CsvToEs.new(csv[1], $options, csv) end def test_assemble_json json = @test1.assemble_json - assert_equal 42, json.length + assert_equal 58, json.length assert_equal "test.001", json["identifier"] json = @test2.assemble_json - assert_equal 42, json.length + assert_equal 58, json.length assert_equal "test.002", json["identifier"] end def test_csv_to_es_fields json = @test1.assemble_json assert_equal "1887-01-01", json["date"] - contributors = [{"name"=>"Jessica Dussault"}, {"name"=>"Greg Tunink"}, {"name"=>"Karin Dalziel"}] assert_equal contributors, json["contributor"] diff --git a/test/helpers_test.rb b/test/helpers_test.rb index 88d740ecf..0fa3ca13f 100644 --- a/test/helpers_test.rb +++ b/test/helpers_test.rb @@ -35,7 +35,7 @@ def test_date_standardize def test_get_directory_files # real directory files = Datura::Helpers.get_directory_files("#{File.dirname(__FILE__)}/fixtures") - assert_equal 6, files.length + assert_equal 7, files.length # not a real directory files = Datura::Helpers.get_directory_files("/fake") diff --git a/test/html_to_es_test.rb b/test/html_to_es_test.rb index e0f5b9281..d15dff342 100644 --- a/test/html_to_es_test.rb +++ b/test/html_to_es_test.rb @@ -7,7 +7,7 @@ def setup def test_assemble_json json = @test.assemble_json - assert_equal 42, json.length + assert_equal 58, json.length assert_equal "testing", json["identifier"] end diff --git a/test/tei_to_es_test.rb b/test/tei_to_es_test.rb index 19d59c9d1..bc510963a 100644 --- a/test/tei_to_es_test.rb +++ b/test/tei_to_es_test.rb @@ -10,7 +10,7 @@ def setup def test_assemble_json json = @neihardt.assemble_json - assert_equal 42, json.length + assert_equal 58, json.length assert_equal "nei.j4c.12.52", json["identifier"] end @@ -26,11 +26,11 @@ def test_fields creator = [{"name"=>"Neihardt, John Gneisenau, 1881-1973"}] assert_equal creator, neihardt["creator"] - contributor = [{"id"=>"lkw", "name"=>"Weakly, Laura K.", "role"=>""}, - {"id"=>"swa", "name"=>"Adrales, Samantha W.", "role"=>""}, - {"id"=>"az", "name"=>"Zeljkovic, Arman", "role"=>""}, - {"id"=>"ep", "name"=>"Pedigo, Erin", "role"=>""}, - {"id"=>"", "name"=>"Gossin, Pamela", "role"=>""} + contributor = [{"id"=>"lkw", "name"=>"Weakly, Laura K.", "role"=>nil}, + {"id"=>"swa", "name"=>"Adrales, Samantha W.", "role"=>nil}, + {"id"=>"az", "name"=>"Zeljkovic, Arman", "role"=>nil}, + {"id"=>"ep", "name"=>"Pedigo, Erin", "role"=>nil}, + {"id"=>nil, "name"=>"Gossin, Pamela", "role"=>nil} ] assert_equal contributor, neihardt["contributor"] @@ -40,18 +40,19 @@ def test_fields assert_equal "late 1865 (?)", whitman["date_display"] assert_equal "1865-12-31", whitman["date_not_after"] assert_equal "1865-07-01", whitman["date_not_before"] - # source - source = "Track and stable talk, Aberdeen, South Dakota, 1888-02-24" - assert_equal source, cody["source"] - - source = "Neihardt, John Gneisenau, 1881-1973, Letter from John G. Neihardt to Julius T. House, 1927-11-05" - assert_equal source, neihardt["source"] - - # NOTE: this document does have publisher information in the biblStruct and will - # need to override the default xpaths to obtain that information for the source field - source = "Walt Whitman, Walt Whitman to a Soldier, late 1865 (?)" - assert_equal source, whitman["source"] + # note that source has been replaced by has_source + # TeiToES at this point does not define default behavior for this field + # source = "Track and stable talk, Aberdeen, South Dakota, 1888-02-24" + # assert_equal source, cody["has_source"] + + # source = "Neihardt, John Gneisenau, 1881-1973, Letter from John G. Neihardt to Julius T. House, 1927-11-05" + # assert_equal source, neihardt["has_source"] + + # # NOTE: this document does have publisher information in the biblStruct and will + # # need to override the default xpaths to obtain that information for the source field + # source = "Walt Whitman, Walt Whitman to a Soldier, late 1865 (?)" + # assert_equal source, whitman["has_source"] end end diff --git a/test/test_helper.rb b/test/test_helper.rb index 77226fc69..85e0db7ba 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -7,7 +7,8 @@ "collection" => "test_collection", "data_base" => "cdrhtest.unl.edu/media", "environment" => "test", - "site_url" => "cdrhtest.unl.edu" + "site_url" => "cdrhtest.unl.edu", + "api_version" => "2.0" } current_dir = File.expand_path(File.dirname(__FILE__)) diff --git a/test/vra_to_es_test.rb b/test/vra_to_es_test.rb index 60b56f23a..1b815af5e 100644 --- a/test/vra_to_es_test.rb +++ b/test/vra_to_es_test.rb @@ -7,7 +7,7 @@ def setup def test_assemble_json json = @cody.assemble_json - assert_equal 42, json.length + assert_equal 58, json.length assert_equal "wfc.img.pho.69.236.82", json["identifier"] end @@ -22,8 +22,8 @@ def test_vra_to_es_fields assert_equal keywords, json["keywords"] people = [ - {id: nil, name: "Käsebier, Gertrude, 1852-1934", role: "photographer"}, - {id: nil, name: "Spotted Horse, Willie", role: nil} + {"id" => nil, "name" => "Käsebier, Gertrude, 1852-1934", "role" => "photographer"}, + {"id" => nil, "name" => "Spotted Horse, Willie", "role" => nil} ] assert_equal people, json["person"] end diff --git a/test/webs_to_es_test.rb b/test/webs_to_es_test.rb index 44d48d35e..2bd576bdf 100644 --- a/test/webs_to_es_test.rb +++ b/test/webs_to_es_test.rb @@ -7,7 +7,7 @@ def setup def test_assemble_json json = @test.assemble_json - assert_equal 42, json.length + assert_equal 58, json.length assert_equal "testing", json["identifier"] end