OpenSlides/tests/integration/core/test_views.py

63 lines
2.4 KiB
Python
Raw Normal View History

import json
from django.core.urlresolvers import reverse
from rest_framework import status
2015-06-18 21:48:20 +02:00
from openslides import __version__ as version
from openslides.core.models import CustomSlide, Projector
from openslides.utils.test import TestCase
class ProjectorAPI(TestCase):
"""
Tests requests from the anonymous user.
"""
def test_slide_on_default_projector(self):
self.client.login(username='admin', password='admin')
customslide = CustomSlide.objects.create(title='title_que1olaish5Wei7que6i', text='text_aishah8Eh7eQuie5ooji')
default_projector = Projector.objects.get(pk=1)
default_projector.config = [{'name': 'core/customslide', 'id': customslide.id}]
default_projector.save()
response = self.client.get(reverse('projector-detail', args=['1']))
self.assertEqual(response.status_code, status.HTTP_200_OK)
self.assertEqual(json.loads(response.content.decode()), {
'config': [{'name': 'core/customslide', 'id': customslide.id}],
'projector_elements': [
{'name': 'core/customslide',
'scripts': 'core/customslide_slide.js',
'context': [
{'collection': 'core/customslide',
'id': customslide.id}]}]})
def test_invalid_slide_on_default_projector(self):
self.client.login(username='admin', password='admin')
default_projector = Projector.objects.get(pk=1)
default_projector.config = [{'name': 'invalid_slide'}]
default_projector.save()
response = self.client.get(reverse('projector-detail', args=['1']))
self.assertEqual(response.status_code, status.HTTP_200_OK)
self.assertEqual(json.loads(response.content.decode()), {
'config': [{'name': 'invalid_slide'}],
'projector_elements': [
{'name': 'invalid_slide',
'error': 'Projector element does not exist.'}]})
2015-06-18 21:48:20 +02:00
class VersionView(TestCase):
"""
Tests the version info view.
"""
def test_get(self):
self.client.login(username='admin', password='admin')
response = self.client.get(reverse('core_version'))
self.assertEqual(json.loads(response.content.decode()), {
'openslides_version': version,
'plugins': [
{'verbose_name': 'Plugin tests.old.utils',
'description': 'Description of plugin tests.old.utils',
'version': 'unknown'}]})