Exemple #1
0
def entity(id):
    id = str(id)
    try:
        release_group = mb_release_group.get_release_group_by_id(id)
    except mb_exceptions.NoDataFoundException:
        raise NotFound(
            gettext(
                "Sorry, we couldn't find a release group with that MusicBrainz ID."
            ))

    if 'tag-list' in release_group:
        tags = release_group['tag-list']
    else:
        tags = None
    if 'release-list' in release_group and release_group['release-list']:
        release = mb_release.get_release_by_id(
            release_group['release-list'][0]['id'])
    else:
        release = None
    soundcloud_url = soundcloud.get_url(release_group['id'])
    if soundcloud_url:
        spotify_mappings = None
    else:
        spotify_mappings = mbspotify.mappings(release_group['id'])
    limit = int(request.args.get('limit', default=10))
    offset = int(request.args.get('offset', default=0))
    if current_user.is_authenticated:
        my_reviews, my_count = db_review.list_reviews(
            entity_id=release_group['id'],
            entity_type='release_group',
            user_id=current_user.id,
        )
        if my_count != 0:
            my_review = my_reviews[0]
        else:
            my_review = None
    else:
        my_review = None
    reviews, count = db_review.list_reviews(
        entity_id=release_group['id'],
        entity_type='release_group',
        sort='popularity',
        limit=limit,
        offset=offset,
    )
    avg_rating = get_avg_rating(release_group['id'], "release_group")

    return render_template('release_group/entity.html',
                           id=release_group['id'],
                           release_group=release_group,
                           reviews=reviews,
                           release=release,
                           my_review=my_review,
                           spotify_mappings=spotify_mappings,
                           tags=tags,
                           soundcloud_url=soundcloud_url,
                           limit=limit,
                           offset=offset,
                           count=count,
                           avg_rating=avg_rating)
Exemple #2
0
def entity(id):
    id = str(id)
    release_data = mb_release.get_release_by_id(id)
    if release_data:
        group_id = release_data['release-group']['id']
        url = '/release-group/' + str(group_id)
        return redirect(url, 301)

    raise NotFound(gettext("Sorry, we couldn't find a release with that MusicBrainz ID."))
Exemple #3
0
    def test_release_cache(self, release_fetch, cache_set, cache_get):
        mbid = "16bee711-d7ce-48b0-adf4-51f124bcc0df"
        expected_key = b"release_16bee711-d7ce-48b0-adf4-51f124bcc0df"
        release = {
            "id":
            "16bee711-d7ce-48b0-adf4-51f124bcc0df",
            "name":
            "Numb/Encore",
            "medium-list": [{
                "track_list": [{
                    "id": "dfe024b2-95b2-453f-b03e-3b9fa06f44e6",
                    "name": "Numb/Encore (explicit)",
                    "number": "1",
                    "position": 1,
                    "length": 207000,
                    "recording_id": "daccb724-8023-432a-854c-e0accb6c8678",
                    "recording_title": "Numb/Encore (explicit)"
                }]
            }]
        }
        release_fetch.return_value = {mbid: release}

        cache_get.return_value = None
        get_release_by_id(mbid)

        # Test that first time data is fetched database is queried
        cache_get.assert_called_with(expected_key)
        release_fetch.assert_called_with([mbid],
                                         includes=['media', 'release-groups'],
                                         unknown_entities_for_missing=True)
        cache_set.assert_called_with(key=expected_key,
                                     val=release,
                                     time=DEFAULT_CACHE_EXPIRATION)

        cache_get.return_value = release
        cache_set.reset_mock()
        release_fetch.reset_mock()
        get_release_by_id(mbid)

        # Test that second time data is fetched from cache
        cache_get.assert_called_with(expected_key)
        release_fetch.assert_not_called()
        cache_set.assert_not_called()
def entity(id):
    id = str(id)
    release_data = mb_release.get_release_by_id(id)
    if release_data:
        group_id = release_data['release-group']['id']
        url = '/release-group/' + str(group_id)
        return redirect(url, 301)

    raise NotFound(
        gettext("Sorry, we couldn't find a release with that MusicBrainz ID."))
def entity(id):
    id = str(id)
    try:
        release_group = mb_release_group.get_release_group_by_id(id)
    except mb_exceptions.NoDataFoundException:
        raise NotFound(gettext("Sorry, we couldn't find a release group with that MusicBrainz ID."))

    if 'url-rels' in release_group:
        external_reviews = list(filter(lambda rel: rel['type'] == 'review', release_group['url-rels']))
    else:
        external_reviews = []
    if 'tag-list' in release_group:
        tags = release_group['tag-list']
    else:
        tags = None
    if 'release-list' in release_group and release_group['release-list']:
        release = mb_release.get_release_by_id(release_group['release-list'][0]['id'])
    else:
        release = None
    soundcloud_url = soundcloud.get_url(release_group['id'])
    if soundcloud_url:
        spotify_mappings = None
    else:
        spotify_mappings = mbspotify.mappings(release_group['id'])

    limit = int(request.args.get('limit', default=10))
    offset = int(request.args.get('offset', default=0))
    if current_user.is_authenticated:
        my_reviews, my_count = db_review.list_reviews(
            entity_id=release_group['id'],
            entity_type='release_group',
            user_id=current_user.id,
        )
        my_review = my_reviews[0] if my_count else None
    else:
        my_review = None
    reviews, count = db_review.list_reviews(
        entity_id=release_group['id'],
        entity_type='release_group',
        sort='popularity',
        limit=limit,
        offset=offset,
    )
    avg_rating = get_avg_rating(release_group['id'], "release_group")

    rating_form = RatingEditForm(entity_id=id, entity_type='release_group')
    rating_form.rating.data = my_review['rating'] if my_review else None

    return render_template('release_group/entity.html', id=release_group['id'], release_group=release_group, reviews=reviews,
                           release=release, my_review=my_review, spotify_mappings=spotify_mappings, tags=tags,
                           soundcloud_url=soundcloud_url, external_reviews=external_reviews, limit=limit, offset=offset,
                           count=count, avg_rating=avg_rating, rating_form=rating_form, current_user=current_user)
 def test_get_by_id(self):
     self.release_query.return_value = [release_numb_encore]
     release = mb_release.get_release_by_id('16bee711-d7ce-48b0-adf4-51f124bcc0df')
     self.assertEqual(release["name"], "Numb/Encore")
     self.assertEqual(len(release["medium-list"][0]["track-list"]), 2)
     self.assertDictEqual(release["medium-list"][0]["track-list"][0], {
         "id": "dfe024b2-95b2-453f-b03e-3b9fa06f44e6",
         "name": "Numb/Encore (explicit)",
         "number": "1",
         "position": 1,
         "length": 207000,
         "recording_id": "daccb724-8023-432a-854c-e0accb6c8678",
         "recording_title": "Numb/Encore (explicit)"
     })
 def test_get_by_id(self):
     self.release_query.return_value = [release_numb_encore]
     release = mb_release.get_release_by_id(
         '16bee711-d7ce-48b0-adf4-51f124bcc0df')
     self.assertEqual(release["name"], "Numb/Encore")
     self.assertEqual(len(release["medium-list"][0]["track-list"]), 2)
     self.assertDictEqual(
         release["medium-list"][0]["track-list"][0], {
             "id": "dfe024b2-95b2-453f-b03e-3b9fa06f44e6",
             "name": "Numb/Encore (explicit)",
             "number": "1",
             "position": 1,
             "length": 207000,
             "recording_id": "daccb724-8023-432a-854c-e0accb6c8678",
             "recording_title": "Numb/Encore (explicit)"
         })