Permalink
Browse files

Added get_news (currently pending due to unavilable service). Fixed u…

…p unit test generator
  • Loading branch information...
gingerhendrix committed Jul 11, 2009
1 parent b86f1ed commit 6547d04a640728b4ab186c0f3726522e0fab73ab
View
7 TODO
@@ -33,7 +33,12 @@
Create fixture +done
Write unit tests +done
Write model +done
- get_news
+ @iteration get_news +done
+ Run resource generator +done
+ Write acceptance tests +done
+ Create fixture +done
+ Write unit tests +done
+ Write model +done
get_profile
get_reviews
get_similar
@@ -0,0 +1,8 @@
+Feature: Artist news
+ In order to find news about an an artist
+ A user should be able to retrieve news for an artist
+
+ Scenario: Artist news
+ When I retrieve the news for "music://id.echonest.com/~/AR/ARVVZQP11E2835DBCB"
+ Then I should get some news results
+
@@ -71,3 +71,20 @@
end
+When /^I retrieve the news for "([^\"]*)"$/ do |arg1|
+ @artist = Artist.new id
+ pending("Service unavailable") do
+ @news = @artist.get_news
+ end
+end
+
+Then /^I should get some news results$/ do
+ @news.should_not be_nil
+ @news.should be_kind_of(NewsResult)
+ @news.results.docs.should be_kind_of(Array)
+ @news.results.docs.length.should > 0
+ @news.results.docs[0].should be_kind_of(NewsDoc)
+ @news.results.docs[0].url.should_not be_nil
+end
+
+
@@ -5,7 +5,7 @@ describe "<%=name.capitalize%>Result" do
describe "#parse" do
before(:each) do
- @xml = File.read(File.dirname(__FILE__) + "/../fixtures/<%=name%>/wavves.xml")
+ @xml = File.read(File.dirname(__FILE__) + "/../fixtures/<%=name%>/radiohead.xml")
end
it "should parse xml" do
@@ -15,13 +15,13 @@ describe "<%=name.capitalize%>Result" do
it "should have artist" do
<%=name%> = EchoNest::<%=name.capitalize%>Result.parse(@xml)
<%=name%>.artist.should be_kind_of(EchoNest::Artist)
- <%=name%>.artist.name.should == "Wavves"
- <%=name%>.artist.id.should == "music://id.echonest.com/~/AR/ARVVZQP11E2835DBCB"
+ <%=name%>.artist.name.should == "Radiohead"
+ <%=name%>.artist.id.should == "music://id.echonest.com/~/AR/ARH6W4X1187B99274F"
end
it "should have results" do
<%=name%> = EchoNest::<%=name.capitalize%>Result.parse(@xml)
- <%=name%>.results.should be_kind_of(EchoNest::BlogResults)
+ <%=name%>.results.should be_kind_of(EchoNest::<%=name.capitalize%>Results)
#TODO: Fill in these values as found in fixture
<%=name%>.results.found.should == "51"
<%=name%>.results.shown.should == "15"
@@ -32,8 +32,8 @@ describe "<%=name.capitalize%>Result" do
describe "result" do
it "should be an <%=name.capitalize%>Doc" do
- <%=name%> = EchoNest::AudioResult.parse(@xml)
- doc = audio.results.docs[0]
+ <%=name%> = EchoNest::<%=name.capitalize%>Result.parse(@xml)
+ doc = <%=name%>.results.docs[0]
doc.should be_kind_of(EchoNest::<%=name.capitalize%>Doc)
#TODO: Create tests based on attributes in resource
end
View
@@ -24,3 +24,8 @@ def self.api_key
require "echonest/blog_result.rb"
require "echonest/familiarity_result.rb"
require "echonest/hotttnesss_result.rb"
+
+require "echonest/news_doc.rb"
+require "echonest/news_results.rb"
+require "echonest/news_result.rb"
+
View
@@ -31,6 +31,11 @@ def get_hotttnesss
request = ApiRequest.new("get_hotttnesss", {:id => id})
HotttnesssResult.parse request.fetch
end
+
+ def get_news
+ request = ApiRequest.new("get_news", {:id => id})
+ NewsResult.parse request.fetch
+ end
end
end
View
@@ -0,0 +1,13 @@
+
+module EchoNest
+ class NewsDoc
+ include HappyMapper
+
+ tag :doc
+
+ element :name, String
+ element :url, String
+ element :summary, String
+ element :date_found, String
+ end
+end
@@ -0,0 +1,12 @@
+
+module EchoNest
+ class NewsResult
+ include HappyMapper
+
+ tag :response
+
+ has_one :artist, Artist
+ has_one :results, NewsResults
+
+ end
+end
@@ -0,0 +1,15 @@
+
+module EchoNest
+ class NewsResults
+ include HappyMapper
+
+ tag :results
+
+ attribute :found, String
+ attribute :shown, String
+ attribute :start, String
+
+ has_many :docs, NewsDoc
+
+ end
+end
@@ -0,0 +1,49 @@
+require File.dirname(__FILE__) + '/../spec_helper'
+
+describe "NewsResult" do
+
+ describe "#parse" do
+
+ before(:each) do
+ @xml = File.read(File.dirname(__FILE__) + "/../fixtures/news/radiohead.xml")
+ end
+
+ it "should parse xml" do
+ EchoNest::NewsResult.parse(@xml)
+ end
+
+ it "should have artist" do
+ news = EchoNest::NewsResult.parse(@xml)
+ news.artist.should be_kind_of(EchoNest::Artist)
+ news.artist.name.should == "Radiohead"
+ news.artist.id.should == "music://id.echonest.com/~/AR/ARH6W4X1187B99274F"
+ end
+
+ it "should have results" do
+ news = EchoNest::NewsResult.parse(@xml)
+ news.results.should be_kind_of(EchoNest::NewsResults)
+
+ news.results.found.should == "67"
+ news.results.shown.should == "2"
+ news.results.start.should == "0"
+ news.results.docs.should be_kind_of(Array)
+ news.results.docs.length.should == 2
+ end
+
+ describe "result" do
+ it "should be an NewsDoc" do
+ news = EchoNest::NewsResult.parse(@xml)
+ doc = news.results.docs[0]
+ doc.should be_kind_of(EchoNest::NewsDoc)
+
+ doc.name.should == "Modeselektor supports Radiohead in Japan"
+ doc.url.should == "http://www.residentadvisor.net/news.aspx?id=9632"
+ doc.summary.should == "[news text removed]"
+ doc.date_found.should == "2008-11-26 21:19:35.356000"
+
+ end
+ end
+ end
+
+
+end
@@ -0,0 +1,32 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<response version="3">
+ <status>
+ <code>0</code>
+ <message>Success</message>
+ </status>
+ <query>
+ <parameter name="api_key">5ZAOMB3BUR8QUN4PE</parameter>
+ <parameter name="id">music://id.echonest.com/~/AR/ARH6W4X1187B99274F</parameter>
+ <parameter name="start">0</parameter>
+ <parameter name="rows">2</parameter>
+ </query>
+ <artist>
+ <name>Radiohead</name>
+ <id>music://id.echonest.com/~/AR/ARH6W4X1187B99274F</id>
+ <foreign_id>music://id.echonest.com/5ZAOMB3BUR8QUN4PE/AR/1</foreign_id>
+ </artist>
+ <results found="67" shown="2" start="0">
+ <doc id="f43d70ef2692a56b9302a143adc68be0" type="web">
+ <name>Modeselektor supports Radiohead in Japan</name>
+ <url>http://www.residentadvisor.net/news.aspx?id=9632</url>
+ <summary>[news text removed]</summary>
+ <date_found>2008-11-26 21:19:35.356000</date_found>
+ </doc>
+ <doc id="0023ab6baeb5952faf3dc31818804752" type="web">
+ <name>Radiohead webcasting final show of U.S. tour tonight (Santa Barbara Bowl)</name>
+ <url>http://prefixmag.com/news/radiohead-webcasting-final-show-tour-santa-barbara/21104/</url>
+ <summary>news text removed</summary>
+ <date_found>2008-11-26 21:19:35.356000</date_found>
+ </doc>
+ </results>
+</response>

0 comments on commit 6547d04

Please sign in to comment.