1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
|
"""Tests for Event model and EventAdmin.
"""
from datetime import datetime, timedelta
from django.core.exceptions import ValidationError
from django.test import TestCase
from models import Event
class EventTest(TestCase):
"""Event model tests.
"""
def test_source_default(self):
"""Tests if the source field default is set to "import".
"""
event = Event(name='Test', start=datetime.now(), end=datetime.now())
self.assertEqual(event.source, Event.SOURCE_IMPORT)
def test_start_end(self):
"""Tests if an ValidationError is raised if start is lower than end.
"""
start = datetime.now()
end = start - timedelta(1)
event = Event(name='Test', start=start, end=end)
self.assertRaises(ValidationError, event.full_clean)
class EventAdminTest(TestCase):
"""EventAdmin tests.
"""
fixtures = ['testing.json']
def setUp(self):
"""Performs the login with the client.
"""
result = self.client.login(username='admin', password='admin')
self.assertTrue(result, 'Login failed.')
def test_source(self):
"""Tests if the source field is set to "admin" when saved with the admin.
"""
name = 'Test source admin'
data = {
'name': name,
'start_0': '2012-01-01',
'start_1': '12:00:00',
'end_0': '2012-01-01',
'end_1': '13:00:00',
}
self.client.post('/admin/calendarium/event/add/', data=data)
event = Event.objects.get(name=name)
self.assertEqual(event.source, Event.SOURCE_ADMIN)
|