Useful conditions can be put in lambdas
and an extra test to asure transcoding with upload is possible
This commit is contained in:
@@ -14,16 +14,17 @@ def create(model: Type[T], **kwargs) -> T:
|
|||||||
return _create_with_defaults(models.Video, kwargs, title='Title', slug='slug', description='Description')
|
return _create_with_defaults(models.Video, kwargs, title='Title', slug='slug', description='Description')
|
||||||
|
|
||||||
if model is models.Transcoding:
|
if model is models.Transcoding:
|
||||||
defaults = dict(
|
def url():
|
||||||
|
# only URL if no upload for they are mutually exclusive
|
||||||
|
if 'upload' not in kwargs:
|
||||||
|
return 'https://some_url'
|
||||||
|
|
||||||
|
return _create_with_defaults(models.Transcoding, kwargs,
|
||||||
video=lambda: create(models.Video),
|
video=lambda: create(models.Video),
|
||||||
quality=models.qualities[0].name,
|
quality=models.qualities[0].name,
|
||||||
type=str(models.transcoding_types[0]),
|
type=str(models.transcoding_types[0]),
|
||||||
|
url=url,
|
||||||
)
|
)
|
||||||
if 'upload' not in kwargs:
|
|
||||||
# only URL if no upload for they are multually exclusive
|
|
||||||
defaults['url'] = 'https://some_url'
|
|
||||||
|
|
||||||
return _create_with_defaults(models.Transcoding, kwargs, **defaults)
|
|
||||||
|
|
||||||
if model is models.Upload:
|
if model is models.Upload:
|
||||||
return _create_with_defaults(models.Upload, kwargs, file=SimpleUploadedFile('some_file.txt', b'some contents'))
|
return _create_with_defaults(models.Upload, kwargs, file=SimpleUploadedFile('some_file.txt', b'some contents'))
|
||||||
|
|||||||
@@ -1,7 +1,9 @@
|
|||||||
|
import os
|
||||||
|
|
||||||
|
from django.core.files.uploadedfile import SimpleUploadedFile
|
||||||
from django.test import TestCase
|
from django.test import TestCase
|
||||||
from videodinges.models import Transcoding, Video
|
from videodinges.models import Transcoding, Video, Upload
|
||||||
from tests.videodinges import factories
|
from tests.videodinges import factories, UploadMixin
|
||||||
from datetime import datetime
|
|
||||||
|
|
||||||
class TranscodingTestCase(TestCase):
|
class TranscodingTestCase(TestCase):
|
||||||
def test_factory_returns_model(self):
|
def test_factory_returns_model(self):
|
||||||
@@ -35,3 +37,19 @@ class TranscodingTestCase(TestCase):
|
|||||||
)
|
)
|
||||||
|
|
||||||
self.assertEquals(Video.objects.all().count(), 1)
|
self.assertEquals(Video.objects.all().count(), 1)
|
||||||
|
|
||||||
|
|
||||||
|
class TranscodingWithUploadTestCase(UploadMixin, TestCase):
|
||||||
|
def test_can_assign_upload(self):
|
||||||
|
transcoding = factories.create(
|
||||||
|
Transcoding,
|
||||||
|
quality='720p',
|
||||||
|
type='video/mp4',
|
||||||
|
video=factories.create(Video, slug='yet-another-video-slug'),
|
||||||
|
upload=factories.create(Upload, file=SimpleUploadedFile('my_upload.txt', b'some_contents'))
|
||||||
|
)
|
||||||
|
|
||||||
|
self.assertTrue(os.path.exists(os.path.join(self.media_root.name, 'my_upload.txt')))
|
||||||
|
with open(os.path.join(self.media_root.name, 'my_upload.txt'), 'rb') as f:
|
||||||
|
self.assertEquals(f.read(), b'some_contents')
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user