some tests for the agenda
This commit is contained in:
parent
65eeffe1c1
commit
b3806d8cdd
@ -1,108 +0,0 @@
|
||||
from django.db import models
|
||||
from django.test import TestCase
|
||||
from django.utils import simplejson as json
|
||||
|
||||
from fields import JSONField
|
||||
|
||||
|
||||
class JsonModel(models.Model):
|
||||
json = JSONField()
|
||||
|
||||
|
||||
class ComplexEncoder(json.JSONEncoder):
|
||||
def default(self, obj):
|
||||
if isinstance(obj, complex):
|
||||
return {
|
||||
'__complex__': True,
|
||||
'real': obj.real,
|
||||
'imag': obj.imag,
|
||||
}
|
||||
|
||||
return json.JSONEncoder.default(self, obj)
|
||||
|
||||
|
||||
def as_complex(dct):
|
||||
if '__complex__' in dct:
|
||||
return complex(dct['real'], dct['imag'])
|
||||
return dct
|
||||
|
||||
|
||||
class JSONModelCustomEncoders(models.Model):
|
||||
# A JSON field that can store complex numbers
|
||||
json = JSONField(
|
||||
dump_kwargs={'cls': ComplexEncoder},
|
||||
load_kwargs={'object_hook': as_complex},
|
||||
)
|
||||
|
||||
|
||||
class JSONFieldTest(TestCase):
|
||||
"""JSONField Wrapper Tests"""
|
||||
|
||||
def test_json_field_create(self):
|
||||
"""Test saving a JSON object in our JSONField"""
|
||||
|
||||
json_obj = {
|
||||
"item_1": "this is a json blah",
|
||||
"blergh": "hey, hey, hey"}
|
||||
|
||||
obj = JsonModel.objects.create(json=json_obj)
|
||||
new_obj = JsonModel.objects.get(id=obj.id)
|
||||
|
||||
self.failUnlessEqual(new_obj.json, json_obj)
|
||||
|
||||
def test_json_field_modify(self):
|
||||
"""Test modifying a JSON object in our JSONField"""
|
||||
|
||||
json_obj_1 = {'a': 1, 'b': 2}
|
||||
json_obj_2 = {'a': 3, 'b': 4}
|
||||
|
||||
obj = JsonModel.objects.create(json=json_obj_1)
|
||||
|
||||
self.failUnlessEqual(obj.json, json_obj_1)
|
||||
|
||||
obj.json = json_obj_2
|
||||
|
||||
self.failUnlessEqual(obj.json, json_obj_2)
|
||||
|
||||
obj.save()
|
||||
|
||||
self.failUnlessEqual(obj.json, json_obj_2)
|
||||
|
||||
self.assert_(obj)
|
||||
|
||||
def test_json_field_load(self):
|
||||
"""Test loading a JSON object from the DB"""
|
||||
|
||||
json_obj_1 = {'a': 1, 'b': 2}
|
||||
|
||||
obj = JsonModel.objects.create(json=json_obj_1)
|
||||
|
||||
new_obj = JsonModel.objects.get(id=obj.id)
|
||||
|
||||
self.failUnlessEqual(new_obj.json, json_obj_1)
|
||||
|
||||
def test_json_list(self):
|
||||
"""Test storing a JSON list"""
|
||||
|
||||
json_obj = ["my", "list", "of", 1, "objs", {"hello": "there"}]
|
||||
|
||||
obj = JsonModel.objects.create(json=json_obj)
|
||||
new_obj = JsonModel.objects.get(id=obj.id)
|
||||
self.failUnlessEqual(new_obj.json, json_obj)
|
||||
|
||||
def test_empty_objects(self):
|
||||
"""Test storing empty objects"""
|
||||
|
||||
for json_obj in [{}, [], 0, '', False]:
|
||||
obj = JsonModel.objects.create(json=json_obj)
|
||||
new_obj = JsonModel.objects.get(id=obj.id)
|
||||
self.failUnlessEqual(json_obj, obj.json)
|
||||
self.failUnlessEqual(json_obj, new_obj.json)
|
||||
|
||||
def test_custom_encoder(self):
|
||||
"""Test encoder_cls and object_hook"""
|
||||
value = 1 + 3j # A complex number
|
||||
|
||||
obj = JSONModelCustomEncoders.objects.create(json=value)
|
||||
new_obj = JSONModelCustomEncoders.objects.get(pk=obj.pk)
|
||||
self.failUnlessEqual(value, new_obj.json)
|
@ -17,6 +17,7 @@ from django.db.models.query import EmptyQuerySet
|
||||
from openslides.projector.api import get_active_slide
|
||||
from openslides.participant.models import User
|
||||
from openslides.agenda.models import Item
|
||||
from openslides.agenda.slides import agenda_show
|
||||
|
||||
|
||||
class ItemTest(TestCase):
|
||||
@ -65,6 +66,29 @@ class ItemTest(TestCase):
|
||||
self.item1.related_sid = 'foobar'
|
||||
self.assertFalse(self.item1.get_related_slide() is None)
|
||||
|
||||
def test_title_supplement(self):
|
||||
self.assertEqual(self.item1.get_title_supplement(), '')
|
||||
|
||||
def test_delete_item(self):
|
||||
new_item1 = Item.objects.create()
|
||||
new_item2 = Item.objects.create(parent=new_item1)
|
||||
new_item3 = Item.objects.create(parent=new_item2)
|
||||
new_item1.delete()
|
||||
self.assertTrue(new_item3 in Item.objects.all())
|
||||
new_item2.delete(with_children=True)
|
||||
self.assertFalse(new_item3 in Item.objects.all())
|
||||
|
||||
def test_absolute_url(self):
|
||||
self.assertEqual(self.item1.get_absolute_url(), '/agenda/1/')
|
||||
self.assertEqual(self.item1.get_absolute_url('edit'), '/agenda/1/edit/')
|
||||
self.assertEqual(self.item1.get_absolute_url('delete'), '/agenda/1/del/')
|
||||
|
||||
def test_agenda_slide(self):
|
||||
data = agenda_show()
|
||||
self.assertEqual(list(data['items']), list(Item.objects.all().filter(parent=None)))
|
||||
self.assertEqual(data['template'], 'projector/AgendaSummary.html')
|
||||
self.assertEqual(data['title'], 'Agenda')
|
||||
|
||||
|
||||
class ViewTest(TestCase):
|
||||
def setUp(self):
|
||||
@ -94,6 +118,13 @@ class ViewTest(TestCase):
|
||||
def anonymClient(self):
|
||||
return Client()
|
||||
|
||||
def testOverview(self):
|
||||
c = self.adminClient
|
||||
|
||||
response = c.get('/agenda/')
|
||||
self.assertEqual(response.status_code, 200)
|
||||
self.assertEqual(len(response.context['items']), len(Item.objects.all()))
|
||||
|
||||
def testActivate(self):
|
||||
c = self.adminClient
|
||||
|
||||
@ -125,6 +156,14 @@ class ViewTest(TestCase):
|
||||
self.refreshItems()
|
||||
self.assertEqual(response.status_code, 404)
|
||||
|
||||
# Test ajax
|
||||
response = c.get('/agenda/%d/close/' % self.item1.id,
|
||||
HTTP_X_REQUESTED_WITH='XMLHttpRequest')
|
||||
self.assertEqual(response.status_code, 200)
|
||||
response = c.get('/agenda/%d/open/' % self.item1.id,
|
||||
HTTP_X_REQUESTED_WITH='XMLHttpRequest')
|
||||
self.assertEqual(response.status_code, 200)
|
||||
|
||||
def testEdit(self):
|
||||
c = self.adminClient
|
||||
|
||||
|
19
tests/test_init.py
Normal file
19
tests/test_init.py
Normal file
@ -0,0 +1,19 @@
|
||||
#!/usr/bin/env python
|
||||
# -*- coding: utf-8 -*-
|
||||
"""
|
||||
Unit test for OpenSlides __init__.py
|
||||
|
||||
:copyright: 2011, 2012 by OpenSlides team, see AUTHORS.
|
||||
:license: GNU GPL, see LICENSE for more details.
|
||||
"""
|
||||
|
||||
from django.test import TestCase
|
||||
|
||||
from openslides import get_version
|
||||
|
||||
class InitTest(TestCase):
|
||||
def testget_version(self):
|
||||
self.assertEqual(get_version((1, 3, 0, 'beta', 2)), '1.3-beta2')
|
||||
self.assertEqual(get_version((1, 0, 0, 'final', 0)), '1.0')
|
||||
self.assertEqual(get_version((2, 5, 3, 'alpha', 0)), '2.5.3-alpha0')
|
||||
self.assertEqual(len(get_version((2, 5, 0, 'dev', 0))), 47)
|
Loading…
Reference in New Issue
Block a user