Skip to content

Commit

Permalink
Merge pull request #4047 from bjester/readd-constraint-madness
Browse files Browse the repository at this point in the history
Re-add file duration constraint and re-enable tests
  • Loading branch information
vkWeb authored May 3, 2023
2 parents fbb9809 + 5c61836 commit 1a9b18c
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Generated by Django 3.2.18 on 2023-05-03 15:28
from django.db import migrations
from django.db import models


class Migration(migrations.Migration):

dependencies = [
('contentcuration', '0142_remove_file_file_media_duration_int'),
]

operations = [
migrations.AddConstraint(
model_name='file',
constraint=models.CheckConstraint(check=models.Q(models.Q(('duration__gt', 0), ('preset__in', ['audio', 'audio_dependency', 'high_res_video', 'low_res_video', 'video_dependency'])), ('duration__isnull', True), _connector='OR'), name='file_media_duration_int'),
),
]
9 changes: 6 additions & 3 deletions contentcuration/contentcuration/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -2219,9 +2219,12 @@ class Meta:
models.Index(fields=["-modified"], name=FILE_MODIFIED_DESC_INDEX_NAME),
]
constraints = [
# Commented out to temporarily remove the constraint until we can re-run `set_file_duration`
# on all media files with the dependency preset in the database.
# models.CheckConstraint(check=(Q(preset__in=MEDIA_PRESETS, duration__gt=0) | Q(duration__isnull=True)), name=FILE_DURATION_CONSTRAINT)
# enforces that duration is null when not a media preset, but the duration may be null for media presets
# but if not-null, should be greater than 0
models.CheckConstraint(
check=(Q(preset__in=MEDIA_PRESETS, duration__gt=0) | Q(duration__isnull=True)),
name=FILE_DURATION_CONSTRAINT
)
]


Expand Down
2 changes: 0 additions & 2 deletions contentcuration/contentcuration/tests/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -651,7 +651,6 @@ def test_duration_check_constraint__acceptable(self):
duration=1123123,
)

@pytest.mark.skip(reason="Temporarily removed constraint")
def test_duration_check_constraint__negative(self):
channel = testdata.channel()
with self.assertRaises(IntegrityError, msg=FILE_DURATION_CONSTRAINT):
Expand All @@ -661,7 +660,6 @@ def test_duration_check_constraint__negative(self):
duration=-10,
)

@pytest.mark.skip(reason="Temporarily removed constraint")
def test_duration_check_constraint__not_media(self):
channel = testdata.channel()
with self.assertRaises(IntegrityError, msg=FILE_DURATION_CONSTRAINT):
Expand Down

0 comments on commit 1a9b18c

Please sign in to comment.