comparison bandmap/tests/test_views.py @ 825:d91356818cef

Bandmap WIP: added test to add band.
author Brian Neal <bgneal@gmail.com>
date Thu, 25 Sep 2014 21:15:22 -0500
parents 704b47356a49
children 5103edd3acc4
comparison
equal deleted inserted replaced
824:704b47356a49 825:d91356818cef
1 """ 1 """
2 Unit tests for the bandmap application views. 2 Unit tests for the bandmap application views.
3 3
4 """ 4 """
5 import datetime
6
5 from django.test import TestCase 7 from django.test import TestCase
6 from django.core.urlresolvers import reverse 8 from django.core.urlresolvers import reverse
7 from django.contrib.auth.models import User 9 from django.contrib.auth.models import User
8 10
9 from bandmap.models import BandEntry 11 from bandmap.models import BandEntry
48 url = reverse('bandmap-add') 50 url = reverse('bandmap-add')
49 response = self.client.get(url, follow=True) 51 response = self.client.get(url, follow=True)
50 self.assertEqual(response.status_code, 200) 52 self.assertEqual(response.status_code, 200)
51 53
52 def test_post_add(self): 54 def test_post_add(self):
53 """TODO""" 55 url = reverse('bandmap-add')
56 post_data = {
57 'name': 'Test Band',
58 'url': 'http://example.com/',
59 'location': 'Here & There',
60 'note': 'They suck',
61 'is_active': 'on',
62 'lat': '42.0',
63 'lon': '-23.5',
64 }
65 now = datetime.datetime.now()
66 delta_t = datetime.timedelta(seconds=1)
67 response = self.client.post(url, data=post_data, follow=True)
68 self.assertRedirects(response, url)
69
70 self.assertEqual(BandEntry.objects.all().count(), 1)
71 entry = BandEntry.objects.get(pk=1)
72 self.assertEqual(entry.name, post_data['name'])
73 self.assertEqual(entry.user, self.user)
74 self.assertEqual(entry.user, self.user)
75 self.assertTrue(now - entry.date_submitted < delta_t)
76 self.assertIsNone(entry.date_approved)
77 self.assertEqual(entry.url, post_data['url'])
78 self.assertEqual(entry.location, post_data['location'])
79 self.assertAlmostEqual(entry.lat, float(post_data['lat']))
80 self.assertAlmostEqual(entry.lon, float(post_data['lon']))
81 self.assertEqual(entry.note, post_data['note'])
82 self.assertTrue(entry.is_active)
83 self.assertFalse(entry.is_approved)