refactored tests
This commit is contained in:
parent
20e3e33e36
commit
d8a79fb870
58
test/data/ca15a59d7e2581a1458558ca48c02087.xml
Normal file
58
test/data/ca15a59d7e2581a1458558ca48c02087.xml
Normal file
File diff suppressed because one or more lines are too long
@ -22,40 +22,11 @@ class TestAlbum(unittest.TestCase):
|
|||||||
""" A test class for the Album module. """
|
""" A test class for the Album module. """
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
apikey = "152a230561e72192b8b0f3e42362c6ff"
|
self.album = api.get_album("Supersonic", "Oasis")
|
||||||
self.api = Api(apikey, no_cache = True)
|
|
||||||
self.album = self.api.get_album("Supersonic", "Oasis")
|
|
||||||
|
|
||||||
def tearDown(self):
|
def tearDown(self):
|
||||||
pass
|
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):
|
def testAlbumStats(self):
|
||||||
self.assertEqual(self.album.stats.listeners, 14286)
|
self.assertEqual(self.album.stats.listeners, 14286)
|
||||||
self.assertEqual(self.album.stats.playcount, 39594)
|
self.assertEqual(self.album.stats.playcount, 39594)
|
||||||
@ -81,10 +52,33 @@ class TestAlbum(unittest.TestCase):
|
|||||||
('return to paradice', 'Cornucopia'),
|
('return to paradice', 'Cornucopia'),
|
||||||
('return to paradice', 'Lost Balance')]
|
('return to paradice', 'Lost Balance')]
|
||||||
self.assertEqual(
|
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
|
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)
|
test_suite = unittest.TestLoader().loadTestsFromTestCase(TestAlbum)
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
@ -22,31 +22,11 @@ class TestArtist(unittest.TestCase):
|
|||||||
""" A test class for the Artist module. """
|
""" A test class for the Artist module. """
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
apikey = "152a230561e72192b8b0f3e42362c6ff"
|
self.artist = api.get_artist("Bon Jovi")
|
||||||
self.api = Api(apikey, no_cache = True)
|
|
||||||
self.artist = self.api.get_artist("Bon Jovi")
|
|
||||||
|
|
||||||
def tearDown(self):
|
def tearDown(self):
|
||||||
pass
|
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):
|
def testArtistStats(self):
|
||||||
self.assertEqual(self.artist.stats.listeners, 718040)
|
self.assertEqual(self.artist.stats.listeners, 718040)
|
||||||
self.assertEqual(self.artist.stats.playcount, 15353197)
|
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))
|
self.assertEqual(self.artist.bio.published, datetime(2009, 1, 2, 23, 53, 53))
|
||||||
|
|
||||||
def testArtistEvents(self):
|
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):
|
def testArtistShouts(self):
|
||||||
shouts = [('jessicahelwig', 'Fri Jan 2 18:44:43 2009'),
|
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. Big & Rich',
|
||||||
'Bon Jovi feat. LeAnn Rimes',
|
'Bon Jovi feat. LeAnn Rimes',
|
||||||
'Bon Jovi - Forever Young']
|
'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)
|
artists)
|
||||||
|
|
||||||
def testArtistTopAlbums(self):
|
def testArtistTopAlbums(self):
|
||||||
@ -166,10 +146,29 @@ class TestArtist(unittest.TestCase):
|
|||||||
'Bad Medicine',
|
'Bad Medicine',
|
||||||
'Keep the Faith']
|
'Keep the Faith']
|
||||||
self.assertEqual([track.name for track in self.artist.top_tracks[:10]], tracks)
|
self.assertEqual([track.name for track in self.artist.top_tracks[:10]], tracks)
|
||||||
|
|
||||||
def testArtistTopTrack(self):
|
def testArtistTopTrack(self):
|
||||||
self.assertEqual(self.artist.top_track.name, 'You Give Love a Bad Name')
|
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)
|
test_suite = unittest.TestLoader().loadTestsFromTestCase(TestArtist)
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
@ -22,22 +22,11 @@ class TestEvent(unittest.TestCase):
|
|||||||
""" A test class for the Event module. """
|
""" A test class for the Event module. """
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
apikey = "152a230561e72192b8b0f3e42362c6ff"
|
self.event = api.get_event(216156)
|
||||||
self.api = Api(apikey, no_cache = True)
|
|
||||||
self.event = self.api.get_event(216156)
|
|
||||||
|
|
||||||
def tearDown(self):
|
def tearDown(self):
|
||||||
pass
|
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):
|
def testEventArtists(self):
|
||||||
artists = ['Aerosmith']
|
artists = ['Aerosmith']
|
||||||
self.assertEqual([artist.name for artist in self.event.artists], artists)
|
self.assertEqual([artist.name for artist in self.event.artists], artists)
|
||||||
@ -45,23 +34,10 @@ class TestEvent(unittest.TestCase):
|
|||||||
def testEventHeadliner(self):
|
def testEventHeadliner(self):
|
||||||
self.assertEqual(self.event.headliner.name, 'Aerosmith')
|
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):
|
def testEventStats(self):
|
||||||
self.assertEqual(self.event.stats.attendance, 48)
|
self.assertEqual(self.event.stats.attendance, 48)
|
||||||
self.assertEqual(self.event.stats.reviews, 1)
|
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):
|
def testEventShouts(self):
|
||||||
shouts = [('Aeromaniac21280',
|
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!!!'),
|
'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),
|
self.assertEqual((shout.author.name, shout.body),
|
||||||
('Aeromaniac21280',
|
('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!!!'))
|
'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)
|
test_suite = unittest.TestLoader().loadTestsFromTestCase(TestEvent)
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
@ -22,33 +22,19 @@ class TestGeo(unittest.TestCase):
|
|||||||
""" A test class for the Geo module. """
|
""" A test class for the Geo module. """
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
apikey = "152a230561e72192b8b0f3e42362c6ff"
|
venue = api.get_venue('tokyo dome')
|
||||||
self.api = Api(apikey, no_cache = True)
|
|
||||||
venue = self.api.get_venue('tokyo dome')
|
|
||||||
self.location = venue.location
|
self.location = venue.location
|
||||||
self.country = venue.location.country
|
self.country = venue.location.country
|
||||||
|
|
||||||
def tearDown(self):
|
def tearDown(self):
|
||||||
pass
|
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):
|
def testLocationLatitude(self):
|
||||||
self.assertAlmostEqual(self.location.latitude, 35.685, 3)
|
self.assertAlmostEqual(self.location.latitude, 35.685, 3)
|
||||||
|
|
||||||
def testLocationLongitude(self):
|
def testLocationLongitude(self):
|
||||||
self.assertAlmostEqual(self.location.longitude, 139.7514, 4)
|
self.assertAlmostEqual(self.location.longitude, 139.7514, 4)
|
||||||
|
|
||||||
def testLocationTopTracks(self):
|
def testLocationTopTracks(self):
|
||||||
tracks = [('Viva la Vida', 'Coldplay'),
|
tracks = [('Viva la Vida', 'Coldplay'),
|
||||||
('Ulysses', 'Franz Ferdinand'),
|
('Ulysses', 'Franz Ferdinand'),
|
||||||
@ -63,7 +49,7 @@ class TestGeo(unittest.TestCase):
|
|||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
[(track.name, track.artist.name) for track in self.location.top_tracks[:10]],
|
[(track.name, track.artist.name) for track in self.location.top_tracks[:10]],
|
||||||
tracks)
|
tracks)
|
||||||
|
|
||||||
def testLocationTopTrack(self):
|
def testLocationTopTrack(self):
|
||||||
top_track = self.location.top_track
|
top_track = self.location.top_track
|
||||||
self.assertEqual((top_track.name, top_track.artist.name), ('Viva la Vida', 'Coldplay'))
|
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,
|
event_ids = [961510, 925636, 959392, 875466, 951038,
|
||||||
950520, 957543, 930614, 871240, 857063]
|
950520, 957543, 930614, 871240, 857063]
|
||||||
self.assertEqual([e.id for e in self.country.events[:10]], event_ids)
|
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)
|
test_suite = unittest.TestLoader().loadTestsFromTestCase(TestGeo)
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
Loading…
Reference in New Issue
Block a user