88 lines
3.2 KiB
Python
88 lines
3.2 KiB
Python
import json
|
|
|
|
from django.test import TestCase
|
|
|
|
from books.factories import InstrumentFactory, ContentBlockFactory, ModuleFactory
|
|
from notes.models import InstrumentBookmark
|
|
from notes.schema import find_content
|
|
from users.models import User
|
|
from users.services import create_users
|
|
|
|
|
|
class TestGetBookmarkContent(TestCase):
|
|
def setUp(self):
|
|
create_users()
|
|
self.student1 = User.objects.get(username='student1')
|
|
self.instrument = InstrumentFactory(title="My Instrument", slug='instrument-slug')
|
|
|
|
def test_content_from_content_list_item(self):
|
|
content_list = [
|
|
{
|
|
"id": "45c5d9e7-233b-4ec7-a539-4136f2f969a4",
|
|
"type": "content_list_item",
|
|
"value": [
|
|
{
|
|
"id": "4eb6a9ec-576a-4bec-8eb7-798ac21e88cd",
|
|
"type": "text_block",
|
|
"value": {"text": "<p>Schauen Sie sich die</p>"}
|
|
},
|
|
{
|
|
"id": "718bee9a-5f92-4e3d-b7f8-aa63b8f2497e",
|
|
"type": "link_block",
|
|
"value": {"url": "https://skilM2_A2_Studie.pdf", "text": "Studie anzeigen"}
|
|
}
|
|
]
|
|
},
|
|
{
|
|
"id": "6a72b706-5ad7-4c8b-9fa1-e89909a2a5e6",
|
|
"type": "content_list_item",
|
|
"value": [
|
|
{
|
|
"id": "b7cd58c7-3131-4e3c-a51a-cd0026be03f8",
|
|
"type": "assignment",
|
|
"value": {"assignment_id": 204}
|
|
}
|
|
]
|
|
}
|
|
]
|
|
|
|
bookmark = InstrumentBookmark.objects.create(
|
|
instrument=self.instrument,
|
|
uuid='4eb6a9ec-576a-4bec-8eb7-798ac21e88cd',
|
|
user=self.student1
|
|
)
|
|
content = find_content(content_list, bookmark)
|
|
|
|
self.assertEqual("<p>Schauen Sie sich die</p>", content)
|
|
|
|
def test_content_from_instrument(self):
|
|
self.instrument = InstrumentFactory(title="My Instrument", slug='instrument-slug-sdfe')
|
|
|
|
content_list = [{'id': '6dd39d83-e442-4f3c-8d3f-e7e8026b0c4b',
|
|
'type': 'basic_knowledge',
|
|
'value': {'description': '', 'basic_knowledge': self.instrument.id}}
|
|
]
|
|
|
|
bookmark = InstrumentBookmark.objects.create(
|
|
instrument=self.instrument,
|
|
uuid='6dd39d83-e442-4f3c-8d3f-e7e8026b0c4b',
|
|
user=self.student1
|
|
)
|
|
content = find_content(content_list, bookmark)
|
|
self.assertEqual("My Instrument", content)
|
|
|
|
def test_content_from_thinglink_block(self):
|
|
self.instrument = InstrumentFactory(title="My Instrument", slug='instrument-slug-sdfe')
|
|
|
|
content_list = [{'id': 'f3f80b35-9098-4eeb-a149-3dc0318208cb',
|
|
'type': 'thinglink_block',
|
|
'value': {'id': '1251174983242088451'}}]
|
|
|
|
bookmark = InstrumentBookmark.objects.create(
|
|
instrument=self.instrument,
|
|
uuid='f3f80b35-9098-4eeb-a149-3dc0318208cb',
|
|
user=self.student1
|
|
)
|
|
content = find_content(content_list, bookmark)
|
|
self.assertEqual("Infografik", content)
|