diff options
author | Markus Zapke-Grùˆndemann <info@keimlink.de> | 2012-01-04 23:58:44 +0100 |
---|---|---|
committer | Markus Zapke-Grùˆndemann <info@keimlink.de> | 2012-01-04 23:58:44 +0100 |
commit | 7e960881ae6cbcd709538dcd73e4fd89e33507d3 (patch) | |
tree | ceea18c587ca1efe4f1877e3b891fa7d61948a06 /sublab_project/calendarium/tests.py | |
parent | 9d873fd644b9cc265ad63dbc33f308dbd888ca19 (diff) |
Added model, admin, tests and tasks for calendarium.
Diffstat (limited to 'sublab_project/calendarium/tests.py')
-rw-r--r-- | sublab_project/calendarium/tests.py | 55 |
1 files changed, 46 insertions, 9 deletions
diff --git a/sublab_project/calendarium/tests.py b/sublab_project/calendarium/tests.py index 501deb7..0ad8c06 100644 --- a/sublab_project/calendarium/tests.py +++ b/sublab_project/calendarium/tests.py @@ -1,16 +1,53 @@ +"""Tests for Event model and EventAdmin. """ -This file demonstrates writing tests using the unittest module. These will pass -when you run "manage.py test". - -Replace this with more appropriate tests for your application. -""" +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 SimpleTest(TestCase): - def test_basic_addition(self): +class EventAdminTest(TestCase): + """EventAdmin tests. + """ + fixtures = ['testing.json'] + + def setUp(self): + """Performs the login with the client. """ - Tests that 1 + 1 always equals 2. + 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. """ - self.assertEqual(1 + 1, 2) + 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) |