Add unit tests
[pharos-tools.git] / pharos-dashboard / src / notification / tests.py
1 ##############################################################################
2 # Copyright (c) 2016 Max Breitenfeldt and others.
3 #
4 # All rights reserved. This program and the accompanying materials
5 # are made available under the terms of the Apache License, Version 2.0
6 # which accompanies this distribution, and is available at
7 # http://www.apache.org/licenses/LICENSE-2.0
8 ##############################################################################
9
10
11 from datetime import timedelta
12 from unittest import TestCase
13
14 from django.contrib.auth.models import User
15 from django.utils import timezone
16
17 from booking.models import Booking
18 from dashboard.models import Resource
19 from jenkins.models import JenkinsSlave
20 from notification.models import *
21
22
23 class JenkinsModelTestCase(TestCase):
24     def setUp(self):
25         self.slave = JenkinsSlave.objects.create(name='test1', url='test')
26         self.res1 = Resource.objects.create(name='res1', slave=self.slave, description='x',
27                                             url='x')
28         self.user1 = User.objects.create(username='user1')
29
30         start = timezone.now()
31         end = start + timedelta(days=1)
32         self.booking = Booking.objects.create(start=start, end=end, purpose='test',
33                                               resource=self.res1, user=self.user1)
34
35     def test_booking_notification(self):
36         BookingNotification.objects.create(type='test', booking=self.booking,
37                                            submit_time=timezone.now())
38
39         self.assertRaises(ValueError, BookingNotification.objects.create, type='test',
40                           booking=self.booking,
41                           submit_time=timezone.now())