Exemplo n.º 1
0
 def setup(self):
     self.geo = Geo()
     self.utils = Utils()
Exemplo n.º 2
0
 def setup(self):
     self.geo = Geo()
     self.utils = Utils()
Exemplo n.º 3
0
class TestGeo:
    def __init__(self):
        self.geo = Geo()
        self.utils = None

    def setup(self):
        self.geo = Geo()
        self.utils = Utils()

    @raises(Exception)
    def test_raise_data_exception(self):
        """ Testing make request data raising Exception """
        events = self.geo.get_events()

    def test_get_events_from_a_city(self):
        """ Testing Geo get Event from a city """
        events = self.geo.get_events(location="Belo Horizonte")
        self.utils.assert_response_content(events)

    def test_get_event_with_lat_and_long(self):
        """ Testing Geo get Event with latitude and longitude """
        lat = "-19.923645"
        long = "-43.919173"
        location = "Belo Horizonte"
        events = self.geo.get_events(lat=lat, long=long)
        self.utils.assert_response_content(events)
        geo = events["events"]["event"][0]["venue"]["location"]["geo:point"]
        assert_equal(geo["geo:long"], long)
        assert_equal(geo["geo:lat"], lat)

    def test_get_event_with_distance(self):
        """ Testing Geo get Event with radial distance """
        location = "London"
        distance = "300"
        events = self.geo.get_events(location=location, distance=distance)
        self.utils.assert_response_content(events)

    def test_get_event_with_page(self):
        """ Testing Geo get Event with page parameter """
        page = 2
        location = "London"
        events = self.geo.get_events(location=location, page=page)
        self.utils.assert_response_content(events)
        assert_equal(events["events"]["@attr"]["page"], str(page))

    def test_get_event_with_tag(self):
        """ Testing Geo get Event with tag parameter """
        location = "Belo Horizonte"
        tag = "thrash metal"
        events = self.geo.get_events(location=location, tag=tag)
        self.utils.assert_response_content(events)
        event_tag = events["events"]["event"][0]["tags"]["tag"]
        assert_equal(event_tag, tag)

    def test_get_event_with_festivalsonly(self):
        """ Testing Geo get Event with festivalsonly parameter """
        location = "London"
        festonly = True
        events = self.geo.get_events(location=location, festivalsonly=festonly)
        self.utils.assert_response_content(events)
        assert_equal(events["events"]["@attr"]["festivalsonly"], "1")

    def test_get_event_with_limit(self):
        """ Testing Geo get Event with limit parameter """
        events = self.geo.get_events(location="Belo Horizonte", limit=1)
        self.utils.assert_response_content(events)
        del events["events"]["@attr"]
        assert_equal(len(events["events"]), 1)

    def test_get_metro_artist_chart(self):
        """ Testing Geo get Metro artist """
        metro = "madrid"
        country = "spain"
        chart = self.geo.get_metro_artist_chart(metro=metro, country=country)
        self.utils.assert_response_content(chart)
        assert_greater(len(chart["topartists"]["artist"]), 5)

    @raises(Exception)
    def test_get_metro_artist_chart_with_no_country(self):
        """ Testing Geo get Metro artist with no country """
        self.geo.get_metro_artist_chart(metro="Baker Street")

    @raises(Exception)
    def test_get_metro_artist_chart_with_no_metro(self):
        """ Testing Geo get Metro artist with no metro name """
        self.geo.get_metro_artist_chart(country="United Kingdom")

    def test_get_metro_artist_chart_with_start(self):
        """ Testing Geo get Metro artist with start parameter """
        metro = "madrid"
        country = "spain"
        chart = self.geo.get_metro_artist_chart(metro=metro, country=country, start=5)
        self.utils.assert_response_content(chart)

    def test_get_metro_artist_chart_with_end(self):
        """ Testing Geo get Metro artist with end parameter """
        metro = "madrid"
        country = "spain"
        chart = self.geo.get_metro_artist_chart(metro=metro, country=country, end=10)
        self.utils.assert_response_content(chart)

    def test_get_metro_artist_chart_with_start_and_end(self):
        """ Testing Geo get Metro artist with start and end parameters """
        metro = "madrid"
        country = "spain"
        start = int(mktime((datetime.now() - timedelta(days=60)).timetuple()))
        end = int(mktime(datetime.now().timetuple()))
        chart = self.geo.get_metro_artist_chart(metro=metro, country=country, start=start, end=end)
        self.utils.assert_response_content(chart)

    def test_get_metro_artist_chart_with_page(self):
        """ Testing Geo get Metro artist with page parameter """
        metro = "madrid"
        country = "spain"
        page = "2"
        chart = self.geo.get_metro_artist_chart(metro=metro, country=country, page=page)
        self.utils.assert_response_content(chart)
        assert_equal(chart["topartists"]["@attr"]["page"], page)

    def test_get_metro_artist_chart_with_limit(self):
        """ Testing Geo get Metro artist with limit parameter """
        metro = "madrid"
        country = "spain"
        limit = "1"
        chart = self.geo.get_metro_artist_chart(metro=metro, country=country, limit=limit)
        self.utils.assert_response_content(chart)
        import ipdb

        ipdb.set_trace()
        assert_equal(chart["topartists"]["@attr"]["perPage"], limit)
        del chart["topartists"]["@attr"]
        assert_equal(len(chart["topartists"]), int(limit))
Exemplo n.º 4
0
    def setup(self):

        self.artist = Artist("Foo fighters")
        self.auth = Auth(mysession)
        self.album = Album(artist=self.artist, album="Wasting Light")
        self.utils = Utils()
Exemplo n.º 5
0
class TestGeo:
    def __init__(self):
        self.geo = Geo()
        self.utils = None

    def setup(self):
        self.geo = Geo()
        self.utils = Utils()

    @raises(Exception)
    def test_raise_data_exception(self):
        """ Testing make request data raising Exception """
        events = self.geo.get_events()

    def test_get_events_from_a_city(self):
        """ Testing Geo get Event from a city """
        events = self.geo.get_events(location="Belo Horizonte")
        self.utils.assert_response_content(events)

    def test_get_event_with_lat_and_long(self):
        """ Testing Geo get Event with latitude and longitude """
        lat = "-19.923645"
        long = "-43.919173"
        location = "Belo Horizonte"
        events = self.geo.get_events(lat=lat, long=long)
        self.utils.assert_response_content(events)
        geo = events['events']['event'][0]['venue']['location']['geo:point']
        assert_equal(geo['geo:long'], long)
        assert_equal(geo['geo:lat'], lat)

    def test_get_event_with_distance(self):
        """ Testing Geo get Event with radial distance """
        location = "London"
        distance = "300"
        events = self.geo.get_events(location=location, distance=distance)
        self.utils.assert_response_content(events)

    def test_get_event_with_page(self):
        """ Testing Geo get Event with page parameter """
        page = 2
        location = "London"
        events = self.geo.get_events(location=location, page=page)
        self.utils.assert_response_content(events)
        assert_equal(events['events']['@attr']['page'], str(page))

    def test_get_event_with_tag(self):
        """ Testing Geo get Event with tag parameter """
        location = "Belo Horizonte"
        tag = "thrash metal"
        events = self.geo.get_events(location=location, tag=tag)
        self.utils.assert_response_content(events)
        event_tag = events['events']['event'][0]['tags']['tag']
        assert_equal(event_tag, tag)

    def test_get_event_with_festivalsonly(self):
        """ Testing Geo get Event with festivalsonly parameter """
        location = "London"
        festonly = True
        events = self.geo.get_events(location=location, festivalsonly=festonly)
        self.utils.assert_response_content(events)
        assert_equal(events['events']['@attr']['festivalsonly'], "1")

    def test_get_event_with_limit(self):
        """ Testing Geo get Event with limit parameter """
        events = self.geo.get_events(location="Belo Horizonte", limit=1)
        self.utils.assert_response_content(events)
        del events['events']['@attr']
        assert_equal(len(events['events']), 1)

    def test_get_metro_artist_chart(self):
        """ Testing Geo get Metro artist """
        metro = "madrid"
        country = "spain"
        chart = self.geo.get_metro_artist_chart(metro=metro, country=country)
        self.utils.assert_response_content(chart)
        assert_greater(len(chart['topartists']['artist']), 5)

    @raises(Exception)
    def test_get_metro_artist_chart_with_no_country(self):
        """ Testing Geo get Metro artist with no country """
        self.geo.get_metro_artist_chart(metro="Baker Street")

    @raises(Exception)
    def test_get_metro_artist_chart_with_no_metro(self):
        """ Testing Geo get Metro artist with no metro name """
        self.geo.get_metro_artist_chart(country="United Kingdom")

    def test_get_metro_artist_chart_with_start(self):
        """ Testing Geo get Metro artist with start parameter """
        metro = "madrid"
        country = "spain"
        chart = self.geo.get_metro_artist_chart(metro=metro,
                                                country=country,
                                                start=5)
        self.utils.assert_response_content(chart)

    def test_get_metro_artist_chart_with_end(self):
        """ Testing Geo get Metro artist with end parameter """
        metro = "madrid"
        country = "spain"
        chart = self.geo.get_metro_artist_chart(metro=metro,
                                                country=country,
                                                end=10)
        self.utils.assert_response_content(chart)

    def test_get_metro_artist_chart_with_start_and_end(self):
        """ Testing Geo get Metro artist with start and end parameters """
        metro = "madrid"
        country = "spain"
        start = int(mktime((datetime.now() - timedelta(days=60)).timetuple()))
        end = int(mktime(datetime.now().timetuple()))
        chart = self.geo.get_metro_artist_chart(metro=metro,
                                                country=country,
                                                start=start,
                                                end=end)
        self.utils.assert_response_content(chart)

    def test_get_metro_artist_chart_with_page(self):
        """ Testing Geo get Metro artist with page parameter """
        metro = "madrid"
        country = "spain"
        page = '2'
        chart = self.geo.get_metro_artist_chart(metro=metro,
                                                country=country,
                                                page=page)
        self.utils.assert_response_content(chart)
        assert_equal(chart['topartists']['@attr']['page'], page)

    def test_get_metro_artist_chart_with_limit(self):
        """ Testing Geo get Metro artist with limit parameter """
        metro = "madrid"
        country = "spain"
        limit = '1'
        chart = self.geo.get_metro_artist_chart(metro=metro,
                                                country=country,
                                                limit=limit)
        self.utils.assert_response_content(chart)
        import ipdb
        ipdb.set_trace()
        assert_equal(chart['topartists']['@attr']['perPage'], limit)
        del chart['topartists']['@attr']
        assert_equal(len(chart['topartists']), int(limit))
Exemplo n.º 6
0
class TestChart:
    """ Test class of Chart module """

    def __init__(self):
        self.utils = None
        self.chart = None

    def setup(self):
        self.utils = Utils()
        self.chart = Chart()

    def test_hyped_artists(self):
        """ Testing Chart hyped artists """
        chart = self.chart.get_hyped_artists()
        self.utils.assert_response_content(chart)
        assert_greater(chart['artists'], 1)

    def test_hyped_artists_with_page(self):
        """ Testing Chart hyped artists with page parameter """
        chart = self.chart.get_hyped_artists(page=2)
        self.utils.assert_response_content(chart)
        assert_equal(chart['artists']['@attr']['page'], "2")

    def test_hyped_artists_with_limit(self):
        """ Testing Chart hyped artists with limit parameter """
        chart = self.chart.get_hyped_artists(limit=1)
        self.utils.assert_response_content(chart)
        del chart['artists']['@attr']
        assert_equal(len(chart['artists']), 1)

    def test_get_hyped_tracks(self):
        """ Testing Chart hyped tracks """
        chart = self.chart.get_hyped_tracks(page=2, limit=1)
        self.utils.assert_response_content(chart)
        assert_equal(chart['tracks']['@attr']['page'], "2")
        del chart['tracks']['@attr']
        assert_equal(len(chart['tracks']), 1)

    def test_get_loved_tracks(self):
        """ Testing Chart loved tracks """
        chart = self.chart.get_loved_tracks(page=2, limit=1)
        self.utils.assert_response_content(chart)
        assert_equal(chart['tracks']['@attr']['page'], "2")
        del chart['tracks']['@attr']
        assert_equal(len(chart['tracks']), 1)

    def test_get_top_artists(self):
        """ Testing Chart top artists """
        chart = self.chart.get_top_artists(page=2, limit=1)
        self.utils.assert_response_content(chart)
        assert_equal(chart['artists']['@attr']['page'], "2")
        del chart['artists']['@attr']
        assert_equal(len(chart['artists']), 1)

    def test_get_top_tags(self):
        """ Testing Chart top tags """
        chart = self.chart.get_top_tags(page=2, limit=1)
        self.utils.assert_response_content(chart)
        assert_equal(chart['tags']['@attr']['page'], "2")
        del chart['tags']['@attr']
        assert_equal(len(chart['tags']), 1)

    def get_top_tracks(self):
        """ Testing Chart top tags """
        chart = self.chart.get_top_tracks(page=2, limit=1)
        self.utils.assert_response_content(chart)
        assert_equal(chart['tracks']['@attr']['page'], "2")
        del chart['tracks']['@attr']
        assert_equal(len(chart['tracks']), 1)
Exemplo n.º 7
0
class TestAlbum:
    def __init__(self):
        self.artist = None
        self.auth = None
        self.album = None
        self.utils = None

    def setup(self):

        self.artist = Artist("Foo fighters")
        self.auth = Auth(mysession)
        self.album = Album(artist=self.artist, album="Wasting Light")
        self.utils = Utils()

    @raises(Exception)
    def test_album_with_no_artist(self):
        """ Testing Album with no artist """
        self.album = Album(album="Wasting Light")

    @raises(Exception)
    def test_album_with_no_album(self):
        """ Testing Album with no album name """
        self.album = Album(artist=self.artist)

    def test_add_tags(self):
        """ Testing Album add tags  """
        tags = self.album.add_tags(tags="api test", auth=self.auth)
        self.utils.assert_response_content(tags)

    @raises(Exception)
    def test_add_tags_with_no_auth(self):
        """ Testing Album add tags with no auth object """
        self.album.add_tags(tags="api test")

    def test_get_buy_links(self):
        """ Testing Album buy links """
        buy_links = self.album.get_buy_links(country="Brazil", correct=True)
        self.utils.assert_response_content(buy_links)
        assert_greater(buy_links['affiliations'], 0)

    def test_get_info(self):
        """ Testing Album information """
        info = self.album.get_info()
        self.utils.assert_response_content(info)
        assert_in("name", info['album'])

    def test_get_info_with_username(self):
        """ Testing Album information with username parameter """
        info = self.album.get_info(username="******")
        self.utils.assert_response_content(info)
        assert_in('userplaycount', info['album'])

    def test_get_info_with_lang(self):
        """ Testing Album information with language parameter """
        info = self.album.get_info(lang="por")
        self.utils.assert_response_content(info)

    def test_get_shouts(self):
        """ Testing Album shouts """
        shouts = self.album.get_shouts()
        self.utils.assert_response_content(shouts)

    def test_get_shouts_with_limit(self):
        """ Testing Album shouts with limit parameter """
        shouts = self.album.get_shouts(limit=1)
        self.utils.assert_response_content(shouts)
        del shouts['shouts']['@attr']
        assert_equal(len(shouts['shouts']), 1)

    def test_get_shouts_with_page(self):
        """ Testing Album shouts with page parameter """
        shouts = self.album.get_shouts(page=2)
        self.utils.assert_response_content(shouts)
        assert_equal(shouts['shouts']['@attr']['page'], '2')

    def test_get_tags(self):
        """ Testing Album tags """
        auth = Auth(mysession)
        tags = self.album.get_tags(auth=auth)
        self.utils.assert_response_content(tags)
        assert_in("name", tags['tags']['tag'])

    def test_get_tags_with_user(self):
        """ Testing Album tags with username """
        tags = self.album.get_tags(user="******")
        self.utils.assert_response_content(tags)
        del tags['tags']['@attr']
        assert_equal(len(tags['tags']), 1)

    def test_get_top_tags(self):
        """ Testing Album top tags """
        tags = self.album.get_top_tags(correct=True)
        self.utils.assert_response_content(tags)
        assert_in("name", tags['toptags']['tag'][0])

    def test_remove_tag(self):
        """ Testing Album remove tag """
        auth = Auth(mysession)
        tag = self.album.remove_tag(tag="api test", auth=auth)
        self.utils.assert_response_content(tag)

    def test_search(self):
        """ Testing Album search """
        result = Album.search(album="the st")
        self.utils.assert_response_content(result)

    def test_search_limit(self):
        """ Testing Album search with limit parameter """
        result = Album.search(album="the st", limit=5)
        self.utils.assert_response_content(result)

    def test_search_page(self):
        """ Testing Album search with page parameter """
        result = Album.search(album="the st", page=2)
        self.utils.assert_response_content(result)

    def test_share(self):
        """ Testing Album share """
        auth = Auth(mysession)
        share = self.album.share(recipient="lastfm",
                                 message="api test",
                                 public=True,
                                 auth=auth)

        self.utils.assert_response_content(share)
        assert_equal(share['status'], 'ok')

    @raises(Exception)
    def test_share_with_no_auth(self):
        """ Testing Album share with no auth object """
        self.album.share(recipient="lastfm", message="api test", public=True)

    @raises(Exception)
    def test_share_with_no_recipient(self):
        """ Testing Album share with no recipient """
        self.album.share(message="api test", public=True)
Exemplo n.º 8
0
 def setup(self):
     self.event = Event(3388376)
     self.utils = Utils()
Exemplo n.º 9
0
 def setup(self):
     self.utils = Utils()
     self.chart = Chart()
Exemplo n.º 10
0
 def setup(self):
     self.artist = Artist("the strokes")
     self.utils = Utils()
Exemplo n.º 11
0
class TestEvent:

    def __init__(self):
        self.event = None
        self.utils = None

    def setup(self):
        self.event = Event(3388376)
        self.utils = Utils()

    def test_attend(self):
        """ Testing Event attend """
        auth = Auth(mysession)
        event = self.event.attend(status=Event.ATTENDING, auth=auth)
        self.utils.assert_response_content(event)

    @raises(Exception)
    def test_attend_with_no_status(self):
        """ Testing Event attend with no status parameter """
        self.event.attend()

    @raises(Exception)
    def test_attend_with_invalid_status(self):
        """ Testing Event attend with invalid status """
        self.event.attend(status=3)

    @raises(Exception)
    def test_attend_with_no_auth(self):
        """ Testing Event attend with no auth object """
        self.event.attend(status=Event.ATTENDING)

    def test_get_attendees(self):
        """ Testing Event get attendees """
        attendees = self.event.get_attendees(page=0, limit=1)
        self.utils.assert_response_content(attendees)
        assert_equal(attendees['attendees']['@attr']['page'], "1")
        del attendees['attendees']['@attr']
        assert_equal(len(attendees['attendees']), 1)

    def test_get_info(self):
        """ Testing Event get info """
        event = self.event.get_info()
        self.utils.assert_response_content(event)
        assert_equal(event['event']['id'], unicode(self.event.get_event()))

    def test_get_shouts(self):
        """ Testing Event get shouts """
        shouts = self.event.get_shouts()
        self.utils.assert_response_content(shouts)
        assert_in("shouts", shouts)

    def test_share(self):
        """ Testing Event share """
        auth = Auth(mysession)
        message = "testing api event share"
        share = self.event.share(public=False, message=message,
                                 recipient="lastfm", auth=auth)
        self.utils.assert_response_content(share)

    @raises(Exception)
    def test_share_with_no_auth(self):
        """ Testing Event share with no auth """
        self.event.share(recipient="lastfm")

    def test_shout(self):
        """ Testing Event shout """
        auth = Auth(mysession)
        message = "More one api test"
        shout = self.event.shout(message=message, auth=auth)
        self.utils.assert_response_content(shout)

    @raises(Exception)
    def test_shout_with_no_message(self):
        """ Testing Event shout with no message """
        self.event.shout()

    @raises(Exception)
    def test_shout_with_no_auth(self):
        """ Testing Event Shout with no auth """
        message = "api test"
        self.event.shout(message=message)
Exemplo n.º 12
0
class TestArtist():
    """ Tests the Artist class """
    def __init__(self):
        self.artist = None
        self.utils = None

    def setup(self):
        self.artist = Artist("the strokes")
        self.utils = Utils()

    @raises(Exception)
    def test_object_exception(self):
        """ Testing Artist object creation failure """
        self.artist = Artist()

    def test_add_tags(self):
        """ Testing Artist add tags """
        tag = u'test api'
        auth = Auth(mysession)
        tags = self.artist.add_tags(tags=tag, auth=auth)
        self.utils.assert_response_content(tags)
        assert_equal(tags['status'], 'ok')
        tags = self.artist.get_tags(auth=auth)
        assert_equal(tags['tags']['tag']['name'], tag)

    @raises(Exception)
    def test_add_tag_with_no_auth(self):
        """ Testing Artist add tag with no auth parameter """
        self.artist.get_tags(tags='test api')

    def test_corrections(self):
        """ Testing Artist correction """
        correction = self.artist.get_correction()
        self.utils.assert_response_content(correction)

    def test_events(self):
        """ Testing Artist events """
        events = self.artist.get_events()
        self.utils.assert_response_content(events)

    def test_events_correction(self):
        """ Testing Artist events with correction parameter """
        events = self.artist.get_events(correct=True)
        self.utils.assert_response_content(events)

    def test_events_limit(self):
        """ Testing Artist events with limit parameter"""
        events = self.artist.get_events(limit=2)
        self.utils.assert_response_content(events)

    def test_events_page(self):
        """ Testing Artist events with page parameter """
        events = self.artist.get_events(page=1)
        self.utils.assert_response_content(events)

    def test_events_festivalsonly(self):
        """ Testing Artist events with festivalsonly parameter """
        events = self.artist.get_events(festivals=True)
        self.utils.assert_response_content(events)

    def test_info(self):
        """ Testing Artist info """
        info = self.artist.get_info()
        self.utils.assert_response_content(info)

    def test_info_lang(self):
        """ Testing Artist info with lang parameter """
        # portuguese language in ISO 639 alpha-2 code
        info = self.artist.get_info(lang='por')
        self.utils.assert_response_content(info)
        # there is no Artist biography in portuguese
        assert_equal(len(info['artist']['bio']['content']), 0)

    def test_info_autocorrect(self):
        """ Testing Artist info with correction """
        self.artist = Artist("the stroke")
        info = self.artist.get_info(correct=True)
        self.utils.assert_response_content(info)
        assert_equal(info['artist']['name'], u"The Strokes")

    def test_info_username(self):
        """ Testing Artist info with username parameter """
        info = self.artist.get_info(username="******")
        self.utils.assert_response_content(info)
        assert_in('userplaycount', info['artist']['stats'])

    def test_past_events(self):
        """ Testing Artist past events """
        past_events = self.artist.get_past_events()
        self.utils.assert_response_content(past_events)
        assert_in('event', past_events['events'])

    def test_past_events_page(self):
        """ Testing Artist past events with page parameter """
        past_events = self.artist.get_past_events(page=2)
        self.utils.assert_response_content(past_events)
        assert_in('event', past_events['events'])

    def test_past_events_correct(self):
        """ Testing Artist past event with correct parameter """
        self.artist = Artist("the stroke")
        past_events = self.artist.get_past_events(correct=True)
        self.utils.assert_response_content(past_events)
        assert_in(u"The Strokes", past_events['events']['@attr']['artist'])

    def test_past_events_limit(self):
        """ Testing Artist past event with limit parameter """
        past_events = self.artist.get_past_events(limit=1)
        self.utils.assert_response_content(past_events)
        del past_events['events']['@attr']
        assert_equal(len(past_events), 1)

    def test_podcast(self):
        """ Testing Artist podcast """
        podcast = self.artist.get_podcast()
        self.utils.assert_response_content(podcast)

    def test_podcast_correct(self):
        """ Testing Artist podcast with correct parameter """
        self.artist = Artist('The stroke')
        podcast = self.artist.get_podcast(correct=True)
        self.utils.assert_response_content(podcast)

    def test_shouts(self):
        """ Testing Artist shouts """
        shouts = self.artist.get_shouts()
        self.utils.assert_response_content(shouts)

    def test_shouts_limit(self):
        """ Testing Artist shouts with limit parameter """
        shouts = self.artist.get_shouts(limit=1)
        self.utils.assert_response_content(shouts)
        del shouts['shouts']['@attr']
        assert_equal(len(shouts['shouts']), 1)

    def test_shouts_page(self):
        """ Testing Artist shouts with page parameter """
        shouts = self.artist.get_shouts(page=2)
        self.utils.assert_response_content(shouts)
        assert_equal(shouts['shouts']['@attr']['page'], "2")

    def test_shouts_correct(self):
        """ Testing Artist shouts with correct parameter """
        self.artist = Artist("the stroke")
        shouts = self.artist.get_shouts(correct=True)
        self.utils.assert_response_content(shouts)
        assert_equal(u"The Strokes", shouts['shouts']['@attr']['artist'])

    def test_similar_artists(self):
        """ Testing similar artists """
        artists = self.artist.get_similar()
        self.utils.assert_response_content(artists)

    def test_similar_artists_limit(self):
        """ Testing similar artists with limit """
        artists = self.artist.get_similar(limit=2)
        self.utils.assert_response_content(artists)
        assert_in('similarartists', artists)
        assert_equal(len(artists['similarartists']), 2)

    def test_tags(self):
        """ Testing Artist tags """
        tags = self.artist.get_tags(user='******')
        self.utils.assert_response_content(tags)

    def test_tags_no_user(self):
        """ Testing Artist tags with no user """
        auth = Auth(mysession)
        tags = self.artist.get_tags(auth=auth)
        self.utils.assert_response_content(tags)

    @raises(Exception)
    def test_tag_invalid_request(self):
        """ Testing Artist tags failure """
        self.artist.get_tags()

    def test_top_albums(self):
        """ Testing Artist top albums """
        albums = self.artist.get_top_albums()
        self.utils.assert_response_content(albums)

    def test_top_albums_limit(self):
        """ Testing Artist top albums with limit parameter """
        albums = self.artist.get_top_albums(limit=2)
        self.utils.assert_response_content(albums)

    def test_top_albums_page(self):
        """ Testing Artist top albums with page parameter """
        albums = self.artist.get_top_albums(page=2)
        self.utils.assert_response_content(albums)

    def test_top_albums_correction(self):
        """ Testing Artist top albums with correction parameter """
        albums = self.artist.get_top_albums(correct=True)
        self.utils.assert_response_content(albums)

    def test_top_fans(self):
        """ Testing Artist top fans """
        fans = self.artist.get_top_fans()
        self.utils.assert_response_content(fans)

    def test_top_fans_correction(self):
        """ Testing Artist top fans with correction parameter """
        fans = self.artist.get_top_fans(correct=True)
        self.utils.assert_response_content(fans)

    def test_top_tags(self):
        """ Testing Artist top tags """
        tags = self.artist.get_top_tags()
        self.utils.assert_response_content(tags)

    def test_top_tags_correction(self):
        """ Testing Artist top tags with correction parameter """
        tags = self.artist.get_top_tags(correct=True)
        self.utils.assert_response_content(tags)

    def test_top_tracks(self):
        """ Testing Artist top tracks """
        tracks = self.artist.get_top_tracks()
        self.utils.assert_response_content(tracks)

    def test_top_tracks_limit(self):
        """ Testing Artist top tracks with limit parameter """
        tracks = self.artist.get_top_tracks(limit=3)
        self.utils.assert_response_content(tracks)

    def test_top_tracks_page(self):
        """ Testing Artist top tracks with page parameter """
        tracks = self.artist.get_top_tracks(page=2)
        self.utils.assert_response_content(tracks)

    def test_top_tracks_correct(self):
        """ Testing Artist top tracks with correct parameter """
        tracks = self.artist.get_top_tracks(correct=True)
        self.utils.assert_response_content(tracks)

    def test_remove_tags(self):
        """ Testing Artist add tags """
        tag = u'test api'
        auth = Auth(mysession)
        tags = self.artist.remove_tag(tag=tag, auth=auth)
        self.utils.assert_response_content(tags)
        assert_equal(tags['status'], 'ok')

    def test_search(self):
        """ Testing Artist search """
        result = Artist.search(artist="the st")
        self.utils.assert_response_content(result)

    def test_search_limit(self):
        """ Testing Artist search with limit parameter """
        result = Artist.search(artist="the st", limit=5)
        self.utils.assert_response_content(result)

    def test_search_page(self):
        """ Testing Artist search with page parameter """
        result = Artist.search(artist="the st", page=2)
        self.utils.assert_response_content(result)

    def test_artist_share(self):
        """ Testing Artist share """
        auth = Auth(mysession)
        share = self.artist.share(recipient="lastfm",
                                  message="api test",
                                  public=True,
                                  auth=auth)

        self.utils.assert_response_content(share)
        assert_equal(share['status'], 'ok')

    @raises(Exception)
    def test_exception_on_shout(self):
        """ Testing Artist shout with no message """
        self.artist.shout()

    def test_post_shout(self):
        """ Testing Artist shout """
        auth = Auth(mysession)
        shout = self.artist.shout(message="nice Indie rock band", auth=auth)
        self.utils.assert_response_content(shout)
        assert_equal(shout['status'], 'ok')
Exemplo n.º 13
0
 def setup(self):
     self.artist = Artist("the strokes")
     self.utils = Utils()
Exemplo n.º 14
0
class TestArtist():
    """ Tests the Artist class """

    def __init__(self):
        self.artist = None
        self.utils = None

    def setup(self):
        self.artist = Artist("the strokes")
        self.utils = Utils()

    @raises(Exception)
    def test_object_exception(self):
        """ Testing Artist object creation failure """
        self.artist = Artist()

    def test_add_tags(self):
        """ Testing Artist add tags """
        tag = u'test api'
        auth = Auth(mysession)
        tags = self.artist.add_tags(tags=tag, auth=auth)
        self.utils.assert_response_content(tags)
        assert_equal(tags['status'], 'ok')
        tags = self.artist.get_tags(auth=auth)
        assert_equal(tags['tags']['tag']['name'], tag)

    @raises(Exception)
    def test_add_tag_with_no_auth(self):
        """ Testing Artist add tag with no auth parameter """
        self.artist.get_tags(tags='test api')

    def test_corrections(self):
        """ Testing Artist correction """
        correction = self.artist.get_correction()
        self.utils.assert_response_content(correction)

    def test_events(self):
        """ Testing Artist events """
        events = self.artist.get_events()
        self.utils.assert_response_content(events)

    def test_events_correction(self):
        """ Testing Artist events with correction parameter """
        events = self.artist.get_events(correct=True)
        self.utils.assert_response_content(events)

    def test_events_limit(self):
        """ Testing Artist events with limit parameter"""
        events = self.artist.get_events(limit=2)
        self.utils.assert_response_content(events)

    def test_events_page(self):
        """ Testing Artist events with page parameter """
        events = self.artist.get_events(page=1)
        self.utils.assert_response_content(events)

    def test_events_festivalsonly(self):
        """ Testing Artist events with festivalsonly parameter """
        events = self.artist.get_events(festivals=True)
        self.utils.assert_response_content(events)

    def test_info(self):
        """ Testing Artist info """
        info = self.artist.get_info()
        self.utils.assert_response_content(info)

    def test_info_lang(self):
        """ Testing Artist info with lang parameter """
        # portuguese language in ISO 639 alpha-2 code
        info = self.artist.get_info(lang='por')
        self.utils.assert_response_content(info)
        # there is no Artist biography in portuguese
        assert_equal(len(info['artist']['bio']['content']), 0)

    def test_info_autocorrect(self):
        """ Testing Artist info with correction """
        self.artist = Artist("the stroke")
        info = self.artist.get_info(correct=True)
        self.utils.assert_response_content(info)
        assert_equal(info['artist']['name'], u"The Strokes")

    def test_info_username(self):
        """ Testing Artist info with username parameter """
        info = self.artist.get_info(username="******")
        self.utils.assert_response_content(info)
        assert_in('userplaycount', info['artist']['stats'])

    def test_past_events(self):
        """ Testing Artist past events """
        past_events = self.artist.get_past_events()
        self.utils.assert_response_content(past_events)
        assert_in('event', past_events['events'])

    def test_past_events_page(self):
        """ Testing Artist past events with page parameter """
        past_events = self.artist.get_past_events(page=2)
        self.utils.assert_response_content(past_events)
        assert_in('event', past_events['events'])

    def test_past_events_correct(self):
        """ Testing Artist past event with correct parameter """
        self.artist = Artist("the stroke")
        past_events = self.artist.get_past_events(correct=True)
        self.utils.assert_response_content(past_events)
        assert_in(u"The Strokes", past_events['events']['@attr']['artist'])

    def test_past_events_limit(self):
        """ Testing Artist past event with limit parameter """
        past_events = self.artist.get_past_events(limit=1)
        self.utils.assert_response_content(past_events)
        del past_events['events']['@attr']
        assert_equal(len(past_events), 1)

    def test_podcast(self):
        """ Testing Artist podcast """
        podcast = self.artist.get_podcast()
        self.utils.assert_response_content(podcast)

    def test_podcast_correct(self):
        """ Testing Artist podcast with correct parameter """
        self.artist = Artist('The stroke')
        podcast = self.artist.get_podcast(correct=True)
        self.utils.assert_response_content(podcast)

    def test_shouts(self):
        """ Testing Artist shouts """
        shouts = self.artist.get_shouts()
        self.utils.assert_response_content(shouts)

    def test_shouts_limit(self):
        """ Testing Artist shouts with limit parameter """
        shouts = self.artist.get_shouts(limit=1)
        self.utils.assert_response_content(shouts)
        del shouts['shouts']['@attr']
        assert_equal(len(shouts['shouts']), 1)

    def test_shouts_page(self):
        """ Testing Artist shouts with page parameter """
        shouts = self.artist.get_shouts(page=2)
        self.utils.assert_response_content(shouts)
        assert_equal(shouts['shouts']['@attr']['page'], "2")

    def test_shouts_correct(self):
        """ Testing Artist shouts with correct parameter """
        self.artist = Artist("the stroke")
        shouts = self.artist.get_shouts(correct=True)
        self.utils.assert_response_content(shouts)
        assert_equal(u"The Strokes", shouts['shouts']['@attr']['artist'])

    def test_similar_artists(self):
        """ Testing similar artists """
        artists = self.artist.get_similar()
        self.utils.assert_response_content(artists)

    def test_similar_artists_limit(self):
        """ Testing similar artists with limit """
        artists = self.artist.get_similar(limit=2)
        self.utils.assert_response_content(artists)
        assert_in('similarartists', artists)
        assert_equal(len(artists['similarartists']), 2)

    def test_tags(self):
        """ Testing Artist tags """
        tags = self.artist.get_tags(user='******')
        self.utils.assert_response_content(tags)

    def test_tags_no_user(self):
        """ Testing Artist tags with no user """
        auth = Auth(mysession)
        tags = self.artist.get_tags(auth=auth)
        self.utils.assert_response_content(tags)

    @raises(Exception)
    def test_tag_invalid_request(self):
        """ Testing Artist tags failure """
        self.artist.get_tags()

    def test_top_albums(self):
        """ Testing Artist top albums """
        albums = self.artist.get_top_albums()
        self.utils.assert_response_content(albums)

    def test_top_albums_limit(self):
        """ Testing Artist top albums with limit parameter """
        albums = self.artist.get_top_albums(limit=2)
        self.utils.assert_response_content(albums)

    def test_top_albums_page(self):
        """ Testing Artist top albums with page parameter """
        albums = self.artist.get_top_albums(page=2)
        self.utils.assert_response_content(albums)

    def test_top_albums_correction(self):
        """ Testing Artist top albums with correction parameter """
        albums = self.artist.get_top_albums(correct=True)
        self.utils.assert_response_content(albums)

    def test_top_fans(self):
        """ Testing Artist top fans """
        fans = self.artist.get_top_fans()
        self.utils.assert_response_content(fans)

    def test_top_fans_correction(self):
        """ Testing Artist top fans with correction parameter """
        fans = self.artist.get_top_fans(correct=True)
        self.utils.assert_response_content(fans)

    def test_top_tags(self):
        """ Testing Artist top tags """
        tags = self.artist.get_top_tags()
        self.utils.assert_response_content(tags)

    def test_top_tags_correction(self):
        """ Testing Artist top tags with correction parameter """
        tags = self.artist.get_top_tags(correct=True)
        self.utils.assert_response_content(tags)

    def test_top_tracks(self):
        """ Testing Artist top tracks """
        tracks = self.artist.get_top_tracks()
        self.utils.assert_response_content(tracks)

    def test_top_tracks_limit(self):
        """ Testing Artist top tracks with limit parameter """
        tracks = self.artist.get_top_tracks(limit=3)
        self.utils.assert_response_content(tracks)

    def test_top_tracks_page(self):
        """ Testing Artist top tracks with page parameter """
        tracks = self.artist.get_top_tracks(page=2)
        self.utils.assert_response_content(tracks)

    def test_top_tracks_correct(self):
        """ Testing Artist top tracks with correct parameter """
        tracks = self.artist.get_top_tracks(correct=True)
        self.utils.assert_response_content(tracks)

    def test_remove_tags(self):
        """ Testing Artist add tags """
        tag = u'test api'
        auth = Auth(mysession)
        tags = self.artist.remove_tag(tag=tag, auth=auth)
        self.utils.assert_response_content(tags)
        assert_equal(tags['status'], 'ok')

    def test_search(self):
        """ Testing Artist search """
        result = Artist.search(artist="the st")
        self.utils.assert_response_content(result)

    def test_search_limit(self):
        """ Testing Artist search with limit parameter """
        result = Artist.search(artist="the st", limit=5)
        self.utils.assert_response_content(result)

    def test_search_page(self):
        """ Testing Artist search with page parameter """
        result = Artist.search(artist="the st", page=2)
        self.utils.assert_response_content(result)

    def test_artist_share(self):
        """ Testing Artist share """
        auth = Auth(mysession)
        share = self.artist.share(recipient="lastfm", message="api test",
                                  public=True, auth=auth)

        self.utils.assert_response_content(share)
        assert_equal(share['status'], 'ok')

    @raises(Exception)
    def test_exception_on_shout(self):
        """ Testing Artist shout with no message """
        self.artist.shout()

    def test_post_shout(self):
        """ Testing Artist shout """
        auth = Auth(mysession)
        shout = self.artist.shout(message="nice Indie rock band", auth=auth)
        self.utils.assert_response_content(shout)
        assert_equal(shout['status'], 'ok')
Exemplo n.º 15
0
    def setup(self):

        self.artist = Artist("Foo fighters")
        self.auth = Auth(mysession)
        self.album = Album(artist=self.artist, album="Wasting Light")
        self.utils = Utils()
Exemplo n.º 16
0
class TestAlbum:

    def __init__(self):
        self.artist = None
        self.auth = None
        self.album = None
        self.utils = None

    def setup(self):

        self.artist = Artist("Foo fighters")
        self.auth = Auth(mysession)
        self.album = Album(artist=self.artist, album="Wasting Light")
        self.utils = Utils()

    @raises(Exception)
    def test_album_with_no_artist(self):
        """ Testing Album with no artist """
        self.album = Album(album="Wasting Light")

    @raises(Exception)
    def test_album_with_no_album(self):
        """ Testing Album with no album name """
        self.album = Album(artist=self.artist)

    def test_add_tags(self):
        """ Testing Album add tags  """
        tags = self.album.add_tags(tags="api test", auth=self.auth)
        self.utils.assert_response_content(tags)

    @raises(Exception)
    def test_add_tags_with_no_auth(self):
        """ Testing Album add tags with no auth object """
        self.album.add_tags(tags="api test")

    def test_get_buy_links(self):
        """ Testing Album buy links """
        buy_links = self.album.get_buy_links(country="Brazil", correct=True)
        self.utils.assert_response_content(buy_links)
        assert_greater(buy_links['affiliations'], 0)

    def test_get_info(self):
        """ Testing Album information """
        info = self.album.get_info()
        self.utils.assert_response_content(info)
        assert_in("name", info['album'])

    def test_get_info_with_username(self):
        """ Testing Album information with username parameter """
        info = self.album.get_info(username="******")
        self.utils.assert_response_content(info)
        assert_in('userplaycount', info['album'])

    def test_get_info_with_lang(self):
        """ Testing Album information with language parameter """
        info = self.album.get_info(lang="por")
        self.utils.assert_response_content(info)

    def test_get_shouts(self):
        """ Testing Album shouts """
        shouts = self.album.get_shouts()
        self.utils.assert_response_content(shouts)

    def test_get_shouts_with_limit(self):
        """ Testing Album shouts with limit parameter """
        shouts = self.album.get_shouts(limit=1)
        self.utils.assert_response_content(shouts)
        del shouts['shouts']['@attr']
        assert_equal(len(shouts['shouts']), 1)

    def test_get_shouts_with_page(self):
        """ Testing Album shouts with page parameter """
        shouts = self.album.get_shouts(page=2)
        self.utils.assert_response_content(shouts)
        assert_equal(shouts['shouts']['@attr']['page'], '2')

    def test_get_tags(self):
        """ Testing Album tags """
        auth = Auth(mysession)
        tags = self.album.get_tags(auth=auth)
        self.utils.assert_response_content(tags)
        assert_in("name", tags['tags']['tag'])

    def test_get_tags_with_user(self):
        """ Testing Album tags with username """
        tags = self.album.get_tags(user="******")
        self.utils.assert_response_content(tags)
        del tags['tags']['@attr']
        assert_equal(len(tags['tags']), 1)

    def test_get_top_tags(self):
        """ Testing Album top tags """
        tags = self.album.get_top_tags(correct=True)
        self.utils.assert_response_content(tags)
        assert_in("name", tags['toptags']['tag'][0])

    def test_remove_tag(self):
        """ Testing Album remove tag """
        auth = Auth(mysession)
        tag = self.album.remove_tag(tag="api test", auth=auth)
        self.utils.assert_response_content(tag)

    def test_search(self):
        """ Testing Album search """
        result = Album.search(album="the st")
        self.utils.assert_response_content(result)

    def test_search_limit(self):
        """ Testing Album search with limit parameter """
        result = Album.search(album="the st", limit=5)
        self.utils.assert_response_content(result)

    def test_search_page(self):
        """ Testing Album search with page parameter """
        result = Album.search(album="the st", page=2)
        self.utils.assert_response_content(result)

    def test_share(self):
        """ Testing Album share """
        auth = Auth(mysession)
        share = self.album.share(recipient="lastfm", message="api test",
                                 public=True, auth=auth)

        self.utils.assert_response_content(share)
        assert_equal(share['status'], 'ok')

    @raises(Exception)
    def test_share_with_no_auth(self):
        """ Testing Album share with no auth object """
        self.album.share(recipient="lastfm", message="api test",
                         public=True)

    @raises(Exception)
    def test_share_with_no_recipient(self):
        """ Testing Album share with no recipient """
        self.album.share(message="api test", public=True)