From 7e960881ae6cbcd709538dcd73e4fd89e33507d3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Markus=20Zapke-Gru=CC=88ndemann?= Date: Wed, 4 Jan 2012 23:58:44 +0100 Subject: Added model, admin, tests and tasks for calendarium. --- sublab_project/calendarium/tests.py | 55 +++++++++++++++++++++++++++++++------ 1 file changed, 46 insertions(+), 9 deletions(-) (limited to 'sublab_project/calendarium/tests.py') 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) -- cgit v1.2.1