Mercurial > public > sg101
diff 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 |
line wrap: on
line diff
--- a/bandmap/tests/test_views.py Wed Sep 24 21:22:24 2014 -0500 +++ b/bandmap/tests/test_views.py Thu Sep 25 21:15:22 2014 -0500 @@ -2,6 +2,8 @@ Unit tests for the bandmap application views. """ +import datetime + from django.test import TestCase from django.core.urlresolvers import reverse from django.contrib.auth.models import User @@ -50,4 +52,32 @@ self.assertEqual(response.status_code, 200) def test_post_add(self): - """TODO""" + url = reverse('bandmap-add') + post_data = { + 'name': 'Test Band', + 'url': 'http://example.com/', + 'location': 'Here & There', + 'note': 'They suck', + 'is_active': 'on', + 'lat': '42.0', + 'lon': '-23.5', + } + now = datetime.datetime.now() + delta_t = datetime.timedelta(seconds=1) + response = self.client.post(url, data=post_data, follow=True) + self.assertRedirects(response, url) + + self.assertEqual(BandEntry.objects.all().count(), 1) + entry = BandEntry.objects.get(pk=1) + self.assertEqual(entry.name, post_data['name']) + self.assertEqual(entry.user, self.user) + self.assertEqual(entry.user, self.user) + self.assertTrue(now - entry.date_submitted < delta_t) + self.assertIsNone(entry.date_approved) + self.assertEqual(entry.url, post_data['url']) + self.assertEqual(entry.location, post_data['location']) + self.assertAlmostEqual(entry.lat, float(post_data['lat'])) + self.assertAlmostEqual(entry.lon, float(post_data['lon'])) + self.assertEqual(entry.note, post_data['note']) + self.assertTrue(entry.is_active) + self.assertFalse(entry.is_approved)