Skip to content

Commit

Permalink
Flatten the VCR cassette structure
Browse files Browse the repository at this point in the history
  • Loading branch information
mbklein committed May 11, 2020
1 parent cb08447 commit 882837f
Show file tree
Hide file tree
Showing 8 changed files with 117 additions and 124 deletions.
27 changes: 10 additions & 17 deletions test/authoritex/lcnaf_test.exs
Original file line number Diff line number Diff line change
@@ -1,18 +1,9 @@
defmodule Authoritex.LCNAFTest do
use ExUnit.Case
use ExUnit.Case, async: true
use ExVCR.Mock, adapter: ExVCR.Adapter.Hackney

alias Authoritex.LCNAF

setup do
ExVCR.Config.cassette_library_dir(
"test/fixtures/vcr_cassettes/lcnaf",
"test/fixtures/custom_cassettes/lcnaf"
)

:ok
end

test "can_resolve?/1" do
assert LCNAF.can_resolve?("http://id.loc.gov/authorities/names/no2011087251")
assert LCNAF.can_resolve?("info:lc/authorities/names/no2011087251")
Expand All @@ -29,7 +20,7 @@ defmodule Authoritex.LCNAFTest do

describe "fetch/1" do
test "success" do
use_cassette "fetch_success" do
use_cassette "lcnaf_fetch_success" do
assert LCNAF.fetch("http://id.loc.gov/authorities/names/no2011087251") ==
{:ok, "Valim, Jose"}

Expand All @@ -39,14 +30,15 @@ defmodule Authoritex.LCNAFTest do
end

test "failure" do
use_cassette "fetch_failure" do
use_cassette "lcnaf_fetch_failure" do
assert LCNAF.fetch("http://id.loc.gov/authorities/names/wrong-id") ==
{:error, 404}
end
end

test "error" do
use_cassette "500", custom: true do
use_cassette "lcnaf_500",
custom: true do
assert LCNAF.fetch("http://id.loc.gov/authorities/names/no2011087251") ==
{:error, 500}
end
Expand All @@ -55,26 +47,27 @@ defmodule Authoritex.LCNAFTest do

describe "search/2" do
test "results" do
use_cassette "search_results" do
use_cassette "lcnaf_search_results" do
{:ok, results} = LCNAF.search("smith")
assert length(results) == 30
assert %{id: _id, label: _label} = List.first(results)
end

use_cassette "search_results_max" do
use_cassette "lcnaf_search_results_max" do
{:ok, results} = LCNAF.search("smith", 50)
assert length(results) == 50
end
end

test "no results" do
use_cassette "search_results_empty" do
use_cassette "lcnaf_search_results_empty" do
assert {:ok, []} = LCNAF.search("NO_resulteeeees")
end
end

test "error" do
use_cassette "500", custom: true do
use_cassette "lcnaf_500",
custom: true do
assert LCNAF.search("smith") ==
{:error, 500}
end
Expand Down
26 changes: 8 additions & 18 deletions test/authoritex_test.exs
Original file line number Diff line number Diff line change
@@ -1,20 +1,10 @@
defmodule AuthoritexTest do
use ExUnit.Case

use ExUnit.Case, async: true
use ExVCR.Mock, adapter: ExVCR.Adapter.Hackney

setup do
ExVCR.Config.cassette_library_dir(
"test/fixtures/vcr_cassettes/lcnaf",
"test/fixtures/custom_cassettes/lcnaf"
)

:ok
end

describe "fetch/1" do
test "success" do
use_cassette "fetch_success" do
use_cassette "lcnaf_fetch_success" do
assert Authoritex.fetch("http://id.loc.gov/authorities/names/no2011087251") ==
{:ok, "Valim, Jose"}

Expand All @@ -24,14 +14,14 @@ defmodule AuthoritexTest do
end

test "failure" do
use_cassette "fetch_failure" do
use_cassette "lcnaf_fetch_failure" do
assert Authoritex.fetch("http://id.loc.gov/authorities/names/wrong-id") ==
{:error, 404}
end
end

test "error" do
use_cassette "500", custom: true do
use_cassette "lcnaf_500", custom: true do
assert Authoritex.fetch("http://id.loc.gov/authorities/names/no2011087251") ==
{:error, 500}
end
Expand All @@ -40,20 +30,20 @@ defmodule AuthoritexTest do

describe "search/2" do
test "results" do
use_cassette "search_results" do
use_cassette "lcnaf_search_results" do
{:ok, results} = Authoritex.search("lcnaf", "smith")
assert length(results) == 30
assert %{id: _id, label: _label} = List.first(results)
end

use_cassette "search_results_max" do
use_cassette "lcnaf_search_results_max" do
{:ok, results} = Authoritex.search("lcnaf", "smith", 50)
assert length(results) == 50
end
end

test "no results" do
use_cassette "search_results_empty" do
use_cassette "lcnaf_search_results_empty" do
assert {:ok, []} = Authoritex.search("lcnaf", "NO_resulteeeees")
end
end
Expand All @@ -66,7 +56,7 @@ defmodule AuthoritexTest do
end

test "error" do
use_cassette "500", custom: true do
use_cassette "lcnaf_500", custom: true do
assert Authoritex.search("lcnaf", "smith") ==
{:error, 500}
end
Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -4,34 +4,36 @@
"body": "",
"headers": [],
"method": "get",
"options": [],
"options": {
"proxy": "http://127.0.0.1:8000"
},
"request_body": "",
"url": "http://id.loc.gov/authorities/names/no2011087251.rdf"
},
"response": {
"binary": false,
"body": "<rdf:RDF xmlns:rdf=\"http://www.w3.org/1999/02/22-rdf-syntax-ns#\">\n <madsrdf:PersonalName rdf:about=\"http://id.loc.gov/authorities/names/no2011087251\" xmlns:madsrdf=\"http://www.loc.gov/mads/rdf/v1#\">\n <rdf:type rdf:resource=\"http://www.loc.gov/mads/rdf/v1#Authority\"/>\n <madsrdf:authoritativeLabel>Valim, Jose</madsrdf:authoritativeLabel>\n <madsrdf:elementList rdf:parseType=\"Collection\">\n <madsrdf:FullNameElement>\n\t<madsrdf:elementValue>Valim, Jose</madsrdf:elementValue>\n </madsrdf:FullNameElement>\n </madsrdf:elementList>\n <madsrdf:isMemberOfMADSCollection rdf:resource=\"http://id.loc.gov/authorities/names/collection_NamesAuthorizedHeadings\"/>\n <madsrdf:isMemberOfMADSCollection rdf:resource=\"http://id.loc.gov/authorities/names/collection_LCNAF\"/>\n <madsrdf:hasExactExternalAuthority rdf:resource=\"http://viaf.org/viaf/sourceID/LC%7Cno2011087251#skos:Concept\"/>\n <madsrdf:identifiesRWO>\n <madsrdf:RWO rdf:about=\"http://id.loc.gov/rwo/agents/no2011087251\">\n\t<rdf:type rdf:resource=\"http://id.loc.gov/ontologies/bibframe/Person\"/>\n\t<rdf:type rdf:resource=\"http://xmlns.com/foaf/0.1/Person\"/>\n\t<rdfs:label xmlns:rdfs=\"http://www.w3.org/2000/01/rdf-schema#\">Valim, Jose</rdfs:label>\n\t<bflc:contributorTo xmlns:bflc=\"http://id.loc.gov/ontologies/bflc/\">\n\t <bf:Work rdf:about=\"http://id.loc.gov/resources/works/17032688\" xmlns:bf=\"http://id.loc.gov/ontologies/bibframe/\">\n\t <bflc:aap>Valim, Jose. Crafting rails applications :</bflc:aap>\n\t </bf:Work>\n\t</bflc:contributorTo>\n </madsrdf:RWO>\n </madsrdf:identifiesRWO>\n <madsrdf:isMemberOfMADSScheme rdf:resource=\"http://id.loc.gov/authorities/names\"/>\n <identifiers:lccn xmlns:identifiers=\"http://id.loc.gov/vocabulary/identifiers/\">no2011087251</identifiers:lccn>\n <identifiers:local xmlns:identifiers=\"http://id.loc.gov/vocabulary/identifiers/\">(OCoLC)oca08877947</identifiers:local>\n <madsrdf:hasSource>\n <madsrdf:Source>\n\t<madsrdf:citation-source>Crafting Rails applications, c2011:</madsrdf:citation-source>\n\t<madsrdf:citation-note>t.p. (Jose Valim)</madsrdf:citation-note>\n\t<madsrdf:citation-status>found</madsrdf:citation-status>\n </madsrdf:Source>\n </madsrdf:hasSource>\n <madsrdf:adminMetadata>\n <ri:RecordInfo xmlns:ri=\"http://id.loc.gov/ontologies/RecordInfo#\">\n\t<ri:recordChangeDate rdf:datatype=\"http://www.w3.org/2001/XMLSchema#dateTime\">2011-06-06T00:00:00</ri:recordChangeDate>\n\t<ri:recordStatus rdf:datatype=\"http://www.w3.org/2001/XMLSchema#string\">new</ri:recordStatus>\n\t<ri:recordContentSource rdf:resource=\"http://id.loc.gov/vocabulary/organizations/oco\"/>\n\t<ri:languageOfCataloging rdf:resource=\"http://id.loc.gov/vocabulary/iso639-2/eng\"/>\n </ri:RecordInfo>\n </madsrdf:adminMetadata>\n <madsrdf:adminMetadata>\n <ri:RecordInfo xmlns:ri=\"http://id.loc.gov/ontologies/RecordInfo#\">\n\t<ri:recordChangeDate rdf:datatype=\"http://www.w3.org/2001/XMLSchema#dateTime\">2011-06-07T06:21:47</ri:recordChangeDate>\n\t<ri:recordStatus rdf:datatype=\"http://www.w3.org/2001/XMLSchema#string\">revised</ri:recordStatus>\n\t<ri:recordContentSource rdf:resource=\"http://id.loc.gov/vocabulary/organizations/oco\"/>\n\t<ri:languageOfCataloging rdf:resource=\"http://id.loc.gov/vocabulary/iso639-2/eng\"/>\n </ri:RecordInfo>\n </madsrdf:adminMetadata>\n <rdf:type rdf:resource=\"http://www.w3.org/2004/02/skos/core#Concept\"/>\n <skos:prefLabel xmlns:skos=\"http://www.w3.org/2004/02/skos/core#\">Valim, Jose</skos:prefLabel>\n <skos:exactMatch rdf:resource=\"http://viaf.org/viaf/sourceID/LC%7Cno2011087251#skos:Concept\" xmlns:skos=\"http://www.w3.org/2004/02/skos/core#\"/>\n <skos:inScheme rdf:resource=\"http://id.loc.gov/authorities/names\" xmlns:skos=\"http://www.w3.org/2004/02/skos/core#\"/>\n <skos:changeNote xmlns:skos=\"http://www.w3.org/2004/02/skos/core#\">\n <cs:ChangeSet xmlns:cs=\"http://purl.org/vocab/changeset/schema#\">\n\t<cs:subjectOfChange rdf:resource=\"http://id.loc.gov/authorities/names/no2011087251\"/>\n\t<cs:creatorName rdf:resource=\"http://id.loc.gov/vocabulary/organizations/oco\"/>\n\t<cs:createdDate rdf:datatype=\"http://www.w3.org/2001/XMLSchema#dateTime\">2011-06-06T00:00:00</cs:createdDate>\n\t<cs:changeReason rdf:datatype=\"http://www.w3.org/2001/XMLSchema#string\">new</cs:changeReason>\n </cs:ChangeSet>\n </skos:changeNote>\n <skos:changeNote xmlns:skos=\"http://www.w3.org/2004/02/skos/core#\">\n <cs:ChangeSet xmlns:cs=\"http://purl.org/vocab/changeset/schema#\">\n\t<cs:subjectOfChange rdf:resource=\"http://id.loc.gov/authorities/names/no2011087251\"/>\n\t<cs:creatorName rdf:resource=\"http://id.loc.gov/vocabulary/organizations/oco\"/>\n\t<cs:createdDate rdf:datatype=\"http://www.w3.org/2001/XMLSchema#dateTime\">2011-06-07T06:21:47</cs:createdDate>\n\t<cs:changeReason rdf:datatype=\"http://www.w3.org/2001/XMLSchema#string\">revised</cs:changeReason>\n </cs:ChangeSet>\n </skos:changeNote>\n </madsrdf:PersonalName>\n</rdf:RDF>\n",
"headers": {
"Date": "Mon, 11 May 2020 19:52:41 GMT",
"Content-Type": "application/rdf+xml; charset=UTF-8",
"Content-Length": "4907",
"Connection": "keep-alive",
"Set-Cookie": "__cfduid=d9df5410ca5bd8550cbcb11e86781c9931589226761; expires=Wed, 10-Jun-20 19:52:41 GMT; path=/; domain=.loc.gov; HttpOnly; SameSite=Lax",
"X-RWO-URI": "http://id.loc.gov/rwo/agents/no2011087251",
"ETag": "4e8d8eb3f55d0911a9162daeb11be049",
"X-URI": "http://id.loc.gov/authorities/names/no2011087251",
"date": "Mon, 11 May 2020 20:40:29 GMT",
"content-type": "application/rdf+xml; charset=UTF-8",
"content-length": "4907",
"connection": "keep-alive",
"set-cookie": "__cfduid=dc5de0168f308640069c39d18b7935e9a1589229629; expires=Wed, 10-Jun-20 20:40:29 GMT; path=/; domain=.loc.gov; HttpOnly; SameSite=Lax",
"x-rwo-uri": "http://id.loc.gov/rwo/agents/no2011087251",
"etag": "4e8d8eb3f55d0911a9162daeb11be049",
"x-uri": "http://id.loc.gov/authorities/names/no2011087251",
"cache-control": "public, max-age=2419200",
"X-Varnish": "453145580 445456501",
"Age": "261871",
"Via": "1.1 varnish-v4",
"Access-Control-Allow-Origin": "*",
"Access-Control-Allow-Methods": "HEAD, POST, GET, OPTIONS",
"Access-Control-Allow-Headers": "Content-Type, Access-Control-Allow-Headers, Authorization, X-Requested-With",
"Accept-Ranges": "bytes",
"CF-Cache-Status": "DYNAMIC",
"Server": "cloudflare",
"CF-RAY": "591e711c6db9f23a-ORD",
"cf-request-id": "02a6e505bd0000f23adc99a200000001"
"x-varnish": "456889795 445456501",
"age": "264740",
"via": "1.1 varnish-v4",
"access-control-allow-origin": "*",
"access-control-allow-methods": "HEAD, POST, GET, OPTIONS",
"access-control-allow-headers": "Content-Type, Access-Control-Allow-Headers, Authorization, X-Requested-With",
"accept-ranges": "bytes",
"cf-cache-status": "DYNAMIC",
"server": "cloudflare",
"cf-ray": "591eb7221c287f94-ORD",
"cf-request-id": "02a710c94c00007f947037d200000001"
},
"status_code": 200,
"type": "ok"
Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -6,31 +6,33 @@
"User-Agent": "Authoritex"
},
"method": "get",
"options": [],
"options": {
"proxy": "http://127.0.0.1:8000"
},
"request_body": "",
"url": "http://id.loc.gov/search/?q=NO_resulteeeees&q=scheme%3Ahttp%3A%2F%2Fid.loc.gov%2Fauthorities%2Fnames&count=30&format=xml%2Batom"
},
"response": {
"binary": false,
"body": "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<feed xmlns=\"http://www.w3.org/2005/Atom\">\n<title>Library of Congress Authorities and Vocabulary Service: Search Results</title><link href=\"http://id.loc.gov/search/?q=NO_resulteeeees scheme:http://id.loc.gov/authorities/names&amp;start=1&amp;format=atom\" rel=\"self\"/><id>info:lc/search/?q=NO_resulteeeees+scheme:http://id.loc.gov/authorities/names</id><updated>2020-05-11T15:48:28.393794-04:00</updated><opensearch:totalResults xmlns:opensearch=\"http://a9.com/-/spec/opensearch/1.1/\">0</opensearch:totalResults><opensearch:startIndex xmlns:opensearch=\"http://a9.com/-/spec/opensearch/1.1/\">1</opensearch:startIndex><opensearch:itemsPerPage xmlns:opensearch=\"http://a9.com/-/spec/opensearch/1.1/\">30</opensearch:itemsPerPage>\n</feed>\n",
"headers": {
"Date": "Mon, 11 May 2020 19:52:40 GMT",
"Content-Type": "application/atom+xml; charset=UTF-8",
"Content-Length": "773",
"Connection": "keep-alive",
"Set-Cookie": "__cfduid=d5cbc0208c81adf88ca1bdd7cb408ae5f1589226760; expires=Wed, 10-Jun-20 19:52:40 GMT; path=/; domain=.loc.gov; HttpOnly; SameSite=Lax",
"date": "Mon, 11 May 2020 20:40:30 GMT",
"content-type": "application/atom+xml; charset=UTF-8",
"content-length": "773",
"connection": "keep-alive",
"set-cookie": "__cfduid=d32278b966e74ba55cfa0d060738708d11589229630; expires=Wed, 10-Jun-20 20:40:30 GMT; path=/; domain=.loc.gov; HttpOnly; SameSite=Lax",
"cache-control": "public, max-age=2419200",
"X-Varnish": "465462097 465993753",
"Age": "251",
"Via": "1.1 varnish-v4",
"Access-Control-Allow-Origin": "*",
"Access-Control-Allow-Methods": "HEAD, POST, GET, OPTIONS",
"Access-Control-Allow-Headers": "Content-Type, Access-Control-Allow-Headers, Authorization, X-Requested-With",
"Accept-Ranges": "bytes",
"CF-Cache-Status": "DYNAMIC",
"Server": "cloudflare",
"CF-RAY": "591e71162d5bf23a-ORD",
"cf-request-id": "02a6e501d80000f23adc943200000001"
"x-varnish": "465769205 465993753",
"age": "3122",
"via": "1.1 varnish-v4",
"access-control-allow-origin": "*",
"access-control-allow-methods": "HEAD, POST, GET, OPTIONS",
"access-control-allow-headers": "Content-Type, Access-Control-Allow-Headers, Authorization, X-Requested-With",
"accept-ranges": "bytes",
"cf-cache-status": "DYNAMIC",
"server": "cloudflare",
"cf-ray": "591eb7290ee77f94-ORD",
"cf-request-id": "02a710cda800007f94703cf200000001"
},
"status_code": 200,
"type": "ok"
Expand Down

Large diffs are not rendered by default.

0 comments on commit 882837f

Please sign in to comment.