Fixed agenda slide

Fixes #1035
This commit is contained in:
Oskar Hahn 2013-11-12 08:36:46 +01:00
parent 09ac5d0eb5
commit 9d8d9f806f
2 changed files with 39 additions and 3 deletions

View File

@ -3,8 +3,7 @@
from django.template.loader import render_to_string from django.template.loader import render_to_string
from openslides.config.api import config from openslides.config.api import config
from openslides.projector.api import ( from openslides.projector.api import get_projector_content, register_slide
get_projector_content, register_slide, SlideError)
from .models import Item from .models import Item
@ -29,7 +28,7 @@ def agenda_slide(**kwargs):
try: try:
item = Item.objects.get(pk=item_pk) item = Item.objects.get(pk=item_pk)
except Item.DoesNotExist: except Item.DoesNotExist:
raise SlideError item = None
if slide_type == 'summary' or item is None: if slide_type == 'summary' or item is None:
context = {} context = {}

View File

@ -1,8 +1,10 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
from django.test.client import Client from django.test.client import Client
from mock import patch
from openslides.agenda.models import Item from openslides.agenda.models import Item
from openslides.agenda.slides import agenda_slide
from openslides.participant.models import User from openslides.participant.models import User
from openslides.utils.test import TestCase from openslides.utils.test import TestCase
@ -241,3 +243,38 @@ class ConfigTest(TestCase):
self.assertFormError(response, form='form', self.assertFormError(response, form='form',
field='agenda_start_event_date_time', field='agenda_start_event_date_time',
errors='Invalid input.') errors='Invalid input.')
@patch('openslides.agenda.slides.render_to_string')
class SlideTest(TestCase):
"""
Test the agenda slide.
"""
def setUp(self):
self.item1 = Item.objects.create(title='first slide')
Item.objects.create(title='second slide')
Item.objects.create(title='first child', parent=self.item1)
Item.objects.create(title='second child', parent=self.item1)
def test_full_agenda_summary(self, mock_render_to_string):
agenda_slide()
self.assertTrue(mock_render_to_string.called)
self.assertEqual(mock_render_to_string.call_args[0][0], 'agenda/item_slide_summary.html')
query = mock_render_to_string.call_args[0][1]['items']
self.assertEqual(repr(query), repr(Item.objects.filter(pk__in=[1, 2])))
def test_item_summary(self, mock_render_to_string):
agenda_slide(type='summary', pk=1)
self.assertTrue(mock_render_to_string.called)
self.assertEqual(mock_render_to_string.call_args[0][0], 'agenda/item_slide_summary.html')
self.assertEqual(mock_render_to_string.call_args[0][1]['title'], self.item1.get_title())
query = mock_render_to_string.call_args[0][1]['items']
self.assertEqual(repr(query), repr(Item.objects.filter(pk__in=[3, 4])))
def test_normal_slide(self, mock_render_to_string):
agenda_slide(pk=1)
self.assertTrue(mock_render_to_string.called)
self.assertEqual(mock_render_to_string.call_args[0][0], 'agenda/item_slide.html')
item = mock_render_to_string.call_args[0][1]['item']
self.assertEqual(item, Item.objects.get(pk=1))