Verified Commit 244ebd7a authored by Eliot Berriot's avatar Eliot Berriot
Browse files

Dropped hard constraint on track indexes and added more tests

parent 8ff775a1
# Generated by Django 2.0.3 on 2018-03-19 16:42
# Generated by Django 2.0.3 on 2018-03-20 17:13
from django.db import migrations, models
......@@ -20,4 +20,8 @@ class Migration(migrations.Migration):
name='index',
field=models.PositiveIntegerField(blank=True, null=True),
),
migrations.AlterUniqueTogether(
name='playlisttrack',
unique_together=set(),
),
]
......@@ -44,12 +44,9 @@ def test_can_insert_at_index(factories):
def test_can_insert_and_move(factories):
playlist = factories['playlists.Playlist']()
first = factories['playlists.PlaylistTrack'](playlist=playlist)
second = factories['playlists.PlaylistTrack'](playlist=playlist)
third = factories['playlists.PlaylistTrack'](playlist=playlist)
playlist.insert(first)
playlist.insert(second)
playlist.insert(third)
first = factories['playlists.PlaylistTrack'](playlist=playlist, index=0)
second = factories['playlists.PlaylistTrack'](playlist=playlist, index=1)
third = factories['playlists.PlaylistTrack'](playlist=playlist, index=2)
playlist.insert(second, index=0)
......@@ -62,6 +59,23 @@ def test_can_insert_and_move(factories):
assert first.index == 1
def test_can_insert_and_move_last_to_0(factories):
playlist = factories['playlists.Playlist']()
first = factories['playlists.PlaylistTrack'](playlist=playlist, index=0)
second = factories['playlists.PlaylistTrack'](playlist=playlist, index=1)
third = factories['playlists.PlaylistTrack'](playlist=playlist, index=2)
playlist.insert(third, index=0)
first.refresh_from_db()
second.refresh_from_db()
third.refresh_from_db()
assert third.index == 0
assert first.index == 1
assert second.index == 2
def test_cannot_insert_at_wrong_index(factories):
plt = factories['playlists.PlaylistTrack']()
new = factories['playlists.PlaylistTrack'](playlist=plt.playlist)
......
Supports Markdown
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