Updated tests

This commit is contained in:
Erik Thuning 2022-10-20 09:37:27 +02:00
parent a6c714de33
commit eca8caedf1

141
test.py

@ -19,8 +19,10 @@ from pipeline.utils import raise_for_structure, canonical_manifest
filesdir = 'testfiles'
configfile = 'config.ini'
videosubdir = 'video'
imagesubdir = 'image'
subsglob = path.join(filesdir, '*.vtt')
videoglob = path.join(filesdir, videosubdir, '*')
imageglob = path.join(filesdir, imagesubdir, '*')
class DaemonTest(unittest.TestCase):
@ -44,11 +46,12 @@ class DaemonTest(unittest.TestCase):
self.pipeconf = config['pipeline']
self.subspaths = cycle(iglob(subsglob))
self.videopaths = cycle(iglob(videoglob))
self.imagepaths = cycle(iglob(imageglob))
def tearDown(self):
rmtree(self.testbase)
@unittest.skip
class PackageTest(DaemonTest):
def test_validating(self):
contents = {
@ -56,12 +59,12 @@ class PackageTest(DaemonTest):
'en': 'Test package'},
'description': 'Testbeskrivning',
'created': 1000,
'duration': 500,
'duration': 500.0,
'presenters': ['fooPresenter', 'barPresenter'],
'courses': ['fooCourse', 'barCourse'],
'tags': ['fooTag', 'barTag'],
'thumb': 'somethumb.jpg',
'subtitles': path.basename(self.subspaths.__next__()),
'subtitles': path.basename(next(self.subspaths)),
'sources': {'main': {'poster': 'fooPoster',
'playAudio': True,
'video': {'720': 'fooVideo720',
@ -201,26 +204,84 @@ class PipelineTest(DaemonTest):
self.assertEqual(jobid, result['jobid'])
self.assertEqual(handlername, result['origin'])
package = PackageManager(
self.pipeconf['packagedir'], result['package']['pkg_id'])._read()
package = PackageManager(self.pipeconf['packagedir'],
result['package']['pkg_id']).read()
# Check match of saved package and notification
for key, value in result['package']['contents'].items():
self.assertEqual(value, package[key])
return result
def test_subtitles(self):
uldir = path.join(self.pipeconf['uploaddir'], str(uuid.uuid4()))
subspath = self.subspaths.__next__()
subsfile = path.basename(subspath)
jobspec = {'pkg_id': str(uuid.uuid4()),
'upload_dir': uldir,
'subtitles': subsfile}
def init_job(self, pkgid=False, subs=False, thumb=False,
source_count=0, poster_count=0):
jobspec = {}
# Put subsfile in proper place
makedirs(uldir)
# Set pkg_id
if pkgid == True:
# Generate new
jobspec['pkg_id'] = str(uuid.uuid4())
elif pkgid:
# Re-use existing
jobspec['pkg_id'] = pkgid
if subs:
self.add_subtitles(jobspec)
# Set thumb
if thumb == '':
# Request generation in pipeline
self.add_genthumb(jobspec)
elif thumb == True:
# Set an image to be included
self.add_thumb(jobspec)
# Set sources
if source_count:
# poster_count determines the number of posters to include.
# Any remaining posters will be generated in pipeline
self.add_sources(jobspec, source_count, poster_count)
return jobspec
def ensure_uldir(self, jobspec):
if 'upload_dir' not in jobspec:
uldir = path.join(self.pipeconf['uploaddir'],
str(uuid.uuid4()))
jobspec['upload_dir'] = uldir
makedirs(uldir)
return uldir
def add_subtitles(self, jobspec):
uldir = self.ensure_uldir(jobspec)
subspath = next(self.subspaths)
subsfile = path.basename(subspath)
jobspec['subtitles'] = subsfile
copyfile(subspath, path.join(uldir, subsfile))
def add_sources(self, jobspec, count, poster_count=0):
uldir = self.ensure_uldir(jobspec)
jobspec['sources'] = {}
posters = 0
for i in range(count):
videopath = next(self.videopaths)
videofile = path.basename(videopath)
copyfile(videopath, path.join(uldir, videofile))
sourcedef = {'video': videofile,
'playAudio': False}
if i == 0:
sourcedef['playAudio'] = True
if posters < poster_count:
posterpath = next(self.imagepaths)
posterfile = path.basename(posterpath)
copyfile(posterpath, path.join(uldir, posterfile))
sourcedef['poster'] = posterfile
posters += 1
jobspec['sources'][f"source-{i}"] = sourcedef
@unittest.skip
def test_subtitles(self):
jobspec = self.init_job(subs=True)
jobid = self.submit_default_job(jobspec)
result = self.wait_for_result(jobid, 'SubtitlesHandler')
@ -230,24 +291,25 @@ class PipelineTest(DaemonTest):
with PackageManager(self.pipeconf['packagedir'],
result['package']['pkg_id']) as package:
# Check match of saved package and jobspec
self.assertEqual(package['subtitles'], subsfile)
self.assertEqual(package['subtitles'], jobspec['subtitles'])
# Subsfile should be in place
self.assertTrue(path.exists(path.join(package.basedir, subsfile)))
self.assertTrue(path.exists(path.join(package.basedir,
jobspec['subtitles'])))
# uldir should be gone
self.assertFalse(path.exists(uldir))
self.assertFalse(path.exists(jobspec['upload_dir']))
@unittest.skip
def test_metadata(self):
jobspec = {'pkg_id': str(uuid.uuid4()),
'title': {'sv': 'Testtitel',
'en': 'Test title'},
'description': 'Test description',
'created': 1234567,
'duration': 100,
'presenters': ['fooPerson', 'barPerson'],
'courses': ['fooCourse', 'barCourse'],
'tags': ['foo', 'bar']}
jobspec = self.init_job()
jobspec['title'] = {'sv': 'Testtitel',
'en': 'Test title'}
jobspec['description'] = 'Test description'
jobspec['created'] = 1234567
jobspec['presenters'] = ['fooPerson', 'barPerson']
jobspec['courses'] = ['fooCourse', 'barCourse']
jobspec['tags'] = ['foo', 'bar']
jobid = self.submit_default_job(jobspec)
result = self.wait_for_result(jobid, 'MetadataHandler')
@ -269,36 +331,28 @@ class PipelineTest(DaemonTest):
#@unittest.skip("This test is very slow")
def test_transcoding(self):
uldir = path.join(self.pipeconf['uploaddir'], str(uuid.uuid4()))
jobspec = {'pkg_id': str(uuid.uuid4()),
'upload_dir': uldir,
'sources': {}}
makedirs(uldir)
sourcenames = ['main', 'camera']
for name in sourcenames:
videopath = self.videopaths.__next__()
videofile = path.basename(videopath)
jobspec['sources'][name] = {'video': videofile}
copyfile(videopath, path.join(uldir, videofile))
jobspec = self.init_job(source_count=4, poster_count=2)
jobid = self.submit_default_job(jobspec)
result = self.wait_for_result(jobid, 'TranscodeHandler', timeout=180)
# There should be no further pending jobs
# There should be no further pending handlers
self.assertEqual([], result['pending'])
with PackageManager(self.pipeconf['packagedir'],
result['package']['pkg_id']) as package:
# Check match of saved package and jobspec
for name in sourcenames:
variants = package['sources'][name]['video']
for variant, filename in variants.items():
for name, source in jobspec['sources'].items():
pkgsource = package['sources'][name]
self.assertEqual(source['playAudio'], pkgsource['playAudio'])
self.assertTrue(path.exists(path.join(package.basedir,
pkgsource['poster'])))
for variant, filename in pkgsource['video'].items():
videopath = path.join(package.basedir, filename)
self.assertTrue(path.exists(videopath))
# uldir should be gone
self.assertFalse(path.exists(uldir))
self.assertFalse(path.exists(jobspec['upload_dir']))
if __name__ == '__main__':
@ -315,6 +369,7 @@ current working directory.
- At least one file with a .vtt suffix.
- A subdirectory named '{videosubdir}', containing at least one video clip.
Tests may fail if this subdirectory contains non-video files.
- A subdirectory named '{imagesubdir}', containing at least one image file.
""")
exit(1)
unittest.main()