-
Notifications
You must be signed in to change notification settings - Fork 73
/
tests.py
68 lines (55 loc) · 3.52 KB
/
tests.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
from django.test import TestCase
from django.test.client import Client
from apps.app_renderers import build_plugin_renderers
from apps.models import HTMLPlugin, ExternalIFramePlugin, RSSPlugin
from course.models import Course, CourseInstance
HTML_PLUGIN_CONTENT = "test_content1245123"
RSS_PLUGIN_ADDRESS = "address12453"
IFRAME_PLUGIN_ADDRESS = "address13123"
class AppsTest(TestCase):
@classmethod
def setUpTestData(cls):
cls.client = Client()
cls.course = Course.objects.create(name="Test", code="test", url="test")
cls.instance = CourseInstance.objects.create(course=cls.course,
instance_name="Ins",
starting_time="2000-01-01T12:00:00.000Z",
ending_time="2020-01-01T12:00:00.000Z")
cls.html_plugin = HTMLPlugin.objects.create(container=cls.instance,
title="HTML Plugin",
views="exercise,course_instance",
content=HTML_PLUGIN_CONTENT)
cls.rss_plugin = RSSPlugin.objects.create(container=cls.instance,
title="RSS Plugin",
views="course_instance",
feed_url=RSS_PLUGIN_ADDRESS)
cls.iframe_plugin = ExternalIFramePlugin.objects.create(container=cls.instance,
title="Iframe Plugin",
views="exercise",
service_url=IFRAME_PLUGIN_ADDRESS,
width=100, height=200)
def test_plugin_builder_selections(self):
renderers = build_plugin_renderers(self.instance.plugins, 'submission',
course_instance=self.instance, course=self.course)
self.assertEqual(len(renderers), 0)
renderers = build_plugin_renderers(self.instance.plugins, 'exercise',
course_instance=self.instance, course=self.course)
self.assertEqual(len(renderers), 2)
renderers = build_plugin_renderers(self.instance.plugins, 'course_instance',
course_instance=self.instance, course=self.course)
self.assertEqual(len(renderers), 2)
def test_iframe_plugin(self):
renderers = build_plugin_renderers(ExternalIFramePlugin.objects, 'exercise',
course_instance=self.instance, course=self.course)
html = renderers[0].render()
self.assertTrue(IFRAME_PLUGIN_ADDRESS in html)
def test_html_plugin(self):
renderers = build_plugin_renderers(HTMLPlugin.objects, 'exercise',
course_instance=self.instance, course=self.course)
html = renderers[0].render()
self.assertTrue(HTML_PLUGIN_CONTENT in html)
def test_rss_plugin(self):
renderers = build_plugin_renderers(RSSPlugin.objects, 'course_instance',
course_instance=self.instance, course=self.course)
html = renderers[0].render() # pylint: disable=unused-variable
# No real content expected but should not raise errors.