updated agenda unittests
This commit is contained in:
parent
4e16c6639b
commit
e85822ebc9
@ -13,37 +13,19 @@
|
|||||||
from django.test import TestCase
|
from django.test import TestCase
|
||||||
from django.test.client import Client
|
from django.test.client import Client
|
||||||
from django.contrib.auth.models import User
|
from django.contrib.auth.models import User
|
||||||
|
from django.db.models.query import EmptyQuerySet
|
||||||
|
|
||||||
from openslides.agenda.models import Item, ItemText
|
from projector.api import get_active_slide
|
||||||
from openslides.agenda.api import get_active_item, is_summary, children_list
|
|
||||||
|
from agenda.models import Item
|
||||||
|
from agenda.api import is_summary
|
||||||
|
|
||||||
class ItemTest(TestCase):
|
class ItemTest(TestCase):
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
self.item1 = ItemText.objects.create(title='item1')
|
self.item1 = Item.objects.create(title='item1')
|
||||||
self.item2 = ItemText.objects.create(title='item2')
|
self.item2 = Item.objects.create(title='item2')
|
||||||
self.item3 = ItemText.objects.create(title='item1A', parent=self.item1)
|
self.item3 = Item.objects.create(title='item1A', parent=self.item1)
|
||||||
self.item4 = ItemText.objects.create(title='item1Aa', parent=self.item3)
|
self.item4 = Item.objects.create(title='item1Aa', parent=self.item3)
|
||||||
|
|
||||||
def testActive(self):
|
|
||||||
with self.assertRaises(Item.DoesNotExist):
|
|
||||||
get_active_item()
|
|
||||||
self.assertTrue(is_summary())
|
|
||||||
self.assertFalse(self.item4.active_parent)
|
|
||||||
|
|
||||||
self.assertFalse(self.item1.active)
|
|
||||||
|
|
||||||
self.item1.set_active()
|
|
||||||
self.assertTrue(self.item1.active)
|
|
||||||
self.assertTrue(self.item4.active_parent)
|
|
||||||
|
|
||||||
self.assertEqual(get_active_item().cast(), self.item1)
|
|
||||||
self.assertNotEqual(get_active_item().cast(), self.item2)
|
|
||||||
|
|
||||||
self.assertFalse(is_summary())
|
|
||||||
|
|
||||||
self.item2.set_active(summary=True)
|
|
||||||
self.assertFalse(self.item1.active)
|
|
||||||
self.assertTrue(is_summary())
|
|
||||||
|
|
||||||
def testClosed(self):
|
def testClosed(self):
|
||||||
self.assertFalse(self.item1.closed)
|
self.assertFalse(self.item1.closed)
|
||||||
@ -55,18 +37,18 @@ class ItemTest(TestCase):
|
|||||||
self.assertFalse(self.item1.closed)
|
self.assertFalse(self.item1.closed)
|
||||||
|
|
||||||
def testParents(self):
|
def testParents(self):
|
||||||
self.assertEqual(self.item1.parents, [])
|
self.assertEqual(type(self.item1.get_ancestors()), EmptyQuerySet)
|
||||||
self.assertTrue(self.item1 in self.item3.parents)
|
self.assertTrue(self.item1 in self.item3.get_ancestors())
|
||||||
self.assertTrue(self.item1 in self.item4.parents)
|
self.assertTrue(self.item1 in self.item4.get_ancestors())
|
||||||
self.assertFalse(self.item2 in self.item4.parents)
|
self.assertFalse(self.item2 in self.item4.get_ancestors())
|
||||||
|
|
||||||
def testChildren(self):
|
def testChildren(self):
|
||||||
self.assertEqual(list(self.item2.children), [])
|
self.assertEqual(list(self.item2.get_children()), [])
|
||||||
self.assertTrue(self.item3 in [item.cast() for item in self.item1.children])
|
self.assertTrue(self.item3 in self.item1.get_children())
|
||||||
self.assertFalse(self.item4 in [item.cast() for item in self.item1.children])
|
self.assertFalse(self.item4 in self.item1.get_children())
|
||||||
|
|
||||||
l = children_list([self.item1, self.item2])
|
l = Item.objects.all()
|
||||||
self.assertEqual(str(l), "[<ItemText: item1>, <Item: item1A>, <Item: item1Aa>, <ItemText: item2>]")
|
self.assertEqual(str(l), "[<Item: item1>, <Item: item1A>, <Item: item1Aa>, <Item: item2>]")
|
||||||
|
|
||||||
def testForms(self):
|
def testForms(self):
|
||||||
for item in Item.objects.all():
|
for item in Item.objects.all():
|
||||||
@ -78,16 +60,11 @@ class ItemTest(TestCase):
|
|||||||
self.assertEqual(initial['parent'], 0)
|
self.assertEqual(initial['parent'], 0)
|
||||||
self.assertEqual(initial['weight'], item.weight)
|
self.assertEqual(initial['weight'], item.weight)
|
||||||
|
|
||||||
item.edit_form()
|
|
||||||
|
|
||||||
def testtype(self):
|
|
||||||
self.assertEqual(self.item1.type, 'ItemText')
|
|
||||||
|
|
||||||
|
|
||||||
class ViewTest(TestCase):
|
class ViewTest(TestCase):
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
self.item1 = ItemText.objects.create(title='item1')
|
self.item1 = Item.objects.create(title='item1')
|
||||||
self.item2 = ItemText.objects.create(title='item2')
|
self.item2 = Item.objects.create(title='item2')
|
||||||
self.refreshItems()
|
self.refreshItems()
|
||||||
|
|
||||||
self.admin = User.objects.create_user('testadmin', '', 'default')
|
self.admin = User.objects.create_user('testadmin', '', 'default')
|
||||||
@ -129,11 +106,10 @@ class ViewTest(TestCase):
|
|||||||
self.assertEqual(response.status_code, 302)
|
self.assertEqual(response.status_code, 302)
|
||||||
self.assertFalse(self.item2.active)
|
self.assertFalse(self.item2.active)
|
||||||
self.assertFalse(self.item1.active)
|
self.assertFalse(self.item1.active)
|
||||||
with self.assertRaises(Item.DoesNotExist):
|
self.assertEqual(get_active_slide(only_sid=True), 'agenda_show')
|
||||||
get_active_item()
|
|
||||||
|
|
||||||
response = c.get('/agenda/%d/activate/' % 10000)
|
response = c.get('/agenda/%d/activate/' % 10000)
|
||||||
self.assertEqual(response.status_code, 302)
|
self.assertEqual(response.status_code, 404)
|
||||||
self.assertFalse(self.item2.active)
|
self.assertFalse(self.item2.active)
|
||||||
self.assertFalse(self.item1.active)
|
self.assertFalse(self.item1.active)
|
||||||
|
|
||||||
@ -152,32 +128,27 @@ class ViewTest(TestCase):
|
|||||||
|
|
||||||
response = c.get('/agenda/%d/open/' % 1000)
|
response = c.get('/agenda/%d/open/' % 1000)
|
||||||
self.refreshItems()
|
self.refreshItems()
|
||||||
self.assertEqual(response.status_code, 302)
|
self.assertEqual(response.status_code, 404)
|
||||||
|
|
||||||
def testEdit(self):
|
def testEdit(self):
|
||||||
c = self.adminClient
|
c = self.adminClient
|
||||||
|
|
||||||
response = c.get('/agenda/%d/edit/' % self.item1.id)
|
response = c.get('/agenda/%d/edit/' % self.item1.id)
|
||||||
self.assertEqual(response.status_code, 200)
|
self.assertEqual(response.status_code, 200)
|
||||||
self.assertEqual(response.context['form'].instance, self.item1.cast())
|
|
||||||
|
|
||||||
response = c.get('/agenda/%d/edit/' % 1000)
|
response = c.get('/agenda/%d/edit/' % 1000)
|
||||||
self.assertEqual(response.status_code, 302)
|
self.assertEqual(response.status_code, 404)
|
||||||
|
|
||||||
|
|
||||||
data = {'title': 'newitem1', 'text': 'item1-text', 'weight':'0'}
|
data = {'title': 'newitem1', 'text': 'item1-text', 'weight':'0'}
|
||||||
response = c.post('/agenda/%d/edit/' % self.item1.id, data)
|
response = c.post('/agenda/%d/edit/' % self.item1.id, data)
|
||||||
self.assertEqual(response.status_code, 302)
|
self.assertEqual(response.status_code, 302)
|
||||||
self.refreshItems()
|
self.refreshItems()
|
||||||
self.assertEqual(self.item1.cast().title, 'newitem1')
|
self.assertEqual(self.item1.title, 'newitem1')
|
||||||
self.assertEqual(self.item1.cast().text, 'item1-text')
|
self.assertEqual(self.item1.text, 'item1-text')
|
||||||
|
|
||||||
data = {'title': '', 'text': 'item1-text', 'weight': '0'}
|
data = {'title': '', 'text': 'item1-text', 'weight': '0'}
|
||||||
response = c.post('/agenda/%d/edit/' % self.item1.id, data)
|
response = c.post('/agenda/%d/edit/' % self.item1.id, data)
|
||||||
self.assertEqual(response.status_code, 200)
|
self.assertEqual(response.status_code, 200)
|
||||||
self.refreshItems()
|
self.refreshItems()
|
||||||
self.assertEqual(self.item1.cast().title, 'newitem1')
|
self.assertEqual(self.item1.title, 'newitem1')
|
||||||
|
|
||||||
def testNew(self):
|
|
||||||
pass
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user