vbv/server/vbv_lernwelt/competence/tests/media_library_factories.py

101 lines
2.7 KiB
Python

import uuid
import wagtail_factories
from vbv_lernwelt.competence.content_blocks import MediaContentCollection, AnchorBlock, LinkBlock, \
CrossReferenceBlock
from vbv_lernwelt.competence.models import LibraryDocument, MediaLibraryPage, MediaCategoryPage
class LibraryDocumentFactory(wagtail_factories.DocumentFactory):
link_display_text = 'Dokument herunter laden'
thumbnail = 'https://d9-wret.s3.us-west-2.amazonaws.com/assets/palladium/production/s3fs-public/thumbnails/image/file.jpg'
class Meta:
model = LibraryDocument
class MediaLibraryPageFactory(wagtail_factories.PageFactory):
title = 'Mediathek'
class Meta:
model = MediaLibraryPage
class AnchorBlockFactory(wagtail_factories.StructBlockFactory):
class Meta:
model = AnchorBlock
class LinkBlockFactory(wagtail_factories.StructBlockFactory):
title = 'Interesting link'
description = 'This link is really interesting...'
url = 'https://www.vbv.ch/'
class Meta:
model = LinkBlock
class CrossReferenceBlockFactory(wagtail_factories.StructBlockFactory):
class Meta:
model = CrossReferenceBlock
class MediaContentCollectionFactory(wagtail_factories.StructBlockFactory):
title = 'Links'
contents = wagtail_factories.StreamFieldFactory({
'Links': LinkBlockFactory,
'Documents': LibraryDocumentFactory
})
class Meta:
model = MediaContentCollection
class MediaCategoryPageFactory(wagtail_factories.PageFactory):
title = 'Fahrzeug'
introduction_text = 'Das Auto ist für viele der grösste Stolz! Es birgt aber ...'
description_title = 'Das erwartet dich in diesem Handlungsfeld'
class Meta:
model = MediaCategoryPage
def create_media_content_link(link_block=None):
if link_block is None:
link_block = LinkBlockFactory()
return {
"id": str(uuid.uuid4()),
"type": "Links",
"value": dict(link_block.items())
}
def create_link_collection(links_dict=None):
return {
"id": str(uuid.uuid4()),
"type": "content_collection",
"value": {
"title": "Links",
"contents": [link_dict for link_dict in links_dict]
}
}
def create_document_collection(document_ids=None):
if document_ids is None:
document_ids = [d.id for d in LibraryDocument.objects.all()]
return {
"id": str(uuid.uuid4()),
"type": "content_collection",
"value": {
"title": "Lernmedien",
"contents": [{
"id": str(uuid.uuid4()),
"type": "Documents",
"value": doc_id
} for doc_id in document_ids]
}
}