Commit dcb66690 authored by Eliot Berriot's avatar Eliot Berriot 💬

Fixed #7: store release-group id on Album

parent 4c9469ac
Pipeline #267 passed with stage
in 47 seconds
Changelog
=========
0.2.4 (unreleased)
------------------
Models: now store relese group mbid on Album model (#7)
# -*- coding: utf-8 -*-
# Generated by Django 1.11 on 2017-12-13 22:11
from __future__ import unicode_literals
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('music', '0012_auto_20161122_1905'),
]
operations = [
migrations.AlterModelOptions(
name='importjob',
options={'ordering': ('id',)},
),
migrations.AlterModelOptions(
name='track',
options={'ordering': ['album', 'position']},
),
migrations.AddField(
model_name='album',
name='release_group_id',
field=models.UUIDField(blank=True, null=True),
),
]
......@@ -110,13 +110,14 @@ class Album(APIModelMixin):
title = models.CharField(max_length=255)
artist = models.ForeignKey(Artist, related_name='albums')
release_date = models.DateField(null=True)
release_group_id = models.UUIDField(null=True, blank=True)
cover = VersatileImageField(upload_to='albums/covers/%Y/%m/%d', null=True, blank=True)
TYPE_CHOICES = (
('album', 'Album'),
)
type = models.CharField(choices=TYPE_CHOICES, max_length=30, default='album')
api_includes = ['artist-credits', 'recordings', 'media']
api_includes = ['artist-credits', 'recordings', 'media', 'release-groups']
api = musicbrainz.api.releases
musicbrainz_model = 'release'
musicbrainz_mapping = {
......@@ -127,6 +128,10 @@ class Album(APIModelMixin):
'musicbrainz_field_name': 'release-list',
'converter': lambda v: int(v[0]['medium-list'][0]['position']),
},
'release_group_id': {
'musicbrainz_field_name': 'release-group',
'converter': lambda v: v['id'],
},
'title': {
'musicbrainz_field_name': 'title',
},
......
......@@ -18,6 +18,7 @@ class AlbumFactory(factory.django.DjangoModelFactory):
release_date = factory.Faker('date')
cover = factory.django.ImageField()
artist = factory.SubFactory(ArtistFactory)
release_group_id = factory.Faker('uuid4')
class Meta:
model = 'music.Album'
......
import pytest
from funkwhale_api.music import models
from funkwhale_api.music import importers
from . import factories
def test_can_store_release_group_id_on_album(db):
album = factories.AlbumFactory()
assert album.release_group_id is not None
def test_import_album_stores_release_group(db):
album_data = {
"artist-credit": [
{
"artist": {
"disambiguation": "George Shaw",
"id": "62c3befb-6366-4585-b256-809472333801",
"name": "Adhesive Wombat",
"sort-name": "Wombat, Adhesive"
}
}
],
"artist-credit-phrase": "Adhesive Wombat",
"country": "XW",
"date": "2013-06-05",
"id": "a50d2a81-2a50-484d-9cb4-b9f6833f583e",
"status": "Official",
"title": "Marsupial Madness",
'release-group': {'id': '447b4979-2178-405c-bfe6-46bf0b09e6c7'}
}
artist = factories.ArtistFactory(
mbid=album_data['artist-credit'][0]['artist']['id']
)
cleaned_data = models.Album.clean_musicbrainz_data(album_data)
album = importers.load(models.Album, cleaned_data, album_data, import_hooks=[])
assert album.release_group_id == album_data['release-group']['id']
assert album.artist == artist
......@@ -33,9 +33,12 @@ services:
- redis
command: python manage.py celery worker
environment:
- C_FORCE_ROOT=true
- "DATABASE_URL=postgresql://postgres@postgres/postgres"
- "CACHE_URL=redis://redis:6379/0"
- "DJANGO_ALLOWED_HOSTS=localhost"
- "DJANGO_SETTINGS_MODULE=config.settings.local"
- "DJANGO_SECRET_KEY=dev"
- C_FORCE_ROOT=true
- "DATABASE_URL=postgresql://postgres@postgres/postgres"
- "CACHE_URL=redis://redis:6379/0"
volumes:
- ./api:/app
- ./data/music:/music
......@@ -49,6 +52,9 @@ services:
- ./api:/app
- ./data/music:/music
environment:
- "DJANGO_ALLOWED_HOSTS=localhost"
- "DJANGO_SETTINGS_MODULE=config.settings.local"
- "DJANGO_SECRET_KEY=dev"
- "DATABASE_URL=postgresql://postgres@postgres/postgres"
- "CACHE_URL=redis://redis:6379/0"
ports:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment