From d8a79fb870ea47d2792071bf2c72f2a66370332e Mon Sep 17 00:00:00 2001 From: Abhinav Sarkar Date: Wed, 4 Mar 2009 12:36:39 +0000 Subject: [PATCH] refactored tests --- .../data/ca15a59d7e2581a1458558ca48c02087.xml | 58 +++++++++++++++++++ test/test_album.py | 56 ++++++++---------- test/test_artist.py | 51 ++++++++-------- test/test_event.py | 47 +++++++-------- test/test_geo.py | 38 ++++++------ 5 files changed, 148 insertions(+), 102 deletions(-) create mode 100644 test/data/ca15a59d7e2581a1458558ca48c02087.xml diff --git a/test/data/ca15a59d7e2581a1458558ca48c02087.xml b/test/data/ca15a59d7e2581a1458558ca48c02087.xml new file mode 100644 index 0000000..aa8b539 --- /dev/null +++ b/test/data/ca15a59d7e2581a1458558ca48c02087.xml @@ -0,0 +1,58 @@ + + + + Oasis + 39ab1aed-75e0-4140-bd47-540276886b60 + http://www.last.fm/music/Oasis + http://userserve-ak.last.fm/serve/34/129589.jpg + http://userserve-ak.last.fm/serve/64/129589.jpg + http://userserve-ak.last.fm/serve/126/129589.jpg + 1 + + 1474646 + 45731388 + + + + + Noel Gallagher + http://www.last.fm/music/Noel+Gallagher + http://userserve-ak.last.fm/serve/34/250798.jpg + http://userserve-ak.last.fm/serve/64/250798.jpg> + http://userserve-ak.last.fm/serve/126/250798.jpg + + + The Verve + http://www.last.fm/music/The+Verve + http://userserve-ak.last.fm/serve/34/176111.jpg + http://userserve-ak.last.fm/serve/64/176111.jpg> + http://userserve-ak.last.fm/serve/126/176111.jpg + + + The Stone Roses + http://www.last.fm/music/The+Stone+Roses + http://userserve-ak.last.fm/serve/34/107436.jpg + http://userserve-ak.last.fm/serve/64/107436.jpg> + http://userserve-ak.last.fm/serve/126/107436.jpg + + + Richard Ashcroft + http://www.last.fm/music/Richard+Ashcroft + http://userserve-ak.last.fm/serve/34/561176.jpg + http://userserve-ak.last.fm/serve/64/561176.jpg> + http://userserve-ak.last.fm/serve/126/561176.jpg + + + Kasabian + http://www.last.fm/music/Kasabian + http://userserve-ak.last.fm/serve/34/63658.jpg + http://userserve-ak.last.fm/serve/64/63658.jpg> + http://userserve-ak.last.fm/serve/126/63658.jpg + + + + Mon, 2 Mar 2009 20:54:07 +0000 + Omar-S 4. A British classical music group active in the mid-80's British rock band: Oasis is a British group, originally formed in Manchester, United Kingdom in 1991.]]> + Omar-S 4. A British classical music group active in the mid-80's British rock band: Oasis is a British group, originally formed in Manchester, United Kingdom in 1991. They enjoyed a period of huge success following the release of their first album, Definitely Maybe and during the second, "(What's the Story) Morning Glory?", with praise from across the spectrum and the accumulation of several major awards. Many critics have since said this was the peak of their musical career to-date. They cite bands such as The Beatles, Slade, The Stone Roses, The Real People, The Smiths and The Who as influences. Oasis has sold 50 million albums worldwide. To date, they have released 7 studio albums, all to hit #1 on the UK album chart! The band currently comprises lead guitarist and principal songwriter Noel Gallagher and his younger brother vocalist/songwriter Liam Gallagher, who are the only remaining original band members. Included in the group are Andy Bell (formerly of shoegaze band Ride), Gem Archer, and drummer Chris Sharrock, former Robbie Williams drummer. The band continues to maintain its original organization of two guitarists, one bassist, drummer, and lead singer. Thanks to the success of their critically acclaimed debut album "Definitely Maybe" and its 18m selling follow-up "(What's the Story) Morning Glory?", the Gallagher brothers featured regularly in tabloid newspaper stories, and cultivated a reputation as bad boys. Berwick Street in London was used for the Album cover of (What's the Story) Morning Glory? http://www.musicpilgrimages.com/articl/2005.php At the height of their fame, their 1997 third album "Be Here Now" reached #1 in the UK charts and also became the fastest-selling album in chart history, with almost half a million copies sold on the first day alone. It also reached #1 in France, Canada, Australia, Ireland, and Japan as well as #2 in the U.S., just 770 copies short of that week's #1 album. However, the record almost caused the destruction of the band as they experienced an immediate fall in popularity. Stocks Hotel and Country Club in Hertfordshire was used for the album cover for Be Here Now http://www.musicpilgrimages.com/articl/1601.php After a three-year break they returned with "Standing on the Shoulder of Giants" in 2000. Although it was poorly received by critics, it duly gave them their fourth UK #1 album and their fifth UK #1 single with lead single "Go Let It Out". Most of the album was recorded by just Noel Gallagher, Liam Gallagher, and Alan White as Paul Arthurs and Paul McGuigan left shortly before its recording. A new line-up, containing ex-Ride member Andy Bell and Gem Archer, released "Heathen Chemistry" in 2002, which wasn't well received by the public or the critics. It also hit #1 and contained their sixth UK #1 single in "The Hindu Times", which also topped the Canadian and Italian charts. Alan White, with the band since "(What's the Story) Morning Glory?", left in 2004 shortly before the recording of the band's sixth album "Don't Believe the Truth" with rumours suggesting he lacked commitment to the band. He was replaced by Zak Starkey, son of The Beatles' drummer Ringo Starr. "Don't Believe the Truth" was a huge hit both commercially and (for the first time in a long time for Oasis) critically, hitting #1 and winning a Q award for album of the year, beating Coldplay's "X&Y" amongst others. Sales were over 350,000 in the first week alone and have already broken 1,000,000. Their performances live were also their most consistent in years, as Liam completed all shows. They successfully toured Europe, North America (Canada, USA, Mexico), Asia (Japan, South Korea, Hong Kong, Singapore) and Australia (Perth, Sydney, Brisbane and Melbourne). Through surviving the loss of founding members and with continuous support from their loyal fanbase, Oasis have managed to outlast many of their Britpop contemporaries. Suede, Pulp, and some other peer groups have split up, or record only infrequently, while Oasis maintain a regular schedule of releases and touring. They released a best of compilation entitled "Stop The Clocks" in 2006. The Battle of Britpop A slight setback occured during early sessions for their second album. Original drummer Tony McCarroll was sacked. Noel Gallagher has since claimed that his departure was a result of him not being technically good enough to play on more complex songs. There were also reports of scuffles with the Gallaghers. McCaroll had been angered by the "£1,000 incident", as the band called it, which occurred after Creation advanced them that sum to purchase new equipment. Having already spent £600 of his own money on drums, McCaroll was annoyed to find that Noel refused to spend any of the cash on drum skins and instead bought a new guitar. McCaroll was replaced with quiet Londoner Alan White, whose brother Steve had drummed for Paul Weller and his band Style Council and many others. McCaroll later attempted to sue the Gallaghers over his sacking, citing breach of contract, but lost the suit on a technicality. Oasis soon had their first UK #1 with "Some Might Say", the first single from their second album (and the only track on the second album to feature McCarroll), in late April 1995. During this period, the British media seized upon a supposed rivalry between Oasis and fellow Britpop band Blur. Noel Gallagher played along, telling The Observer that he hoped Damon Albarn and Alex James of Blur would "catch AIDS and die". He subsequently apologized for this in a formal letter to Melody Maker magazine. On Monday, August 14, 1995, Blur and Oasis released new singles on the same day, setting up a "Battle of the Bands" that dominated the week's music news. Perhaps in part because it was more cheaply priced (£1.99 vs £3.99), Blur's "Country House" outsold Oasis's "Roll With It" by 274,000 copies to 216,000 during the week. There was also the difference that "Country House" was the lead single for a new album, whereas "Roll With It" was the second single off of "(What's the Story) Morning Glory?". Nonetheless, the supposed rivalry has been exploited and rehashed innumerable times in the British press ever since. In spite of the loss on the singles charts for "Roll With It", Oasis's second album, "(What's the Story) Morning Glory?", became the second largest selling album of all time in the UK. Locations There is a number of locations around the UK that are associated with Oasis. John Lennon's childhood home, 251 Menlove Avenue - was used for the sleeve of Oasis single 'Live Forever' http://www.musicpilgrimages.com/articl/2015.php Berwick street in London was used for the Album cover of '(What's the Story) Morning Glory?' http://www.musicpilgrimages.com/articl/2005.php Cromford Railway Station in Derbyshire was used for the sleeve of Oasis single 'Some might say' http://www.musicpilgrimages.com/articl/2012.php Liam Gallagher has gotten married twice at the Marylebone Registry Office, to Patsy Kensit in 1997 and on Valentines day the 14th of February 2008 he married his present wife Nicole Appleton. Perhaps one reason is that he is a big Beatle fan and both Paul McCartney and Ringo Starr got married at the Marylebone Registry Office. Liam Gallagher obviously a massive fan of The Beatles once quoted they are his favorite band, but his favorite modern band are Floor monks http://www.musicpilgrimages.com/articl/1109.php Regents Park was used for the music video for Liam's track Songbird http://www.musicpilgrimages.com/articl/2010.php Sifters Records in the Manchester suburb of Didsbury is both mentioned in the lyrics for, and appears in the video of, 'Shakermaker' http://www.musicpilgrimages.com/articl/2014.php Stocks Hotel and Country Club was used for the album cover 'Be here now' http://www.musicpilgrimages.com/articl/1601.php When Noel had first moved to London and before Oasis rose to fame, he used to hang out at the Good Mixer in Camden, the classic Britpop pub. http://www.musicpilgrimages.com/articl/1600.php Official site: www.oasisinet.com American rock band: Oasis was an American rock band from Marin County, California active in the 1970s. Their sound has been described as psychedelic folk rock, progressive folk and psychedelic pop, characterized by male/female harmonies. With the help of David Crosby of famed Crosby, Stills & Nash, they recorded one album, Oasis, released on the Cranbus label in 1973. Members Shelly Fox was previously in Cookin Mama, and Stephen Barncard also worked with Chet Nichols and David Crosby. Kelly Bryan had earlier been in the short-lived Grootna, and later played on a couple of albums by Jesse Colin Young. Between 1971 and 1978 members of Oasis also recorded under the name RJ Fox and completed an album for Atlantic in 1971 which was never released. A double disc collection of Oasis and RJ Fox material was compiled by the Black Bamboo label in 1998. RJ Fox: Retrospective Dreams included the lost LP, tracks from the Oasis album and many others. American deep house producer: Oasis is an alias of Omar-S (Alex O. Smith) from Detroit, a deep house / techno producer. British classical group: Oasis was a short-lived English classic group active through 1984-1988 featuring Peter Skellern, Julian Lloyd Webber (later replaced by Audrey Riley), Mitch Dalton, Bill Lovelady and Mary Hopkin. Oasis released only self-titled album and two singles and toured till 1988.]]> + + diff --git a/test/test_album.py b/test/test_album.py index e24e0f9..c4e78a9 100644 --- a/test/test_album.py +++ b/test/test_album.py @@ -22,40 +22,11 @@ class TestAlbum(unittest.TestCase): """ A test class for the Album module. """ def setUp(self): - apikey = "152a230561e72192b8b0f3e42362c6ff" - self.api = Api(apikey, no_cache = True) - self.album = self.api.get_album("Supersonic", "Oasis") + self.album = api.get_album("Supersonic", "Oasis") def tearDown(self): pass - def testAlbumName(self): - self.assertEqual(self.album.name, "Supersonic") - - def testAlbumArtist(self): - self.assertEqual(self.album.artist.name, "Oasis") - - def testAlbumId(self): - self.assertEqual(self.album.id, 2038492) - - def testAlbumMbid(self): - mbid = '2c2a24de-67b6-483b-b597-9c6b7891ba90' - self.assertEqual(self.album.mbid, mbid) - - def testAlbumUrl(self): - url = 'http://www.last.fm/music/Oasis/Supersonic' - self.assertEqual(self.album.url, url) - - def testAlbumReleaseDate(self): - date = datetime.datetime(1994, 7, 28, 0, 0) - self.assertEqual(self.album.release_date, date) - - def testAlbumImage(self): - self.assertEqual(self.album.image['small'], "http://userserve-ak.last.fm/serve/34/11846565.jpg") - self.assertEqual(self.album.image['medium'], "http://userserve-ak.last.fm/serve/64/11846565.jpg") - self.assertEqual(self.album.image['large'], "http://userserve-ak.last.fm/serve/174s/11846565.jpg") - self.assertEqual(self.album.image['extralarge'], "http://userserve-ak.last.fm/serve/300x300/11846565.jpg") - def testAlbumStats(self): self.assertEqual(self.album.stats.listeners, 14286) self.assertEqual(self.album.stats.playcount, 39594) @@ -81,10 +52,33 @@ class TestAlbum(unittest.TestCase): ('return to paradice', 'Cornucopia'), ('return to paradice', 'Lost Balance')] self.assertEqual( - [(album.name, album.artist.name) for album in self.api.search_album("paradice")[:10]], + [(album.name, album.artist.name) for album in api.search_album("paradice")[:10]], albums ) +apikey = "152a230561e72192b8b0f3e42362c6ff" +api = Api(apikey, no_cache = True) + +data = { + 'name': "Supersonic", + 'artist': api.get_artist("Oasis"), + 'id': 2038492, + 'mbid': '2c2a24de-67b6-483b-b597-9c6b7891ba90', + 'url': 'http://www.last.fm/music/Oasis/Supersonic', + 'release_date': datetime.datetime(1994, 7, 28, 0, 0), + 'image': { + 'extralarge': 'http://userserve-ak.last.fm/serve/300x300/23049597.jpg', + 'large': 'http://userserve-ak.last.fm/serve/174s/23049597.jpg', + 'medium': 'http://userserve-ak.last.fm/serve/64s/23049597.jpg', + 'small': 'http://userserve-ak.last.fm/serve/34s/23049597.jpg' + } +} + +for k,v in data.iteritems(): + def testFunc(self): + self.assertEqual(getattr(self.album, k), v) + setattr(TestAlbum, "testAlbum%s" % k.replace('_', ' ').title().replace(' ', ''), testFunc) + test_suite = unittest.TestLoader().loadTestsFromTestCase(TestAlbum) if __name__ == '__main__': diff --git a/test/test_artist.py b/test/test_artist.py index 24fbb43..614f81e 100644 --- a/test/test_artist.py +++ b/test/test_artist.py @@ -22,31 +22,11 @@ class TestArtist(unittest.TestCase): """ A test class for the Artist module. """ def setUp(self): - apikey = "152a230561e72192b8b0f3e42362c6ff" - self.api = Api(apikey, no_cache = True) - self.artist = self.api.get_artist("Bon Jovi") + self.artist = api.get_artist("Bon Jovi") def tearDown(self): pass - - def testArtistName(self): - self.assertEqual(self.artist.name, 'Bon Jovi') - - def testArtistMbid(self): - self.assertEqual(self.artist.mbid, '5dcdb5eb-cb72-4e6e-9e63-b7bace604965') - - def testArtistUrl(self): - self.assertEqual(self.artist.url, 'http://www.last.fm/music/Bon+Jovi') - - def testArtistImage(self): - self.assertEqual(self.artist.image, - {'large': 'http://userserve-ak.last.fm/serve/126/24125.jpg', - 'medium': 'http://userserve-ak.last.fm/serve/64/24125.jpg', - 'small': 'http://userserve-ak.last.fm/serve/34/24125.jpg'}) - - def testArtistStreamable(self): - self.assertFalse(self.artist.streamable) - + def testArtistStats(self): self.assertEqual(self.artist.stats.listeners, 718040) self.assertEqual(self.artist.stats.playcount, 15353197) @@ -88,7 +68,7 @@ class TestArtist(unittest.TestCase): self.assertEqual(self.artist.bio.published, datetime(2009, 1, 2, 23, 53, 53)) def testArtistEvents(self): - self.assertEqual(self.artist.events, [self.api.get_event(642495)]) + self.assertEqual(self.artist.events, [api.get_event(642495)]) def testArtistShouts(self): shouts = [('jessicahelwig', 'Fri Jan 2 18:44:43 2009'), @@ -119,7 +99,7 @@ class TestArtist(unittest.TestCase): 'Bon Jovi Feat. Big & Rich', 'Bon Jovi feat. LeAnn Rimes', 'Bon Jovi - Forever Young'] - self.assertEqual([artist.name for artist in self.api.search_artist("Bon Jovi")[:10]], + self.assertEqual([artist.name for artist in api.search_artist("Bon Jovi")[:10]], artists) def testArtistTopAlbums(self): @@ -166,10 +146,29 @@ class TestArtist(unittest.TestCase): 'Bad Medicine', 'Keep the Faith'] self.assertEqual([track.name for track in self.artist.top_tracks[:10]], tracks) - + def testArtistTopTrack(self): self.assertEqual(self.artist.top_track.name, 'You Give Love a Bad Name') - + + +apikey = "152a230561e72192b8b0f3e42362c6ff" +api = Api(apikey, no_cache = True) + +data = { + 'name': 'Bon Jovi', + 'mbid': '5dcdb5eb-cb72-4e6e-9e63-b7bace604965', + 'url': 'http://www.last.fm/music/Bon+Jovi', + 'image': {'large': 'http://userserve-ak.last.fm/serve/126/24125.jpg', + 'medium': 'http://userserve-ak.last.fm/serve/64/24125.jpg', + 'small': 'http://userserve-ak.last.fm/serve/34/24125.jpg'}, + 'streamable': False +} + +for k,v in data.iteritems(): + def testFunc(self): + self.assertEqual(getattr(self.artist, k), v) + setattr(TestArtist, "testArtist%s" % k.replace('_', ' ').title().replace(' ', ''), testFunc) + test_suite = unittest.TestLoader().loadTestsFromTestCase(TestArtist) if __name__ == '__main__': diff --git a/test/test_event.py b/test/test_event.py index c0de7c6..ede8cbf 100644 --- a/test/test_event.py +++ b/test/test_event.py @@ -22,22 +22,11 @@ class TestEvent(unittest.TestCase): """ A test class for the Event module. """ def setUp(self): - apikey = "152a230561e72192b8b0f3e42362c6ff" - self.api = Api(apikey, no_cache = True) - self.event = self.api.get_event(216156) + self.event = api.get_event(216156) def tearDown(self): pass - - def testEventId(self): - self.assertEqual(self.event.id, 216156) - - def testEventTitle(self): - self.assertEqual(self.event.title, 'Aerosmith') - - def testEventDescription(self): - self.assertEqual(self.event.description, 'Tickets priced at 1,800 and 1,200.') - + def testEventArtists(self): artists = ['Aerosmith'] self.assertEqual([artist.name for artist in self.event.artists], artists) @@ -45,23 +34,10 @@ class TestEvent(unittest.TestCase): def testEventHeadliner(self): self.assertEqual(self.event.headliner.name, 'Aerosmith') - def testEventImage(self): - self.assertEqual(self.event.image, - {'large': 'http://userserve-ak.last.fm/serve/126/300793.jpg', - 'medium': 'http://userserve-ak.last.fm/serve/64/300793.jpg', - 'small': 'http://userserve-ak.last.fm/serve/34/300793.jpg'} - ) - def testEventStats(self): self.assertEqual(self.event.stats.attendance, 48) self.assertEqual(self.event.stats.reviews, 1) - def testEventTag(self): - self.assertEqual(self.event.tag, 'lastfm:event=216156') - - def testEventUrl(self): - self.assertEqual(self.event.url, 'http://www.last.fm/event/216156') - def testEventShouts(self): shouts = [('Aeromaniac21280', 'It was a brillian show still jealous at some ppl who could meet them video of joe perry banging the guitar in youtube, in between u will see a devils hand with the thorny black heavy metal wrist band, that hand IS MINE LOL!!!'), @@ -83,7 +59,26 @@ class TestEvent(unittest.TestCase): self.assertEqual((shout.author.name, shout.body), ('Aeromaniac21280', 'It was a brillian show still jealous at some ppl who could meet them video of joe perry banging the guitar in youtube, in between u will see a devils hand with the thorny black heavy metal wrist band, that hand IS MINE LOL!!!')) + +apikey = "152a230561e72192b8b0f3e42362c6ff" +api = Api(apikey, no_cache = True) + +data = { + 'id': 216156, + 'title': 'Aerosmith', + 'description': 'Tickets priced at 1,800 and 1,200.', + 'image': {'large': 'http://userserve-ak.last.fm/serve/126/300793.jpg', + 'medium': 'http://userserve-ak.last.fm/serve/64/300793.jpg', + 'small': 'http://userserve-ak.last.fm/serve/34/300793.jpg'}, + 'tag': 'lastfm:event=216156', + 'url': 'http://www.last.fm/event/216156' +} +for k,v in data.iteritems(): + def testFunc(self): + self.assertEqual(getattr(self.event, k), v) + setattr(TestEvent, "testEvent%s" % k.replace('_', ' ').title().replace(' ', ''), testFunc) + test_suite = unittest.TestLoader().loadTestsFromTestCase(TestEvent) if __name__ == '__main__': diff --git a/test/test_geo.py b/test/test_geo.py index a86a23c..f81ce03 100644 --- a/test/test_geo.py +++ b/test/test_geo.py @@ -22,33 +22,19 @@ class TestGeo(unittest.TestCase): """ A test class for the Geo module. """ def setUp(self): - apikey = "152a230561e72192b8b0f3e42362c6ff" - self.api = Api(apikey, no_cache = True) - venue = self.api.get_venue('tokyo dome') + venue = api.get_venue('tokyo dome') self.location = venue.location self.country = venue.location.country def tearDown(self): pass - def testLocationCity(self): - self.assertEqual(self.location.city, "Tokyo") - - def testLocationCountry(self): - self.assertEqual(self.location.country, self.api.get_country("Japan")) - - def testLocationStreet(self): - self.assertEqual(self.location.street, '1-3-61, Koraku, Bunkyo-ku') - - def testLocationPostalCode(self): - self.assertEqual(self.location.postal_code, '112-8562') - def testLocationLatitude(self): self.assertAlmostEqual(self.location.latitude, 35.685, 3) def testLocationLongitude(self): - self.assertAlmostEqual(self.location.longitude, 139.7514, 4) - + self.assertAlmostEqual(self.location.longitude, 139.7514, 4) + def testLocationTopTracks(self): tracks = [('Viva la Vida', 'Coldplay'), ('Ulysses', 'Franz Ferdinand'), @@ -63,7 +49,7 @@ class TestGeo(unittest.TestCase): self.assertEqual( [(track.name, track.artist.name) for track in self.location.top_tracks[:10]], tracks) - + def testLocationTopTrack(self): top_track = self.location.top_track self.assertEqual((top_track.name, top_track.artist.name), ('Viva la Vida', 'Coldplay')) @@ -108,7 +94,21 @@ class TestGeo(unittest.TestCase): event_ids = [961510, 925636, 959392, 875466, 951038, 950520, 957543, 930614, 871240, 857063] self.assertEqual([e.id for e in self.country.events[:10]], event_ids) - + +apikey = "152a230561e72192b8b0f3e42362c6ff" +api = Api(apikey, no_cache = True) +data = { + 'city': "Tokyo", + 'country': api.get_country("Japan"), + 'street': '1-3-61, Koraku, Bunkyo-ku', + 'postal_code': '112-8562' +} + +for k,v in data.iteritems(): + def testFunc(self): + self.assertEqual(getattr(self.location, k), v) + setattr(TestGeo, "testLocation%s" % k.replace('_', ' ').title().replace(' ', ''), testFunc) + test_suite = unittest.TestLoader().loadTestsFromTestCase(TestGeo) if __name__ == '__main__':