Permalink
Browse files

Added mocking of calls to Wikidata

  • Loading branch information...
1 parent d951616 commit 2f833c992f881a263be15f2c99e00a751b90c52e @njh committed Dec 23, 2012
View
@@ -236,6 +236,11 @@ def app
:content_type => 'application/json'
)
FakeWeb.register_uri(
+ :get, 'http://wikidata.org/w/api.php?action=wbgetentities&format=json&languages=en&props=info%7Caliases%7Clabels%7Cdescriptions&sites=enwiki&titles=Ceres,%20Fife',
+ :body => fixture_data('wbgetentities-ceres.json'),
+ :content_type => 'application/json'
+ )
+ FakeWeb.register_uri(
:get, %r[http://api.freebase.com/api/service/mqlread],
:body => fixture_data('freebase-mqlread-934787.json'),
:content_type => 'application/json'
@@ -503,6 +508,11 @@ def app
:content_type => 'application/json'
)
FakeWeb.register_uri(
+ :get, 'http://wikidata.org/w/api.php?action=wbgetentities&format=json&languages=en&props=info%7Caliases%7Clabels%7Cdescriptions&sites=enwiki&titles=IMac',
+ :body => fixture_data('wbgetentities-imac.json'),
+ :content_type => 'application/json'
+ )
+ FakeWeb.register_uri(
:get, %r[http://api.freebase.com/api/service/mqlread],
:body => fixture_data('freebase-mqlread-21492980.json'),
:content_type => 'application/json'
@@ -567,14 +577,19 @@ def app
end
end
- context "GETing an HTML thing for something that doesn't exist in Freebase" do
+ context "GETing an HTML thing for something that doesn't exist in Freebase or Wikidata" do
before :each do
FakeWeb.register_uri(
:get, 'http://en.wikipedia.org/w/api.php?action=parse&format=json&pageid=2008435&prop=text%7Cdisplaytitle',
:body => fixture_data('parse-2008435.json'),
:content_type => 'application/json'
)
FakeWeb.register_uri(
+ :get, 'http://wikidata.org/w/api.php?action=wbgetentities&format=json&languages=en&props=info%7Caliases%7Clabels%7Cdescriptions&sites=enwiki&titles=IMAC',
+ :body => fixture_data('wbgetentities-notfound.json'),
+ :content_type => 'application/json'
+ )
+ FakeWeb.register_uri(
:get, %r[http://api.freebase.com/api/service/mqlread],
:body => fixture_data('freebase-mqlread-notfound.json'),
:content_type => 'application/json'
@@ -598,7 +613,8 @@ def app
end
it "should write an error message to stderr" do
- @stderr_buffer.string.should == "Error while reading from Freebase: Freebase query failed return no results\n"
+ @stderr_buffer.string.should == "Error while reading from Freebase: Freebase query failed return no results\n"+
+ "Error while reading from Wikidata: Failed to lookup title in Wikidata\n"
end
end
@@ -0,0 +1 @@
+{"entities":{"q33980":{"pageid":36785,"ns":0,"title":"Q33980","lastrevid":508443,"modified":"2012-11-21T06:09:20Z","id":"q33980","type":"item","labels":{"en":{"language":"en","value":"Ceres"}},"descriptions":{"en":{"language":"en","value":"Ceres is a village in Fife, Scotland."}}}},"success":1}
@@ -0,0 +1 @@
+{"entities":{"q14091":{"pageid":16078,"ns":0,"title":"Q14091","lastrevid":2149527,"modified":"2012-12-22T22:42:51Z","id":"q14091","type":"item","labels":{"en":{"language":"en","value":"iMac"}},"descriptions":{"en":{"language":"en","value":"All-in-one desktop computer designed and built by Apple Inc."}}}},"success":1}
@@ -0,0 +1 @@
+{"entities":{"-1":{"site":"enwiki","title":"notfound","missing":""}},"success":1}
View
@@ -235,11 +235,24 @@
'mid' => '/m/0dw4g',
'name' => 'U2',
})
+ WikidataApi.expects(:find_by_title).once.returns({
+ 'id' => 'q396',
+ 'title'=> 'Q396',
+ 'pageid' => 602,
+ 'labels' => {'en' => {'language' => 'en', 'value' => 'U2'}},
+ 'descriptions' =>
+ {'en' =>
+ {'language' => 'en', 'value' => 'Irish rock band from Dublin formed in 1976'}},
+ 'lastrevid' => 1416446,
+ 'ns' => 0,
+ 'type' => 'item',
+ 'modified' => '2012-12-13T08:20:29Z',
+ })
WikipediaApi.expects(:parse).never
@thing = Thing.new(52780,
:title => 'U2',
:displaytitle => 'U2',
- :abstract => "U2 are an Irish rock band.",
+ :abstract => 'U2 are an Irish rock band.',
:updated_at => DateTime.parse('2010-05-08T17:20:04Z')
)
@graph = @thing.to_rdf
@@ -249,8 +262,8 @@
@graph.class.should == RDF::Graph
end
- it "should return a graph with 11 triples" do
- @graph.count.should == 11
+ it "should return a graph with 15 triples" do
+ @graph.count.should == 15
end
it "should include an rdf:type triple for the thing" do
@@ -293,6 +306,14 @@
])
end
+ it "should include a foaf:page triple for Wikidata page" do
+ @graph.should have_triple([
+ RDF::URI("http://dbpedialite.org/things/52780#id"),
+ RDF::FOAF.page,
+ RDF::URI('http://wikidata.org/wiki/Q396')
+ ])
+ end
+
it "should include a owl:sameAs triple for the FreeBase Machine ID" do
@graph.should have_triple([
RDF::URI("http://dbpedialite.org/things/52780#id"),

0 comments on commit 2f833c9

Please sign in to comment.