# HG changeset patch # User Brian Neal # Date 1411697722 18000 # Node ID d91356818cefb14a328956733eaebc173fc8e499 # Parent 704b47356a4934a22f4bc2e314c00741d3db6fae Bandmap WIP: added test to add band. diff -r 704b47356a49 -r d91356818cef bandmap/tests/test_views.py --- 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) diff -r 704b47356a49 -r d91356818cef bandmap/views.py --- a/bandmap/views.py Wed Sep 24 21:22:24 2014 -0500 +++ b/bandmap/views.py Thu Sep 25 21:15:22 2014 -0500 @@ -28,7 +28,7 @@ band.user = request.user band.save() django_messages.success(request, SUCCESS.format(band.name)) - redirect('bandmap-add') + return redirect('bandmap-add') else: form = BandForm()