Fix bug in unique tracks on different albums
This commit is contained in:
19
.drone.yml
19
.drone.yml
@ -8,7 +8,7 @@ name: run_tests
|
||||
|
||||
steps:
|
||||
# Run tests against Python/Flask engine backend (with pytest)
|
||||
- name: coverage
|
||||
- name: pytest with coverage
|
||||
image: python:3.10.4
|
||||
commands:
|
||||
# Install dependencies
|
||||
@ -16,22 +16,7 @@ steps:
|
||||
- pip install poetry
|
||||
- poetry install
|
||||
# Start with a fresh database (which is already running as a service from Drone)
|
||||
- poetry run pytest --cov-report term --cov=vrobbler tests
|
||||
environment:
|
||||
VROBBLER_DATABASE_URL: sqlite:///test.db
|
||||
volumes:
|
||||
# Mount pip cache from host
|
||||
- name: pip_cache
|
||||
path: /root/.cache/pip
|
||||
- name: pytest
|
||||
image: python:3.10.4
|
||||
commands:
|
||||
# Install dependencies
|
||||
- cp vrobbler.conf.test vrobbler.conf
|
||||
- pip install poetry
|
||||
- poetry install
|
||||
# Start with a fresh database (which is already running as a service from Drone)
|
||||
- poetry run pytest
|
||||
- poetry run pytest --cov-report term:skip-covered --cov=vrobbler tests
|
||||
environment:
|
||||
VROBBLER_DATABASE_URL: sqlite:///test.db
|
||||
volumes:
|
||||
|
||||
@ -39,8 +39,16 @@ class MopidyRequest:
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def mopidy_track_request_data(**kwargs):
|
||||
return MopidyRequest(**kwargs).request_json
|
||||
def mopidy_track_request_data():
|
||||
return MopidyRequest().request_json
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def mopidy_track_diff_album_request_data(**kwargs):
|
||||
mb_album_id = "0c56c457-afe1-4679-baab-759ba8dd2a58"
|
||||
return MopidyRequest(
|
||||
album="Gold", musicbrainz_album_id=mb_album_id
|
||||
).request_json
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
|
||||
@ -38,6 +38,31 @@ def test_scrobble_mopidy_track(client, mopidy_track_request_data):
|
||||
assert scrobble.media_obj.title == "Same in the End"
|
||||
|
||||
|
||||
@pytest.mark.django_db
|
||||
def test_scrobble_mopidy_same_track_different_album(
|
||||
client, mopidy_track_request_data, mopidy_track_diff_album_request_data
|
||||
):
|
||||
url = reverse('scrobbles:mopidy-websocket')
|
||||
response = client.post(
|
||||
url, mopidy_track_request_data, content_type='application/json'
|
||||
)
|
||||
assert response.status_code == 200
|
||||
assert response.data == {'scrobble_id': 1}
|
||||
scrobble = Scrobble.objects.get(id=1)
|
||||
assert scrobble.media_obj.album.name == "Sublime"
|
||||
|
||||
response = client.post(
|
||||
url,
|
||||
mopidy_track_diff_album_request_data,
|
||||
content_type='application/json',
|
||||
)
|
||||
|
||||
scrobble = Scrobble.objects.get(id=2)
|
||||
assert scrobble.media_obj.__class__ == Track
|
||||
assert scrobble.media_obj.album.name == "Gold"
|
||||
assert scrobble.media_obj.title == "Same in the End"
|
||||
|
||||
|
||||
@pytest.mark.django_db
|
||||
def test_scrobble_mopidy_podcast(client, mopidy_podcast_request_data):
|
||||
url = reverse('scrobbles:mopidy-websocket')
|
||||
|
||||
@ -0,0 +1,22 @@
|
||||
# Generated by Django 4.1.5 on 2023-01-19 20:03
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('music', '0008_alter_track_options'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AlterField(
|
||||
model_name='track',
|
||||
name='musicbrainz_id',
|
||||
field=models.CharField(blank=True, max_length=255, null=True),
|
||||
),
|
||||
migrations.AlterUniqueTogether(
|
||||
name='track',
|
||||
unique_together={('album', 'musicbrainz_id')},
|
||||
),
|
||||
]
|
||||
@ -103,7 +103,10 @@ class Track(ScrobblableMixin):
|
||||
|
||||
artist = models.ForeignKey(Artist, on_delete=models.DO_NOTHING)
|
||||
album = models.ForeignKey(Album, on_delete=models.DO_NOTHING, **BNULL)
|
||||
musicbrainz_id = models.CharField(max_length=255, unique=True, **BNULL)
|
||||
musicbrainz_id = models.CharField(max_length=255, **BNULL)
|
||||
|
||||
class Meta:
|
||||
unique_together = [['album', 'musicbrainz_id']]
|
||||
|
||||
def __str__(self):
|
||||
return f"{self.title} by {self.artist}"
|
||||
|
||||
Reference in New Issue
Block a user