From 9d8d9f806f9f3a283cda4a4c2c6433170b8b3bbd Mon Sep 17 00:00:00 2001 From: Oskar Hahn Date: Tue, 12 Nov 2013 08:36:46 +0100 Subject: [PATCH] Fixed agenda slide Fixes #1035 --- openslides/agenda/slides.py | 5 ++--- tests/agenda/tests.py | 37 +++++++++++++++++++++++++++++++++++++ 2 files changed, 39 insertions(+), 3 deletions(-) diff --git a/openslides/agenda/slides.py b/openslides/agenda/slides.py index ce0c3219a..4ea5d4789 100644 --- a/openslides/agenda/slides.py +++ b/openslides/agenda/slides.py @@ -3,8 +3,7 @@ from django.template.loader import render_to_string from openslides.config.api import config -from openslides.projector.api import ( - get_projector_content, register_slide, SlideError) +from openslides.projector.api import get_projector_content, register_slide from .models import Item @@ -29,7 +28,7 @@ def agenda_slide(**kwargs): try: item = Item.objects.get(pk=item_pk) except Item.DoesNotExist: - raise SlideError + item = None if slide_type == 'summary' or item is None: context = {} diff --git a/tests/agenda/tests.py b/tests/agenda/tests.py index d6eac2234..f04b9424a 100644 --- a/tests/agenda/tests.py +++ b/tests/agenda/tests.py @@ -1,8 +1,10 @@ # -*- coding: utf-8 -*- from django.test.client import Client +from mock import patch from openslides.agenda.models import Item +from openslides.agenda.slides import agenda_slide from openslides.participant.models import User from openslides.utils.test import TestCase @@ -241,3 +243,38 @@ class ConfigTest(TestCase): self.assertFormError(response, form='form', field='agenda_start_event_date_time', 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))